Xbee Digimesh 2.4 with arduino

I want to connect some arduinos mega with Xbee DigiMesh 2.4 in a mesh network.

At this moment i try to connect 2 of them, one sender and one receiver, thats the code that i have on them:



// create the XBee object
XBee xbee = XBee();

uint8_t payload[] = { 0, 0 };

// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0, 0xFFFF);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

int pin5 = 0;

void setup() {

void loop() {
payload[0] = 0x34;
payload[1] = 0x76;





XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
// create reusable response objects for responses we expect to handle
ZBRxResponse rx = ZBRxResponse();
ModemStatusResponse msr = ModemStatusResponse();

void setup() {
// start serial

// continuously reads packets, looking for ZB Receive or Modem Status
void loop() {
if (xbee.getResponse().isAvailable()) {
// got something
Serial.println(“got something”);
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) {
// got a zb rx packet
Serial.println(“got rx packet”);
// now fill our zb rx class
// I check both bytes (or)
if (rx.getData(0) == 0x34 || rx.getData(0) == 0x76 ) {
digitalWrite(8, HIGH);

With this code i connect Serial1 to the Xbee. And i have on the hardware selected API(1) mode.

I dont know the reason why i can`t comunicate, if i need to use other libraries or what


1 Like

May I suggest you take a step back and just try sending data via a COM port that the radio is connected to in transparent mode and get that working first. The way you are going right now, in order to properly trouble shoot it, you need to be able to listen to the API frames that are being sent to the radio and see if they are valid frames before you can determine where the issue is.

1 Like

Hi mvut and thanks for your answer, at this moment i have no problem to connect in broadcast mode but i need to connect in unicast mode and here is the problem.
In broadcast mode i send one frame and the other Xbee receive the packet that i sent, but when i change to unicast putting the DH and DL in my code, it stops run and i dont receive nothing in my second Xbee

What are you putting in for the DL and DH addresses?

I put the SL and SH of the receiver on that lane:

XBeeAddress64 addr64 = XBeeAddress64(0x13a200, 0x41b4cb1c);

Your cutting off the first byte in the 64 bit address. The SL begins with 0x0013A200. Make that change and I think you will have better luck.

Thank you mvut,

I tried to put on de SL 0x0013A200 but it don`t work, it do the same when i put 0x0013A200 than when i put 0x13A200

Can you provide the full API frame you are providing the radio and any status frame you are getting back?

Sorry mvut i don`t know how to take the full frame, that i sent or i get back, for my code that frame is transparent, if you know some comands that I can put to to see the frame, please tell me and I will put it on my code to see that frame.

i have been trying the same and i am stuck, i think you should try this library

I’m trying to get this working right now using the same library. If I output the zbTx to a serial console I notice that the DL comes out as 7D 33 A2 00, where in actual fact I have entered 0x0013A200 in my sketch. Therefore the transmit is just not getting to the destination XBee. I can’t understand why this would be. I’m just running the example sketch from the library. Perhaps this might also be the problem you’re experiencing.

Could you write the full frame u send?
So, someone here maybe can help us to solve the problem.

The simplest way I can think of is to remove the xbee and run jumper wires to an interface board. Then use XCTU to view the data.

here is an example of a full frame that that is being sent. note that this frame is being assembled by the library, I haven’t manually sent this.

7E 00 10 10 01 00 7D 33 A2 00 40 E8 43 BD FF FE 00 00 01 35 DE 31 35 33 0D 0A

That is an invalid packet. It is also using API mode 2 and not 1.

Looks like you may also be dropping off the leading 00’s from our 64 bit address in your API frame. That will keep it from being valid and for the radio to send it.

Hi Guys,
I’m going through a similar problem trying to get the Arduino to talk with the xBee S3B Digimesh in API mode.
This is the code I use to in the Arduino “Sender” for sending data. In this particular case I’m trying to send a “Hi” but I think I’m getting the wrong API message in the output of the Arduino “7E01010107D33A2040B2FA4AFFFE00486955”
I use another Arduino “Receiver” to check what is coming in the serial output of the Arduino Sender. In the real application this output would be connected to the xBee module.
I think the API message that goes out of the Arduino sender should look like “7E 00 10 10 01 00 7D 33 A2 00 40 B2 FA 4A FF FE 00 00 48 69 55”

Do you see anything wrong in mi code?

I’m using Andrew’s library “andrewrapp/xbee-arduino”

// Arduino Sender//////////////////////////////////////////////////////

// Create an XBee object at the top of your sketch
XBee xbee = XBee();

int xBeeRX = 6; // Connect Arduino pin 8 to Xbee TX pin
int xBeeTX = 7; // Connect Arduino pin 9 to Xbee RX pin
SoftwareSerial xBeeSerial(xBeeRX, xBeeTX);// Define SoftwareSerial xBeeSerial RX/TX pins

// Create an array for holding the data you want to send.
uint8_t payload[] = {‘H’,‘i’}; //{48,69} in HEX

// Specify the address of the remote XBee (this is the SH + SL)
XBeeAddress64 addr64 = XBeeAddress64(0x0013A200, 0x40B2FA4A);//0013A20040B2FA4A

// Create a TX Request
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));

void setup() {
xBeeSerial.begin(9600); // Start the serial port
xbee.setSerial(xBeeSerial); // Tell XBee to use SoftwareSerial xBeeSerial

void loop() {
xbee.send(zbTx);// Send your request

// Arduino Reciver//////////////////////////////////////////////////////
//This Arduino is connected to the xBeeSerial of Arduino Sender. Just for debugging propose. #include

int xBeeRX = 6; // Connect Arduino pin 8 to Xbee TX pin
int xBeeTX = 7; // Connect Arduino pin 9 to Xbee RX pin
SoftwareSerial xBeeSerial(xBeeRX, xBeeTX);// Define SoftwareSerial xBeeSerial RX/TX pins

void setup() {
// initialize both serial ports:

void loop() {
// read from port xBeeSerial, send to port Serial:
if (xBeeSerial.available()) {
int inByte = xBeeSerial.read();
Serial.print(inByte, HEX);

Look at XBeeAddress64(0x0013A200,0x40B2FA4A);//0013A20040B2FA4A

I believe that should be:

Hi mvut,
Thanks for getting back to me.
The information after the “//” doesn’t matter. It’s just comment of the code. It’s not actual part of the code.
Do you have any other suggestions?

Folks, Most of the examples for the Arduino and other processors have the radios in API mode 2. This then escapes specific characters including 00’s and 7E’s.