Hello guys,
I am kinda new to Arduino but experienced in C#/C++.
I am trying to build a project that will read from a serial device and display the data on an LCD screen using an I2C interface.
My problem is that I'm getting incorrect values when reading from the device. First of all what the device does is it is broadcasting 14 bytes answer continiously (you don't have to query it, it just sends the data over and over). I am using hterm as an auxiliary tool to see what the device does and it seems that it sends more than 1200bytes/second which sounds correct as if you divide 9600/8bits it equals to 1200 bytes. The bytes are 8 bit values, not 16.
So to determine the start of the message it sends 3 characters, 0-1-2 and then 11 bytes of data. When I use hterm and check the dec checkbox I can see correct values of the data. Same when I was testing using C# and read the data as Bytes (using ReadByte() in VS2012).
When reading the data from my Arduino I send them on my lcd screen and I get wrong values. I read the data using Serial.Read() and store them in a byte variable, then lcd.print them.
I am never able to see the start bytes 0-1-2 and it seems like the data is being repeated but it looks like they are 10(?) instead of 14.
So I have the following questions:
- Does anyone has a clue why I get different values than those on hterm? And never see the header bytes 0-1-2?
- I understand that 1200 bytes/sec are a lot for the Arduino to handle but I don't care if it discards some of them as I can determine correct full sets of bytes using the header bytes (IF they decide to appear)
Is the size of the Serial buffer 128 bytes indeed? What about the rest on the serial bus?
- Arduino's Serial.Read() reads the last arrived byte or the oldest in its Serial buffer?
- Is it possible to receive a corrupted byte or once I have managed to received a byte it must be correct?
- For being able to see the data I use a delay of 300-500ms. Is this affecting the reading of the serial stream? What is the Arduino doing during the delay? The device is still broadcasting data. Is it discarding them?
Thank you all in advance!