Serial output buffer - delayed


I have a question about the Arduino serial connection. When I am writing "at full speed" (No delays in the loop function) messages to A serial monitor, it gets behind. For example: when I output the temperature I see it changing, but over time the messages are getting behind. And this builds up very fast. So after 5 seconds there is a delay like 1 sec and after a minute this delay can be > 30 seconds. (I always use a baud rate of 115200)

What I do want to know is, if this is a problem with Arduino OR with the receiving module (This can be the Arduino serial monitor, Visual studio with visual micro serial monitor or my own C# written serial monitor) all these receiving ends are getting behind. But no messages seems to be lost. So they have to be stored somewhere. I want to know how this system works and how I can make my monitor real time?

My end purpose is reading RPM, GPS, Acceleration and temperatures of my RC car. But this needs to be real time.

What I do want to know is, if this is a problem with Arduino OR with the receiving module

It is not a problem with the arduino or with the receiver it's a problem with your code. You are sending to much data.


I thought it wouldn't be a problem. How is it possible that a arduino is capable of generating more output over a serial line then A fast PC can process. Like I said, messages don't get lost its just getting behind.

The Arduino buffers serial data sent and received. If your sketch is generating data as fast as it can be sent then the Arduino will fill up the buffer, which means the data will be delayed (by however long it takes for the data to pass through the buffer).

On the receiving side, the PC will do a similar thing but this time with much bigger buffers. If data is arriving from the serial port anywhere near to close to the speed that it is being read by the application then the PC operating system will buffer the incoming stream. (A similar effect would occur on the writing stream if your PC application is sending data back to the Arduino.)

All of this buffering delays the data so trying to send the data as fast as possible can actually make the problem of stale data worse, not better. It is much better to design the sender to ensure that it does not generate data faster than it can be transmitted, so that the sending and receiving buffers remain empty.

Also, it's easy to design applications that read from a serial port to be so inefficient that they struggle to keep up with a serial port, even when they are running on a PC with massive excess memory and processing power available. We have no idea what code you're running on the PC or how well the serial port handling is written.

Another thing to keep in mind is that it might not be the receiving and process of serial data that is lagging behind. It might simply be the updating of the display that is lagging behind. The Serial Monitor application allows scrolling back through a lot of data. That data needs to be stored somewhere, in space that is dynamically allocated. As the amount of data grows, scrolling gets slower and slower.

It isn't clear what application is receiving your serial data, but you might want to look at whether it buffers any of it for display purposes.


This is very helpful! I think showing and processing the big amounts of data are the bottleneck. But then again, do I need that much data? Answer: no. Sending data 10 times in a sec is still a lot, but "realtime" enough.

You haven't said how fast the Arduino is gathering data.

At 115200 baud the serial link can send about 11,500 bytes per second. The Arduino could probably gather data much faster than that unless you limit it.