Controlling 2 devices using one serial port

Hi Gents,

I have been playing around with the Arduino Serial port on a Nano, and need to read data from one Serial Device and then spit the data to another. I have tried implementing a software serial port and using the hardware one as well but noticed that I sometimes lose the start or end bit of the stream every now and then.

Because I dont need to use both ports at the same time, could I switch between ports using software, using serial.begin(9660), then read the data; and then serial.begin(115200) before printing the data? In theory it seems possible but have you learned souls ever successfully tried this or can advise me of the possible pitfalls?

Ta in advance.

I have tried implementing a software serial port and using the hardware one as well but noticed that I sometimes lose the start or end bit of the stream every now and then.

Let's see the code.

Because I dont need to use both ports at the same time, could I switch between ports using software, using serial.begin(9660), then read the data; and then serial.begin(115200) before printing the data?

Are going to be unplugging and replugging wires, too? Or do you intend to talk to both devices are the same time?

will ping the code over off my other machine, its just decided to die..

I was wondering whether the 2 could both be electrically connected but I just talk to them when I was in software...please let me know if I am being really dumb here...

please let me know if I am being really dumb here...

Think of the serial port as a phone line. You have one phone on the Arduino end and one phone on each of the devices you want to talk to. You are talking about setting the two devices up on a party line, and you want to talk to just one of them. Won't work.

You can certainly use one hardware serial port to receive data from one device and transmit data to another. I haven't tried to do this with different baud rates, but you could try closing the port with Serial.end and then reopening it with Serial.begin at the new baud rate. Not much documentation on Serial.end though.

Another approach would be using RS422 or RS485 in party line mode. Best would be to have only one master. Slaves do only send after being asked something, this prevents collisions. You need some additional hardware to get signal levels (differential signal, 5V) but this is quite easy and you can go very long distances. For RS485 you need another pin for XON/XOFF.

Transmitting to two different devices is easy, just use an identifier for the desired receiver (hey Bill, yada, yada, yada... hey Bob, yada, yada,yada...). Receiving from two different devices could have similar addressing, but a hardware tweek might be needed to keep one device tx line from tryung to pull the other devices tx line low since they are connected together. A pair of diodes might work for this.