Pull up / pull down on Tx / Rx pins?

I have a setup where I'm speaking over USB serial to a Mega. The Mega has it's Serial1 hardware Tx/Rx pins connected to a usb jack. I run those over a short (3 ft) cable run, along with some power and gnd, to a Micro. Tx is connected to the Micro's Rx, and Mega Rx to Micro Tx.

All is working super well while this is connected and running. I'm working on the circuit / code to a do a better job detecting connection and disconnection of the Micro USB, because I want to be able to plug and unplug this whenever in the application and have things go gracefully.

One thing I'm noticing is that when it's unplugged and I read Serial1 on the Mega, I get garbage, because the Tx/Rx are now floating connected to the USB jack which isn't plugged in. Obviously if I detect the disconnection because a ping isn't returned, I'll just stop reading the port. But, I was wondering if there is a best practice to be tying those pins to GND or something via resistors or something to prevent this floating state.

Thanks!

But, I was wondering if there is a best practice to be tying those pins to GND or something via resistors or something to prevent this floating state.

No but tying them to 5V through a pull up resistor would work because a logic one is the idle state of an RX line. Making them a logic zero results in a "spaced out" error in the UART and constantly receiving null characters.
However you should just be able to enable the internal pull up resistor to stop this.

Mike,

As usual, you're the man. That completely did it. Any reason Serial.begin() doesn't just do this, or why it's not mentioned as an idea in any of the serial tutorials?

Is this uniquely a good idea (to use the internal pullups) because I'm using a connection that is sometimes broken when the cable is disconnected?

Also, any tips for quickly detecting the connected/ disconnected state? I only have the four conductors connecting - Vcc, Gnd, Tx, Rx, so was thinking a ping solution.

Yes a ping would work if you need to take a different course of action if the two are separated, but often you might not.

Any reason Serial.begin() doesn't just do this, or why it's not mentioned as an idea in any of the serial tutorials?

Well it is normally connected to the USB / Serial chip through a 1K resistor so their is no need to do it.

Thanks Mike.

I've written a rather lengthy (and as thorough as I could be) post about the problem I'm experiencing just now over on the Adafruit forums. I didn't know what the protocol was on reposting it over here, so I'm not going to do that yet, gonna give folks there a chance to take a peek.

But if you have a moment, I'd super appreciate you taking a look. Link below, think I've provided all the information in there (video and schematic included) that might help you guess what's going on.

I'm open to any design or code change!

https://forums.adafruit.com/viewtopic.php?f=47&t=121717