Serial.println = Clear buffer?

Hi all,

Quick question that I couldn't find a definite answer to. Say hypothetically I have a arduino with a large code with lots of Serial.println's in the code as a debug. When I have a computer connected to the arduino, it will send the strings over serial as it should. So... My question is, If I have all these Serial.println's not serial.print's inside my code without a computer connected to the arduino. Does the arduino automatically clear out the buffer or does it start to accumulate and overflow the buffer?

I would assume it sends it out on the Serial line and forgets about it. aka clears the buffer. However I can't find any real documentation in my searches.

Any info / resources would be greatly appreciated. And I don't think a sample of code is necessary for this question but if so I could easily type something up.

  • Matt

It will clear the buffer because it will just send it. The Arduino has NO knowledge whatsoever if something is connected or not.

If I have all these Serial.println's not serial.print's inside my code without a computer connected to the arduino.

Serial.print() and Serial.println() both behave in the same way. The latter simply adds a linefeed to the output without it needing to be part of the explicit data printed. It does not, as the name might imply, print a line of data.

Depends on the microcontroller. You can bring a Leonardo (and probably a Micro) to a (near) grinding halt by disconnecting the USB cable (while it's powered from external power) and keep on printing.

An Uno is another story; being connected or not does not make a difference.

Thank you all for your answers.

  • Matt

@sterretje, true. I (wrongly) automatically assumed a "standard" Arduino like a Uno / Pro Mini / Nano / Mega etc. The ones without build in USB support which just use UART.