bi-directional communication example

Does anyone have a basic example of bi-directional arduino code that allows two arduinos to send instructions to each other? For example, I would like to be able to use an analog sensor on each board to send information to each other so that they can light up each others' LED.

I don't have any code, but I'm full of ideas :P

I don't see why you couldn't connect serial port to serial port, then switch to transmit mode when you have something to send and back to receive mode while idle. Then just Serial.print things at each other. Assuming the board can switch from serial TX to RX fairly quickly, it'll be about a bidirectional as anything (read: few ms delay, maybe). This uses one physical connection for half-duplex communication, but each side gives up the duplex fairly quickly.

If you're looking for a closer simulation of full-duplex, I think you may be able to assign two other pins to also be a serial interface. Then, in the same loop cycle, you could send and transmit at once.

My XBee examples ( http://tinyurl.com/5rfmrz ) perform bi-directional communication. Each of the boards has two buttons. When the state of a button changes the change is transmitted the other board. The receiving board parses the simple string and performs an action.

In this case the communication is through a wireless connection between serial ports. The same program would work by connecting the serial ports with wires (and removing the XBee configuration commands).

If you can use the serial port the communication is a lot easier. You could do a similar thing with the digital I/O lines. A lot more work.

(* jcl *)


www: http://www.wiblocks.com twitter: http://twitter.com/wiblocks blog: http://luciani.org

Thanks jluciani! And thanks Robert for contributing some ideas as well.