Pages: [1]   Go Down
Author Topic: Two arduino boards communicating  (Read 6344 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

1. What should I connect to? (tx & rx?)
2. How many wires would it take?
3. How long could these wires be?

Ta for any advice!!!

Tom smiley

Logged

Poitiers (France)
Offline Offline
Full Member
***
Karma: 0
Posts: 136
Ca va j'vais le faire !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Tom,

   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 !
« Last Edit: August 05, 2006, 06:07:28 pm by Benoit » Logged

Cordialement,
Benoît ROUSSEAU

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for that Benoît,

Simple when you know how! - I hadn't really got my head around the fact that you can specify the digital pins as both in and out.


Tom

P.S. Sorry for taking so long to reply, i've been away from computer land for a while;)
Logged

Poitiers (France)
Offline Offline
Full Member
***
Karma: 0
Posts: 136
Ca va j'vais le faire !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

  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
  }


Logged

Cordialement,
Benoît ROUSSEAU

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

Poitiers (France)
Offline Offline
Full Member
***
Karma: 0
Posts: 136
Ca va j'vais le faire !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Tomski,

About 6 meters it will be allright, above maybe. I have two arduino boards just at my left wich have 6 meters of wires between them and its ok.

If you want more distance of cables, test it or use radio waves. If you can/want you can use IR to comunicate like here :
receiver : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1152894029
emiter : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1152957061
Logged

Cordialement,
Benoît ROUSSEAU

0
Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Great stuff - thanks for the help.
Logged

California
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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:

1. What should I connect to? (tx & rx?)
2. How many wires would it take?
3. How long could these wires be?

Ta for any advice!!!

Tom smiley


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.

    * Serial.begin(speed)
    * Serial.available()
    * Serial.read()
    * Serial.print(data)
    * Serial.println(data)

Regards,
David
Logged

Pages: [1]   Go Up
Jump to: