two serial outputs used together?

Hey folks,

I need a teeny bit of hardware (or software) help. I've got a serial i/o device that I want to communicate with in a debug mode, and a high speed mode.

In debug mode I want to use NewSoftSerial and a digital output pin to send to the device, and in high speed mode I want to use the UART Tx pin.

(In debug mode the UART Tx pin is monitored by the host IDE)

What I would like to do is tie the digital out pin, and the UART Tx pin together and switch between them as needed. I can set the NSS pin to input, and activate the internal pullup, while I'm using the UART. I've also tried to do the reverse when I switch to the NSS pin.

When I do this through the UART it works great, but switching to the NewSoftSerial send does not?

Is there some trick to setting the Tx output pin into input mode?

Or is there a simple circuit I can use to prevent the two transmit pins from interfering with each other?

thanks, Robert

I'm not sure I understand, but is this correct? You want to talk to a high speed serial device, but in debug mode you ALSO want to be able to send debug info to the Arduino console, right?

Is the device both TX and RX? Why not permanently hook it up to a NewSoftSerial soft port?


Hi Mikal

because NSS halts interrupts during the transmit which interferes with other more time critical processes. It's ok for debugging, but when I want to use it "for real" i'd prefer to use the uart

thanks, Robert


I think in that case I would just accept changing the physical connections between debug mode and release mode, and make some kind of DEBUG flag in the source:

#define DEBUG 0

NewSoftSerial device(2, 3);
#define device Serial

Would something like that work?


Hi Mikal,

Thanks for the reply. That is what I am doing. I use a compile time #ifdef to switch between debug and run modes. However if I wire the NewSoftSerial Tx pin together with the Serial Tx pin to the receive device, then running with Serial is ok, but NewSoftSerial can't transmit.

I found a Serial.end() implementation here:

Which I am hopeful will fix the problem. I'll report back as soon as I get some results + or -

thanks, Robert

Yeah, I don't think you should wire those two pins together. You have NewSoftSerial trying to drive the combined pins while the UART is also driving them sometimes in the opposite direction. This is not a good situation.


The rule is you should never wire two output pins directly together, it can create short circuit conditions if one pin is high and the other low.

It sounds like you wish to "wire or" two output signals together to create a composite transmit signal that is data from either output (but not at the same time or garble will result).

And that can normally be done with some isolation diodes and a pull-up resistor. Each output pin should wire to the cathode end of a small signal diode (a 1N4001 will work also), the two anodes attach together to one end of a 1K ohm resistor, the other end of the resistor wires to +5vdc and finally wire the diodes and resistor junction to your external serial device's receive terminal. Be sure the external device has a ground wire to the Arduino's ground pin.


Hi Lefty,

Thanks, that sounds like what I need to do.

Also, I thought rs232 was normally 0, with a logic 1 start bit, so the output should be normally be 0 ? So shouldn't the pull-up resistor be like 10k so I'm not drawing more current?

oooh, chance to draw an ASCII circuit diagram:

Arduino +---/\/\/--- +5v pin 1 - Tx ___|/|| 10k || | | pin 8 - NSS __|/||_____________ Serial Rx on Device || 1N4148

ground ------------------------- Device ground

Does this look right?

thanks, Robert

Your drawing looks great. Resistor value not critical. RS-232 is inverted logic, but TTL serial as used by Arduino is true logic, so idle (stop bit condition) is a high and a start bit goes low, data bits are true logic, high = one, low = 0.

Most RS-232 to TTL converter chips, like the MAX232 provide the logic inversion as well as the voltage conversion.


Hi Lefty & Mikal,

thanks for your help. T^he two diode solution worked perfectly.

I can switch at compile time easily, and I'm guessing I could switch at run time too, but there is now need of that, and for the finished version I can build it without NewSoftSerial saving a bunch of code space!

thanks again Robert