I've already got 3 serial devices on a mega and might want to add two more. Fortunately most of the devices are polled and polled slowly. I was thinking of having two devices share an RX and TX and only powering on one at a time, but I figured there should be a more elegant solution to switch the outputs using digital pins. Before working up something using transistors/AND gates, I figured there must be a standard way of doing this. Is there?
I do it with a couple of 74HC4067's. I set the address for the 4067, which in turns connects one of the 16 I/O pins to a single I/O. If your devices are self reporting, i.e. don't need to be prompted for a reply, you'd only need a single 74HC4067 to do it.
Mel
The best solution would tend to depend entirely on what these devices are, and what their protocol is.
They are devices that measure environmental parameters (Conductivity, light, dissolved O2, etc).
They typically have a serial signal equal to Vcc when high. Vcc can be 3-5.5v and I usually give them 5.0v.
Messages are polled, So I send an 'E' and I get a string of numbers back '23.45,456.7,2.521'. I poll no more than every ten seconds.
Paul__B:
The best solution would tend to depend entirely on what these devices are, and what their protocol is.
74HC4067 might be overkill:
A 74HC125 would be plenty for 2 devices, or a pair for 4 devices.
Add a pullup or pulldown on Tx on the device side so the line is not floating.
Enable 1 OE at a time for Tx to a device and Rx coming back.
I was thinking of having two devices share an RX and TX and only powering on one at a time, but I figured there should be a more elegant solution to switch the outputs using digital pins. Before working up something using transistors/AND gates, I figured there must be a standard way of doing this. Is there?
If you are having the master poll the slave units and then receive the reply from the slaves, you can connect the master tx pin to all the slave rx pins. the master can include a slave identifier in the slave request such that such that only the desired slave responds. You can put a diode on the slave tx pins so all the slave tx lines can be connected to the master rx pin.
They typically have a serial signal equal to Vcc when high. Vcc can be 3-5.5v and I usually give them 5.0v.
That doesn't really sound like a serial signal to me. Or perhaps it's just the way you expressed it. Are these "serial" devices actually sending you serial ascii or binary data which you need a uart to read, or just turning their output signal on and off like a thermostat ?
Have you tried SoftwareSerial?