Electronic – Arduino Serial Buffer Overflow

arduinoserial

Can I detect whether bytes are getting dropped by the Arduino Serial driver because of buffer overflow (i.e. if I'm not keeping up with my input stream)? If so, how?

Best Answer

If you're using SoftwareSerial, I think you have no chance of detecting serial overflow, because the docs say you can't use Serial.available. But even if you were using the hardware serial library, I don't think you can detect if bytes are getting dropped. The closest thing you could do is use Serial.available to see when you're about to overrun the buffer.

But this is really what hardware and XON/XOFF flow control are for. When the serial driver supports this functionality, you can prevent buffer overflows because the host will tell the client when no more data can be accepted over the serial line, and vice versa.

I don't think Arduino supports any kind of flow control, especially since begin() only takes a serial port speed as a parameter.