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

Copper Contributor

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


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

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

End Sub





0 Replies