Excel Data streamer - Arduino Uno (problems with ExcelVBA acknowledging sequence complete)

%3CLINGO-SUB%20id%3D%22lingo-sub-1988452%22%20slang%3D%22en-US%22%3EExcel%20Data%20streamer%20-%20Arduino%20Uno%20(problems%20with%20ExcelVBA%20acknowledging%20sequence%20complete)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1988452%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%20if%20possible%20I'm%20looking%20for%20some%20help%20regarding%20a%20problem%20that%20I%20have%20acknowledging%20received%20data%20in%20Excel%20(%2B%20Data%20streamer%20add-in).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20hardware%20set%20up%20that%20I%20have%20is%20Excel%20%2B%20Data%20streamer%20add-in%20connected%20via%20serial%20USB%20to%20an%20Arduino%20Uno.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I'm%20trying%20to%20achieve%20is%20for%20Excel%20to%20wait%20for%20the%20Arduino%20to%20finish%20it's%20present%20sequence%20before%20its%20transmitting%20the%20Arduino%20Uno%20a%20subsequent%20command.%20I%20have%20tried%20to%20do%20this%20with%20the%20code%20sample%26nbsp%3B%20attached%20(ExcelVBA)%3CSPAN%3E.%26nbsp%3B%20On%20the%20Arduino%20Uno%20side%3B%20once%20it%20receives%20serial%20data%20it%20will%20first%20transmit%20the%20'r'%20character%2C%20then%20do%20it's%20sequence%20and%20then%20transmit%20a%20'c'%20character.%20The%20ExcelVBA%20code%20aims%20to%20evaluate%20whether%20the%20most%20current%20character%20received%20is%20'c'%20before%20moving%20on%20to%20transmit%20the%20next%20Arduino%20command.%20%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20attached%20VBA%20code%20works%20fine%20on%20step%20into%20(F8)%2C%20but%20not%20run%20(F5).%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EIt%20feels%20like%20the%20artificial%20time%20delay%20in%20step%20through%20works%20to%20give%20time%20for%20the%20serial%20buffer%20to%20load%20the%20character%20values%20(maybe%3F)%3C%2FP%3E%3CP%3EOn%20running%20(F5)%20the%20errors%20are%3B%3C%2FP%3E%3CP%3E(i)%20If%20there%20has%20already%20been%20a%20'c'%20character%20received%20it%20will%20accept%20this%20character%20before%20the%26nbsp%3B'r'%20character%20from%20the%20arduino%20has%20had%20time%20to%20be%20transmitted%20(even%20up%20to%20115200%20baud)%20so%20the%20preceeding%20'c'%20character%20erroneously%20indicates%20the%20Arduino%20sequence%20is%20finished%20before%20it%20truly%20is.%3C%2FP%3E%3CP%3E(ii)%20If%20it%20is%20a%20fresh%20run%2C%20with%20no%20preceeding%20runs%20through%20the%20code%20(and%20so%20no%20'c'%20characters%20stored)%2C%20the%20code%20will%20just%20hang%2Fcrash%20(not%20responding%20error).%3CBR%20%2F%3E(iii)%20If%20an%20artifical%20delay%20is%20included%20in%20the%20loop%20the%20above%20error%20occurs%20too.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20mentioned%20above%2C%20what's%20most%20puzzling%20is%20that%20step%20into%20(F8)%20works%20fine%2C%20and%20the%20programming%20logic%20appears%20to%20work.%20That's%20why%20I'm%20left%20with%20the%20impression%2C%20time%20is%20probably%20the%20factor%20causing%20an%20issue%3B%20however%2C%20I%20don't%20have%20enough%20experience%20to%20know%20exactly%20what.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20appreciate%20any%20help%20that%20can%20be%20offered.%20Many%20thanks.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ESub%20TestProg1()%0AWorksheets(%22Data%20In%22).Select%0AWorksheets(%22Data%20In%22).Range(%22S1%22).NumberFormat%20%3D%20_%0A%22%5B%24-x-systime%5Dh%3Amm%3Ass%20AM%2FPM%22%0AWorksheets(%22Data%20In%22).Range(%22Q1%22).Value%20%3D%20%22r%22%0AWorksheets(%22Data%20In%22).Range(%22R1%22).Value%20%3D%20%22waiting%22%0AWorksheets(%22Data%20In%22).Range(%22P1%22).Value%20%3D%20%22%26lt%3B1%2C6400%2C400%26gt%3B%22%0AWorksheets(%22Data%20Out%22).Range(%22A5%22).Value%20%3D%20_%0AWorksheets(%22Data%20In%22).Range(%22P1%22).Value%0A%0A%0A%0ADoEvents%0A%0ADo%20While%20Worksheets(%22Data%20In%22).Range(%22Q1%22).Value%20%26lt%3B%26gt%3B%20%22c%22%0A'Application.Wait%20(Now%20%2B%20TimeValue(%220%3A00%3A01%22))'This%20makes%20program%20hang%0AWorksheets(%22Data%20In%22).Range(%22Q1%22).Value%20%3D%20_%0AWorksheets(%22Data%20In%22).Range(%22TBL_CUR%5BCH1%5D%22).Value%20'cell%20B5%0A%0ALoop%0AWorksheets(%22Data%20In%22).Range(%22R1%22).Value%20%3D%20%22finished%22%0AWorksheets(%22Data%20In%22).Range(%22S1%22).Value%20%3D%20_%0AWorksheets(%22Data%20In%22).Range(%22A5%22).Value%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1988452%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional Visitor

