Serial begin and print commands consume any power?

Regarding the Electron / E-Series products…

During the development process, my firmware had many Serial.print commands for debugging purposes. It’s great to just plug in USB, open a COM port, and see what’s going on. But this begs the question…does keeping these commands in my code consume any power when the USB is not plugged in? Should the the Serial commands be disabled in a production environment if I wanted lower power consumption?

For example:

void setup() {
Serial.begin(9600); //How much current does opening the serial port consume?
Serial.println("Hello world"); //How much current does each print command consume (based on buffer size)?

Compared to the rest of the power usage on a cellular device, the amount will be negligible.

On Gen 3 devices (Argon, Boron, B Series SoM, Tracker SoM) the USB block within the nRF52840 MCU is even shut down when there is no power on the USB port.

However, you may want to instead use, as a global:

SerialLogHandler logHandler;

and then for logging:"Hello World");

It aiso takes sprintf formatting, and there are other versions like Log.error. The main advantage of these is that you can turn them off by removing one the LogHandler line instead of every place where you’re logging. You can also control the logging level per-module. Also, Serial is not thread safe, and Log is.

And LogHandler can be easily directed to other locations, like Serial1, and there are community log handlers for things like PaperTrail (network-based logging), SD card, BLE, and more.

Perfect. Thanks for the answer. I’ll plan to use the SerialLogHandler in the next version. Shouldn’t be too much to convert everything over