How to detect if Serial is connected

Hi,
on my Gboard Pro (Mega2560) there is no USB chip. To work with it a little board, FOCA, is necessary which is converting the USB signals to simple serial signals.

In my application the serial link "Serial" always is active and is sending data on Serial. If the FOCA is connected to Gboard Pro I can see the data on the Serial Monitor.

Now I want my application to detect if the FOCA is connected, and if it is, some simple command inputs from the Serial Monitor shall be executed.
To detect FOCA I tried to just read the TX0 input. But the result is wrong. Measuring the TX0 line with a volt meter tells me that it is HIGH when FOCA is connected. But digitalRead(1) tells me LOW.

The problem might be that with "Serial.begin(baud)" the TX0 line is set to OUTPUT and "digitalRead(1)" expects it to be set to INPUT.
Is this the reason?
Is there another solution than connecting TX0 to a free input pin and read from that pin?

SupArdu

The problem might be that with “Serial.begin(baud)” the TX0 line is set to OUTPUT and “digitalRead(1)” expects it to be set to INPUT.
Is this the reason?

No. digitalRead() will happily read the state of an output pin. There are extra resistors on the TX and RX pins that make them less suitable as input pins, and it is likely that these are what are causing your problem.

I really don’t understand why you care. The code should read any serial data that arrives, regardless of whether or not the FOCA is attached. Of course, if the FOCA isn’t attached, no serial data will arrive.

The code should read any serial data that arrives, regardless of whether or not the FOCA is attached.

You are right, it is so easy :confused: