2

An XBee Series 2 is set to Router AT whose TX and RX pins are connected to an Arduino Nano's Rx and Tx pins respectively. The Arduino is connected to a Mac OSX via USB.

A second XBee Series 2 is connected to a Windows system via USB. It is set to Coordinator API mode.

Using the sketch below on the Arduino, a packet is sent from the Router AT XBee to the Coordinator API XBee, which is seen by XCTU as a Explicit RX frame. However the Arduino LED should blink once if it received a reply packet (should it?)

On another test, I wrote a script to send a frame for the Coordinator API XBee to send to the Router AT XBee. Once again the Arduino LED does not blink, and nothing is seen using Arduino's Serial Monitor.

Testing the Coordinator API XBee

Using the same script to send a packet from Coordinator API XBee to itself, the packet was received as well as a delivery confirmation packet. This shows that both the Coordinator API XBee and the script are working.

// Delivery confirmation 
received:  { type: 144,
  remote64: '0013a20040a74613',
  remote16: '0000',
  receiveOptions: 1,
  data: [ 116 ] }

// Received the packet sent to itself     
received:  { type: 139,
  id: 1,
  remote16: '0000',
  transmitRetryCount: 0,
  deliveryStatus: 0,
  discoveryStatus: 0 }

Testing the Arduino Sketch Code

Using the same Arduino sketch which continuously sends API frames to the Coordinator, I connected the Router AT XBee's RX pin to Arduino's RX pin, so the frames the Arduino are sending out are going back into its RX pin.

This causes the Arduino's LED to light up! So there is nothing wrong with the code.

Problem: Does this mean the Router AT XBee is not configured properly? I do not think its TX pin is damaged because XCTU can still read the settings off this XBee. Any ideas on how we can troubleshoot this?

Arduino Sketch (Connected to Router Xbee)

#include <XBee.h>

XBee xbee = XBee();
uint8_t payload[] = { 0, 0 };

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


void setup() {
    pinMode(13, OUTPUT);

    Serial.begin(9600);
    xbee.setSerial(Serial);
}



void loop() {
    xbee.send(zbTx);
    delay(1000);

    xbee.readPacket();
    if (xbee.getResponse().isAvailable()) {
        // Response received, blink LED once
        Serial.println('resposne!');
        digitalWrite(13, HIGH);
        delay(1000);
        digitalWrite(13, LOW);
        delay(1000);
    }
}
  • I'm a little confused about how you're sending the Router AT packet to the Coordinator in API mode. Sending out via AT is a Serial.print("sample");. Whereas the sketch you have above only shows us the Coordinator's outwards bound packet. Does that library handle AT mode as well? And what about addresses? You don't need to explicitly set the address outwards of the Coordinator (although it wouldn't hurt), the Coordinator should/can broadcast it's message. Can you confirm the ATDL of the Router is 0x0 or 0xFFFF if ATDH is 0x0. – Madivad Mar 19 '14 at 16:19
  • Just as another afterthought, do put the pertinent XBee settings in the post to confirm you've got it right. Copy them from the digi software. I just confirmed from code.google.com/p/xbee-arduino that the library doesn't work in AT mode. Also, it does require ATAP=2 so that's something else to check. – Madivad Mar 19 '14 at 17:57
  • @Madivad I'm so sorry, the arduino code is for Router AT Xbee, not Coordinator XBee. Made the change in the question – Nyxynyx Mar 19 '14 at 19:03
1

As I mentioned in my comments to your question, if you are using this library then it doesn't actually support AT mode. In fact, AT mode (otherwise known as Transparent Mode) is simply attached to the Serial port and accessed directly through the Serial object.

Example: put this into your Arduino attached to the AT Router.

#define LED 13

void setup() {
    pinMode(LED, OUTPUT);
    Serial.begin(9600);
    Serial.println("\nXBee AT communications test");
}

void loop() {
  static unsigned long previous = millis()/1000;
  if(previous != millis()/1000){
    previous = millis()/1000;
    char buffer[5];    
    sprintf(buffer,"%04i",previous);
    Serial.println(buffer);
   digitalWrite(LED, !digitalRead(LED)); 
  }
}

Then open the console on the XCTU software on the API Coordinator watch the packets.

look at packet 0102

You will see above the received packets from the router. Because the coordinator is in API mode, you see it like this. (In AT mode, you will see the raw packets.

Ichose numbers to send because they are easy to read in this form. Packet 0102 appears in the packets data as 30 31 30 32 0D 0A

In AT mode there is no packet confirmation, validations, status or anything. They are all handled "transparently".

As a side note, I've seen many references that both XBees need to be in the same mode. That is, in fact, incorrect. If we modify our source to include Serial.read you would see data the other way as well.

edit: I thought I would add communications between AT Router and API Coordinator. I have modified the code in the Router to receive a constructed packet from the Coordinator via the XCTU software.

#define LED 13

boolean serialComplete = false;
char bufferIn[64];
char bufferOut[5];
int count=0;

void setup() {
    pinMode(13, OUTPUT);
    Serial.begin(9600);
    Serial.println("\nXBee AT communications test");
}

void loop() {
  static unsigned long previous = millis()/1000;
  if(serialComplete) {
    Serial.println(bufferIn);
    serialComplete=false;
    count = 0;
    memset(bufferIn,0,sizeof(bufferIn));
    digitalWrite(LED,!digitalRead(LED)); 
  }
  if(previous != millis()/1000){
    previous = millis()/1000;
    sprintf(bufferOut,"%04u",(uint16_t)previous);
    Serial.println(bufferOut);
  }
}

void serialEvent() {
  while (Serial.available()) {
    char inChar = (char)Serial.read(); 
    if (inChar == '\n' || inChar == '\0') {
      bufferIn[count++]=0;
      serialComplete = true;
    } else {
      bufferIn[count++] = inChar;
    }
  }
}

Then in XCTU construct a packet for the Coordinator. I'm using version 6.1.0.

add API frame

and click "the create frame using form generator tool"

form generator tool

here is the packet being received by the router. I am only sending 9999 nul terminated.

result

Then once the pair are running, you can send the constructed packet from the XCTU software and it will be received by the router.

1

#include <XBee.h> uint8_t text[] = {'H', 'e', 'l', 'l', 'o',' ','T','H','I','S',' ','I','S',' ', 'A','R','D','U','I','N','O'}; XBee xbee = XBee(); XBeeAddress64 remoteAddress = XBeeAddress64(0x00000000, 0x0000FFFF);//64 address of remote xbee: ZBTxRequest zbTx = ZBTxRequest(remoteAddress, text, sizeof(text));// api 2 Tx request frame ZBRxResponse zbRx = ZBRxResponse();// reading remote xbee response: void setup() { Serial.begin(9600); xbee.setSerial(Serial); Serial.println("starting up yo!"); } void loop () {
xbee.readPacket();// This will read any data that is available: if (xbee.getResponse().isAvailable())//Now, to check if a packet was received: {
if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { xbee.send(zbTx);//sending data to remote xbee: } } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.