How to Program My arduino to receive info via Xbee PRO 24 BZ

Hallo all,

I am using 2 x Xbee Pro S2B modules. When the setup is complete i can chat with one and the other. But if i remove one and insert it in a Arduino Mega Board with a Xbee shield to display what the other Xbee is sending it does not. What can be the problem?

The one Xbee(Router) is connected to a Xbee adapter connected to a laptop via a UART cable, the other Xbee(Co ordinator) is connected to a shield connected on to a Arduino board connected to the same laptop via UART cable.

I have tried all examples and have downloaded libraries. Nothing seems to work.

The program currently on the Arduino board is:

#include <SoftwareSerial.h>
// XBee’s DOUT (TX) is connected to pin 2 (Arduino’s Software RX)
// XBee’s DIN (RX) is connected to pin 3 (Arduino’s Software TX)
SoftwareSerial XBee(2,3); // RX, TX

void setup()
{
// Set up both ports at 9600 baud. This value is most important
// for the XBee. Make sure the baud rate matches the config
// setting of your XBee.
XBee.begin(9600);
Serial.begin(9600);
}

void loop()
{
if (Serial.available())
{ // If data comes in from serial monitor, send it out to XBee
XBee.write(Serial.read());
}
if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
Serial.write(XBee.read());
}
}

I have posted this problem on many blogs and i have received lots of views but no one could answer me! Maybe one of you can?

Hope for a speedy replay. Thank you.

Best regards
Jaco