difficulty communicating between mega/xbee and explorer/xbee

I've got the following: - 1 arduino mega - 2 xbee series 1 - 1 seeed studio xbee shield - 1 sparkfun xbee explorer

I have one xbee plugged into the shield, which is plugged into the mega. The other xbee is plugged into the explorer. Both the explorer and the arduino are connected to USB ports on my laptop.

I've used XCTU to configure the Xbees per the instructions here: https://learn.sparkfun.com/tutorials/exploring-xbees-and-xctu/configuring-networks

With the goal of doing the communication test listed here: https://learn.sparkfun.com/tutorials/xbee-shield-hookup-guide/example-communication-test

When I set things up like this, I don't see anything in the XCTU console, nor in the arduino serial monitor. When I type into the XCTU console log, I see the RSSI led on the xbee shield light up, and I see the RX led on the shield light up (?). I never see the TX led on the explorer light up.

What am I doing wrong?



OK, attempt #2 here, with updated debugging.

I got another XBee explorer. When I plug both configured XBees into an explorer, then plug those in, I can use XCTU to see that traffic is flowing between them just fine. So I think that rules out mis-configured XBees.

I also got a arduino wireless proto shield. Plugged that into the mega, and one of the xbees into that,and again, I can't get messages sent in either direction.

I did notice that some of the time when I plug the mega in, I get some garbage messages on the XBee which is attached to the explorer. A couple of times, it looked like text printed to Serial on the mega has shown up on the remote XBee. That confuses me.

I figure that I maybe had the shield on the mega in a way where it was hijacking the serial connection, leading to my problems. The other wireless shield that I got has some jumpers to map the XBee RX and TX to different pins, so I tried mapping these to 10, 11, which correspond to 10,10 PWM pins on the mega (AFAICT).

Still no dice.

I think I'm misunderstanding something pretty basic about serial communication, softwareserial, the mega, and xbee, but I can't figure out what.

Anyways, what I'd like to get to is a state like this:

  1. XBee on explorer, connected to via XCTU
  2. XBee on shield on mega, connected to via arduino console

... then just see messages entered into XCTU on the arduino console, and vice versa.


I know when I was messing with Xbee WiFi modules, a Leonardo and an Xbee shield my problems were that the shield mapped the uart pins to 0 and 1, which is what the USB interface uses. This meant that whilst connected to the USB, the arduino couldn't communicate with the Xbee on those pins. I just used some wires to connect pins 0 and 1 to pins 8 and 9 then changed the software serial section in the code.

Another problem I had was that switch on the Shield being switched wrong. I know its simple but it has cost me a little time before

I dont know if this will help but this is my post I made about hooking up my Xbee Wi-Fi to a server.


aprykea: Thanks! This did help me make a bit of progress. If I plug the wireless proto shield into the mega and set the serial switch to 'USB", I can send from the mega/xbee -> explorer/xbee. However, I can't send in the opposite direction. My guess is that sending works because that tells the mega to setup serial comms on USB, therefore freeing 0/1 for the Xbee to use.

So I think what I'm not understanding is how the serial ports are mapped on the mega when I have the console open via USB and I'm using a shield.

What I think I want (but I'm new to this, so might be misunderstanding) is for the Xbee that's on the shield to have its TX/RX mapped to something other than 0 and 1 on the mega (which is where the wireless proto shield puts them), as when it's plugged in there, the mega doesn't know whether it should be using 0/1 or USB for serial comms.

I tried your trick of wiring 0/1 to 8/9, but that doesn't seem to work.


After a quick read the reason my wiring trick didn't work was because I was using the Leonardo, and you are using the Mega.

After a quick read on here: http://www.arduino.cc/en/Reference/SoftwareSerialExample

it says :

Note: Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

So where I got away with connecting pins 0, 1 to pins 8 and 9, you need to use any of the above pins eg, 10, 11

You'll also need to flick the switch back to micro and not USB.

If you use the code from my site link (the baud rates are right for the Xbee) just change the code line: SoftwareSerial Xbee(8, 9); // RX, TX

to SoftwareSerial Xbee(10, 11); // RX, TX

Hope that works :)

Thanks, but it still doesn’t work. I’ve got the following code:

#include <SoftwareSerial.h>

SoftwareSerial XBee(10,11); // RX, TX
//SoftwareSerial XBee(8,9);
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.

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

if (XBee.available())
{ // If data comes in from XBee, send it out to serial monitor
//Serial.println(“xbee available”);

That’s on the mega, which has the proto shield plugged in. I’ve got jumpers between RX/0 and D10 and TX/1 and D11, and the mega is plugged into my laptop over USB.

I’ve also got the paired xbee on a sparkfun explorer, which is also plugged into the laptop over USB.

With the shield switch set to “micro”, I get nothing in either direction. With the switch set to “USB”, I can send from the mega to the xbee on the explorer. I can’t seem to get anything sent from the xbee/explorer to show up on the mega.

Personally I don’t think that code entirely makes sense for what you are trying to do. Forgive me if I insult your intelligence but with the void setup() function, that only runs once when the code is first run. So if you are trying to repeatedly send “yo” or “ho” it wont work. Also that delay(1000); will completely invalidate that void loop() function because you’re sending data at much higher speed than that, so if any serial lines are available there’s a 99% you’re going to miss it.

I would try this as I know it works:

#include <SoftwareSerial.h>
SoftwareSerial XBee(10,11); // RX, TX
//SoftwareSerial XBee(8,9);
void setup() // runs once
Serial.begin(9600); // initialises USB
while (!Serial) {
; // wait for serial port to connect
// probably not needed but no harm in having it there
XBee.begin(9600); // initialises XBee UART

void loop() // run over and over
{ // if XBee available, send to USB
if (XBee.available())
// if USB available, send to XBee
if (Serial.available())

What this allows you to is write something in the serial monitor and send it to the Xbee, which will then send it to the other Xbee. That’ll prove all connections work and you can go from there.

Alternatively in the void loop()
you could just write:

which should repeatedly send hello to your other XBee