Arduino Uno + XBee S2 communicating with Arduino Mega + XBee S2

Hello all,

I've used XCTU to configure the two XBee's (The mega one as a router, and the uno one as the coordinator). They can communicate successfully in XCTU, however, when I try to use an arduino sketch, I don't see anything on serial communication.

On the uno: I'm using the pins RX and TX on the uno like this: DOUT -> TX & DIN -> RX.

On the mega: Same thing, using the TX and RX, DOUT -> TX & DIN -> RX

On the router side (mega), I am trying to send H & L, using this code:

#include <SoftwareSerial.h>

#define rxPin 6
#define txPin 7

//Xbee serial connection.
 SoftwareSerial XBSerial(rxPin, txPin);

void setup()
{
 Serial.begin(9600);
  //Start xBee Serial Bus
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 XBSerial.begin(9600);
}

void loop()
{
 XBSerial.write('H');
 delay(1000);
 XBSerial.write('L');
 delay(1000);
}

And on the receiver side (uno):

#include <SoftwareSerial.h>

#define rxPin 6
#define txPin 7

//Xbee serial connection.
 SoftwareSerial XBSerial(rxPin, txPin);

int incomingByte;      // a variable to read incoming serial data into

void setup() {
 // initialize serial communication:
 Serial.begin(9600)
 
  //Start xBee Serial Bus
 pinMode(rxPin, INPUT);
 pinMode(txPin, OUTPUT);
 XBSerial.begin(9600);
 
 void loop() {
 // see if there's incoming serial data:
     while (!XBSerial.available())
   // read the oldest byte in the serial buffer:
   incomingByte = Serial.read();
   
   Serial.println(incomingByte);
   // 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);
   }
}

Any help would be great!

are the xbees set to the same baud rate as your sketch?

On the router side (mega), I am trying to send H & L, using this code:

But, you are using SoftwareSerial on the Mega that has 4 hardware serial ports. You are using it on pins that do not support pin change interrupts, so SoftwareSerial won't work. And, you are using it on pins that the XBee, according to your description, is not attached to.

So, color me surprised that the XBee doesn't send/receive anything. NOT.