Comm32 Logo
Home Button   

Topic:   Arduino to VBA Excel via SComm32

By: GuestPosted on: Apr 22 2016 at 09:01:29 PM
Hello everyone

I am trying to stream data from arduino uno to VBA Excel usin SComm32. It works very good at this point. The problem is that at the arduino serial monitor all data seems to be stable and clear, without interrupts and fast. At the VBA form that reads one cell on the worksheet I receive like random part of each data. Just to be clear from arduino I print to serial something like this "l35" and ends with "'n'" which is new line. On VBA side(SComm32) I get something like this"l3","33","l35","l"...How do I setup SComm in VBA to receive clear, proper each data. All I am doing is to read microphone sound level from Arduino and placing it to a progress bar on VBA form.
I would very much appreciate if I can have a VBA code that reads and copy to a cell 3 chars data clear and stable

By: GuestPosted on: Apr 25 2016 at 07:25:10 PM
Are you using an OnComm event? or are you working in a loop or timer polling the port.?

Bear in mind that when data arrives it arrives one character at a time so when you get one character then continue reading the port for a while to make sure you have all characters.

Also, if the arduino is simply pumping out data in a continuous stream then there's no way that windows can know where each piece of data starts and ends. It's just a long string of data. You'll need to read the port into a local buffer and then write code that splits the data as your application needs it.

By: GuestPosted on: Apr 27 2016 at 02:38:53 AM
Thanks for the replay.

Arduino is printing to the serial like this:
l35
l34
l34
l33
l34
l35
and so on. Each pack ends with line and in between are 20ms delay.
Scomm in VBA is set to inputlen=3, rthreshold=3, inputmode=...text. What will be the code for oncomm to read the inbuffer and extract exactly each 3 characters as one complete string.
Thanks again in advance.

By: Guest Posted on: Apr 28 2016 at 08:27:32 PM
Line end after each piece of data? So each piece of data is actually 4 characters because you must also include the line end.

I suppose you could set rthreshold to 4 and read 4 characters. But personally I would not do that.

I would set inputlen to 0 and rthreshold to 1. Then in the oncomm event append all incoming data to a local buffer/string. Then periodically inspect the string to see if it contains enough characters. Basically parse the string and extract your values.

By: GuestPosted on: May 2 2016 at 07:30:26 PM
Thanks. I did not know I have to include also the "println" as "n" and count as additional char.
About the oncomm event appending I couldn't solve it...Do you have an example code to do as you suggested. Also I suppose this way scomm (VBA) is slower that the data arrives and I loose a lot of bytes, so realy need to change my code.