Hi, if possible I'm looking for some help regarding a problem that I have acknowledging received data in Excel (+ Data streamer add-in).

 

The hardware set up that I have is Excel + Data streamer add-in connected via serial USB to an Arduino Uno.

 

What I'm trying to achieve is for Excel to wait for the Arduino to finish it's present sequence before its transmitting the Arduino Uno a subsequent command. I have tried to do this with the code sample  attached (ExcelVBA).  On the Arduino Uno side; once it receives serial data it will first transmit the 'r' character, then do it's sequence and then transmit a 'c' character. The ExcelVBA code aims to evaluate whether the most current character received is 'c' before moving on to transmit the next Arduino command.

 

The attached VBA code works fine on step into (F8), but not run (F5). 

It feels like the artificial time delay in step through works to give time for the serial buffer to load the character values (maybe?)

On running (F5) the errors are;

(i) If there has already been a 'c' character received it will accept this character before the 'r' character from the arduino has had time to be transmitted (even up to 115200 baud) so the preceeding 'c' character erroneously indicates the Arduino sequence is finished before it truly is.

(ii) If it is a fresh run, with no preceeding runs through the code (and so no 'c' characters stored), the code will just hang/crash (not responding error).
(iii) If an artifical delay is included in the loop the above error occurs too.

 

As mentioned above, what's most puzzling is that step into (F8) works fine, and the programming logic appears to work. That's why I'm left with the impression, time is probably the factor causing an issue; however, I don't have enough experience to know exactly what.

 

I would appreciate any help that can be offered. Many thanks.

 

 

Sub TestProg1()
Worksheets("Data In").Select
Worksheets("Data In").Range("S1").NumberFormat = _
"[$-x-systime]h:mm:ss AM/PM"
Worksheets("Data In").Range("Q1").Value = "r"
Worksheets("Data In").Range("R1").Value = "waiting"
Worksheets("Data In").Range("P1").Value = "<1,6400,400>"
Worksheets("Data Out").Range("A5").Value = _
Worksheets("Data In").Range("P1").Value



DoEvents

Do While Worksheets("Data In").Range("Q1").Value <> "c"
'Application.Wait (Now + TimeValue("0:00:01"))'This makes program hang
Worksheets("Data In").Range("Q1").Value = _
Worksheets("Data In").Range("TBL_CUR[CH1]").Value 'cell B5

Loop
Worksheets("Data In").Range("R1").Value = "finished"
Worksheets("Data In").Range("S1").Value = _
Worksheets("Data In").Range("A5").Value

End Sub

 

 

 

 

0 Replies