I'm trying to setup 2 way communication using XBees and Arduinos Uno (Coordinator) and Mega (Router) both with XBee shields. The XBees have been configured using the XCTU software and can communicate 2 way via the software. They also work properly when the Router sends Serial Data to the Coordinator, but not the other way around. There appears to be a problem with the Router XBee sending Serial data to the Mega.
Here is the simple code I tried to test it with:
Coordinator:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print('H');
delay(1000);
Serial.print('L');
delay(1000);
}
Router:
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
When I swap the code between the router and coordinator, it works exactly as it is suppose to, but not in the configuration above. Why won't the Router Xbee send Serial data to the Mega?