ADMINS: I couldn't decide if this message belonged in "interfacing" (seems to, to me) or user circuits (it's that, too). Relocate/crosspost as you see fit :-)

I had an idea that it might be possible to switch the TTL-level serial lines of an Arduino between two (or more) other devices. I got a 4066 (cmos) quad bilateral switch to try it out, and it seems to be working -- and rather well, at that.

The 4066 "switches" (input/output go either direction) actually have SOME resistance (about 270 ohms, at 5V), so there is a little bit of a voltage drop through the device. But the output was still sufficient to drive the serial-input chips that I tested with.

My simple demo circuit switches an Arduino TX signal between either of two outputs, but adding the other two gates from the 4066 would allow the RX line to be switched, too, of course.

I can't see any reason that something like a binary decoder (such as 74138 3to8) couldn't be used to control additional 4066 switches, and allow the use of fewer Arduino pins for "channel" control.

I can't see any reason that something like a binary decoder (such as 74138 3to8) couldn't be used to control additional 4066 switches, and allow the use of fewer Arduino pins for "channel" control.

Great idea and it certainly that could be made to work. And a more ambitious integration might be to have pull down resistors on the 74138 channel selections pins such that when the Arduino is first powered up and all I/O pins default to inputs the channel 0 selected could then route the arduino's USB converter chip to the hardware serial pins 0 & 1. Then under program control the hardware uart pins could be routed to up to 7 other different users. This could be useful to setting up a small local RS-232 network of up to seven other Arduino slave modules that could communicate back to the central Arduino.

I had an idea a while back where you use 2 4051 mux IC's to multiplex the RX and TX to 8 devices.

One 4051 would handle all the RX lines the other all the TX lines.In theory this should work using only a few Arduino pins. And it could be extended to as many as needed.

The problem with this and all other multiplexing / switching solutions is that it will only work in a system where you only have "call / response" type communication. You can only deal with one line at at time, so if device y is sending data to you while you are reading or sending data to device x, the data from device y will be lost.

I've got applications where the chips from E-Labs (www.elabinc.com) are VERY useful - stepper motor controllers, LCD display drivers, 4x4/8x8 matrix keyboard encoders, and a few others. All the E-Lab chips use serial I/O at TTL levels, and I'm only dealing with one of them at a time, so this serial switching system works REAL well for that. It would be easy enough to take any "I have data to send" signals from external devices and OR them into an interrupt on the Arduino to tell it to switch to a different TX/RX pair...

@DMerriman, I am not saying that you replace serial communication with i2c or SPI. What I am trying to suggest is that there are ICs that on one side you use i2c or SPI (Arduino side) and on the other side you manage TTL level UART (outside world). If you need RS-232 levels, you add a MAX232 or equivalent chip.

This solution will require a library, for sure, similar to soft serial.