Pages: [1] 2   Go Down
Author Topic: Communication between Arduinos  (Read 3566 times)
0 Members and 1 Guest are viewing this topic.
Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been trying to make a simple program to test communication between two arduinos. I have connected the RX/TX-pins and also ground. I have programmed one of the arduinos to send 1 och 2 (DEC) with a 1 or 2 second delay in between. The second arduino is programmed to light the led on pin 13 if it receives a 1, and to turn it off if it receives a 2.

The TX-light is blinking on the "sender", butnothing happens on the "receiver. Since i have not yet been able to get my hands on any external power-supply for the arduinos, i have them both connected to my computer via the USB. (The arduinos are Arduino NG's btw). I have also noticed that i cannot upload the programs to the arduinos if they are connected together. I must disconnect them from eacother everytime.

I'm a total electronics newbie, so maybe I'm making some obvious mistake here?
Does it matter wether i connect the ground at the power connections (bottom of the board) or the GND pin next to digital pin13?

Does anyone have any suggestions? I could upload my code here as well, but it's on my home computer, and i'm not there at the moment. If you wish i could upload it when i get home.

Edit: Added a picture:
« Last Edit: December 05, 2006, 08:38:45 am by Pinky » Logged

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I assume you connected the RX on one board to the TX of the other, and vice-versa (not TX to TX and RX to RX).  Can you post your code?  It's possible one side is using ASCII and the other is using binary.  
Logged

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

yes, the TX on one is connected to RX on the other one, and vice versa. I will upload the code when i get home.
Logged

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

Ok, i rewrote the code quickly, it's a little different than the one i tried at home i beleive, but i get the exact same problem anyway.

Sender code:
Code:
int a = 1;
int b = 2;
;
          
void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.print(a);
  delay(1000);
  Serial.print(b);
  delay(2000);
}

Receiver code:
Code:
int ledPin = 13;
int received = 1;
;
          
void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  while (Serial.available() > 0)
  received = Serial.read();
  if (received == 1) {
    digitalWrite(ledPin, HIGH);
    }
    if (received == 2) {
      digitalWrite(ledPin, LOW);
      }
  }
Logged

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

Ok, i beleive I'm closing in on a solution  smiley-razz

When i disconnected the "receiver" from the computer, it seems to be getting power from the "sender" and it seems to kinda work, except for the power to the receiver being a little low, so sometimes the led doesn't stay lit like it should. If my guesses are correct, this can be helped by also connecting the 5V+ between them as well? (i don't have enough cables on me to try this at the moment)

So the problem really seems to be only when both arduinos are connected to a computer as well.
« Last Edit: December 05, 2006, 09:55:06 am by Pinky » Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem may be due to the fact that the FT232 (the usb/rs232 chip) is driving the receiver while you are trying to drive the same receiver from the other arduino.

Digital inputs are generally meant to have only one driver.  Multiple receivers are OK (within limits; google "fanout").

-j
Logged

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

Quote
The problem may be due to the fact that the FT232 (the usb/rs232 chip) is driving the receiver while you are trying to drive the same receiver from the other arduino.

Digital inputs are generally meant to have only one driver.  Multiple receivers are OK (within limits; google "fanout").

-j

Hmm, i''ll have to get separate power supplies to each then.

Right now it almost works like it should, with usb powering the sender and the sender in turn powering the receiver.
At the moment they are only connected with ground and 9V+, but the receiver seems to have problems keeping the led lit. It just lights up while communicating, every 1 or 2 seconds depending on operation (see the sender code), but every once in a while it keeps lit for 1 second, like it should.
When connected with 5V+ instead of 9, the pwr-led lit up, but nothing seemed to happen.

Maybe i should try connecting both? Is this safe?
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Separate power supplies aren't going to help if the problem is multiple drivers.  The FT232 is trying to make the rx pin see 0V; you are trying to make the rx pin occasionally see 5V (via the TX pin from the other arduino board).

There should be only one driver (e.g. the FT232 or TX from another board) on the pin.

Do not try to hook up power to both regulated and unrelgulated at the same time; you will not make things better, and you may manage to fry some hardware.

Look around for software serial (it's posted on the forum somewhere, IIRC) and try to use pins other than 0 and 1 for this.

-j

[Oh, and it's not an obvious newbie mistake - the newbie mistake is forgetting the signal ground.  smiley ]
Logged

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

Quote
[Oh, and it's not an obvious newbie mistake - the newbie mistake is forgetting the signal ground.  smiley ]

If i hadn't searched the forum for info on this before i started trying I would have missed that too smiley-wink

What i meant was that if i get separate power supplies i can disconnect them from the computer, thus not using the FT232.
If i dont connect anything on USB it is not activated, am I right? And then there will only be one driver.
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
What i meant was that if i get separate power supplies i can disconnect them from the computer, thus not using the FT232.
If i dont connect anything on USB it is not activated, am I right? And then there will only be one driver.

I get ya now.  Yes, if I read the schematic correctly the FT232 is only powered from the USB connector, not from external power.  Switch the PWR_SEL jumper to EXT, the hook 'em up to an external power source (and disconnect the USB cables), and it should work.

-j
Logged

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

Ok, one last question: why are the RX/TX-led sonly blinking on the receiver, but not the sender?  smiley
It's not really a problem, but it seems strange to me.
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The TX/RX LEDs are driven by some dedicated IO lines on the FT232.

-j
Logged

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

Ok, i got a 9V battery adaptor for the arduinos now. Problem is that the program does not start running until i've connected them to USB. I can then remove the USB cable and it will keep running.
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could be this problem: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1161093462

stick a 10k resistor between RX (pin 0) and ground and see if that helps.

-j
Logged

Forum Administrator
Offline Offline
Newbie
*****
Karma: 3
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

That issue has been documented quite a bit in the forum...

You should pull up the RX and TX pins of one of the two processors with a , say, 100k resistor.

when arduino is powered with an external power source the RX and TX pin on the processor are left "floating"

this means that they receive noise from the environment that gets interpreted by the bootloader as data coming in... this prevents the bootloader from timing-out after 7 seconds and running your code.

i.e. your program never starts.... using the pullups  keeps them in a known state for the time needed for the bootloader to realise that nobody wants to download new code into the processor and after about 7 seconds your code runs



massimo
Logged

Pages: [1] 2   Go Up
Jump to: