How would I go about getting two Arduino boards to communicate?
What I want to achieve is for each board to output one of three states (A, B, C) and for the receiving board to perform a different action dependant on the state of the sending board. I'm totally at ease with the software side of things its hardware advice I need:
Take 3 wires and connect them to three digital pins of each board ; one for each command A, B, C. For the emiting board configure them in output and for the receiving board in input [use pinMode(xxx,xxx)].
Then you just have to make some [digitalWrite] on the emiting board and some [digitalRead] on the receiving board to comunicate.
It can be more complicated but it's easy and it work !
If you don't have enough pins for an other project tell me... You can easely reduce number of pins to 2 pins by using a code in binary.
If you take only two pins the code betxeen cards will be 0 (zero) 0 (zero) or 0 1 or 1 0 or 1 1. 4 codes wih two pins.
On the reception card make something like :
byte receive_code = digitalRead (5) + digtalRead(6) * 2;
switch (receive_code)
{
case 0 : f1(); break; // execiute your fisrt function for 0 0
case 1 : f2(); break; // execiute your second function for 0 1
case 2 : f3(); break; // execiute your fird function for 1 0
case 3 : f4(); break; // execiute your #4 function for 1 1
}
Thanks for that - its exactly what i'd been thinking of doing in order to minimize the amount of wires used, which is important for this project....
Another (possibly obvious) question - do you know the maximum length wires can be between boards? i.e. would I run into problems if I had 6 meter lengths? or even greater?
How would I go about getting two Arduino boards to communicate?
What I want to achieve is for each board to output one of three states (A, B, C) and for the receiving board to perform a different action dependant on the state of the sending board. I'm totally at ease with the software side of things its hardware advice I need:
What should I connect to? (tx & rx?)
How many wires would it take?
How long could these wires be?
Ta for any advice!!!
Tom
The easiest way is to connect the TX1 --> RX2 and TX2 --> RX1 and then use the Serial Communication (as described in the reference):
Used for communication between the Arduino board and a computer or other devices. This communication happens via the Arduino board's serial or USB connection and on digital pins 0 (RX) and 1 (TX). Thus, if you use these functions, you cannot also use pins 0 and 1 for digital i/o.