I have two XBee's connected to two Arduino Uno boards (one for each XBee). I connected each XBee to the X-CTU software, and have set the following:
XBee 1
Pan ID = 4270
DL = 10
MY = 20
XBee 2
Pan ID = 4270
DL = 20
MY = 10
Both
DD = 10000
IC = FF
IR = 32
Therefore, they should be on the same network and see each other as the 'other person' each is talking to. I'm using the TX and RX pins of the arduino and the XBee to communicate over the serial port.
When testing if each can hear the other, I loaded one arduino with this code:
#include <SPI.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print('x');
delay(1000);
}
Then another with this:
#include <SPI.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(7,OUTPUT);
digitalWrite(7,LOW);
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available())
{
char getData = Serial.read();
if(getData == 'x')
{
digitalWrite(7,HIGH);
delay(500);
digitalWrite(7,LOW);
delay(500);
}
Serial.print(getData);
getData = ' ';
}
}
This works perfectly. One LED will light up on the correct arduino in half second intervals. However, when I try to make them both communicate at the same time to each other, nothing happens. Neither LED will light up. The code for both arduino's is:
#include <SPI.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(7,OUTPUT);
digitalWrite(7,LOW);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print('x');
delay(1000);
if(Serial.available())
{
char getData = Serial.read();
if(getData == 'y')
{
digitalWrite(7,HIGH);
delay(500);
digitalWrite(7,LOW);
delay(500);
}
Serial.print(getData);
getData = ' ';
}
}
But for one arduino I change the code to Serial.print('y')
and if(getData == 'x')
to listen for the other one. I also have tried delaying one arduino in the setup by one second to offset the sending and recieving, but that also doesn't help.
I need them to be able to listen and talk to each other, maybe even at the same time like this example. I'm trying to create a proximity sensor in, lets say the 'back', area communicate with the 'front' area, and an accelerometer and two switches from the 'front' communicate with the 'back'.
Is there any settings I can change in X-CTU, such as the baud rate or the amount of packets re-sent, to overcome this problem? Or is this merely a code issue?
I do have the power connected to the 3.3V pin of the arduino, and I'm using 470/220 Ohm resistors as voltage dividers for the output pins from the arduino to the XBee, so I don't think voltage is an issue here.
Also, I have disconnected the arduino from the computer. I'm powering it via the USB-A to USB-B cord -> 13000 mAh 5V DC rechargeable battery, so there should be no interference with the serial data lines. Pin 2 (RX) of the XBee is connected to pin D0 (RX) of the arduino, and pin 3 (TX) of the XBee is connected to pin D1 (TX) of the arduino.
Thanks for your help.