Does Serial.print slow the Aduino down?

I'm making a timing critical application that needs to monitor switch changes to 1-2ms accuracy. I'm finding the box seems to work well but i need to do some debugging.

I then added some logging via the serial output to see what the Arduino is doing at what times, usins millis() to show timing. I found that the Arduino slowed down - its response to switch changes seemed to get much slower. Also there were 50-100ms delays in the logging of lines of code that are next to each other.

Are all the delays being caused by the serial output? If so, how to I accurately log from this application? I need to be able to analyse what is happening to improve the project.

Thanks!

Rob

This response from a friend:

"The serial comm is only 9600bps = 1200 bytes pr second, so it'll take at least 0.8ms to send a char. A solution could be to buffer all the logs in a string, and only send it through the comms at the end."

So is the serial comms actually pausing the Arduino for however many ms? That would explain whats happening.

Does anyone know how to append variables and strings to strings to make a log string - i haven't been able to do that!

Rob

I suggest you create an array to hold the values you want to log, then when that log gets full you can call a function that transmits the contents of that array over serial.

  • Ben