Serial print commands for debugging

I put a few Serial.println() commands in my code in case I have issues and need to see some data from variables, etc. But in the normal operation of my projects, the Atmega chip isn't connected to a laptop so the serial port isn't used. Do these serial command still execute or slow down the operation of the code?

Yes they do.

There are lots of ways to have 'debug' and 'not debug' code. Here's one: https://arduinoplusplus.wordpress.com/2017/05/01/simple-debugging-for-arduino-sketches/

1 Like

That look like a very clean solution!

I used to define a "debug_byte" the same way.
But I used it differently like:

#define DEBUG_byte 1
...
if (DEBUG_byte) {Serial.print("setup on-going");

so I need that code each time I need a print, anywhere in my sketch!
so I will now use the hint you provide! :grinning:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.