Serial for debug

Hi,

I have a question for the use of the serial link, I would like to perform a kind of debugger when the connection is active i.e. if the usb is connected, but I believe that the 'Serial' function is always true even if the usb is not connected right?

For example , if USB is connected they print, if not, it's ignored

if (serial) {
Serial.print("");
}

yes. there's nothing on this type of serial interface to prevent the output of bits.

so you could build a board and power it independently without a USB and see the serial output if you plug in a USB cable and use a terminal emulator like putty to see the output at the time you plug in the cable without restarting the board.

Depends on the board which you conveniently forgot to mention.

Custom board made by me, with an atmega328pb (like an arduino uno with 328p)

In that case, if(serial) will indeed always be true.

There is no solution for this ?

Why do you care? You can just send the data, it will just disappear into nowhere.

if you're not sure, just plug your device into a USB power supply and see if your code runs (hopefully a flashing LED).

i just tried ... it runs

If you are using Serial for debugging check out my tutorial on Arduino Serial I/O for the Real World which shows you how to get a non-blocking Serial.print( ) that won't disrupt the rest of your loop.

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