Serial Monitor Skips Bytes (possibly due to Serial.println() misuse)

Hi everyone, I am a noob, but I tried to do my homework. So here is the deal:

I decided to test how fast the Serial class can be used to send short, high-frequency messages to the serial monitor. Here is my code:

void setup()
{
  Serial.begin(19200);
}

void loop()
{
  Serial.println("ABCDEFGH");
  delay(100);
}

When I open the Serial Monitor in the Arduino IDE, and set the correct speed, it starts receiving the "ABCDEFGH" message, as expected. However, after several seconds, some characters start skipping:

...
ABCDEFGH
ABCDEF
ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH
ABCDEFGH
BCDEFGH
ABCDEFGH
...

I don't think I am stressing the bandwidth, because the bit rate needed here is (8x8 bits)/(0.1 s) = 640 baud. (I tried other speeds too, and at higher speeds the connection is a little better, but I still see missed characters several times per minute). At much lower speeds (i.e. >70% of the necessary speed) a big fraction of characters gets skipped. I am connected through the USB port on the Uno R3.

I also increased the delay to 1 full second, and while there are much errors per line, some still happen.

Is this an unavoidable, intrinsic issue with serial communication, even for very short messages? I recognize that when a lot of data gets transferred, hash sums etc. are necessary - are they also necessary for such small communications? Or is there something I may be missing?

Thanks in advance.

I recognize that when a lot of data gets transferred, hash sums etc. are necessary - are they also necessary for such small communications?

Depends on how robust you need the communication to be. In general, the answer is yes.

Several things can cause bytes to be dropped - noise is the biggest issue. Any corrupt bit is going to be dropped, resulting in the loss of a byte,

PaulS:

I recognize that when a lot of data gets transferred, hash sums etc. are necessary - are they also necessary for such small communications?

Depends on how robust you need the communication to be. In general, the answer is yes.

Several things can cause bytes to be dropped - noise is the biggest issue. Any corrupt bit is going to be dropped, resulting in the loss of a byte,

Fair enough. Doesn't this severely impede the ability for direct system control directly from a PC though? (I.e., if all commands have to be hash-checked)? Or are there ways around this issue?

No, not seeing this at all.
What is your environment?

because the bit rate needed here is (8x8 bits)/(0.1 s) = 640 baud.

Small thing, but that's (10x8)bits / (0.1s) = 800 baud.
But agreed, it shouldn't be going wrong.

Hi,

Is it possible you are overflowing the internal transmit buffer? It sounds like you get more errors at lower baud rates, which could happen in this situation.

You might try calling Serial.flush() after you send the data. This function will block until all the data has been sent.

For the most reliable transmission you probably do want to include a checksum, or have the receiver send an acknowledge message back to confirm receipt. Errors can occur even in very short messages. I had to do this to get a 4D Systems display to work correctly (MegunoLink Pro | The swiss army knife for Arduino).

HTH
paul

AFAIK the print() function blocks if the buffer is full, I can't find the appropriate source code but certainly write() does and I thought all the print()s call that.


Rob

but certainly write() does and I thought all the print()s call that.

Correct. Only the write() methods actually send data to the output device. The print() methods convert the value to a string, to be sent by the write() method(s).