Go Down

Topic: Getting XBees Talking (Read 2150 times) previous topic - next topic


I have 2 series 2 XBees.  One coordinator is in API mode and one router is in AT mode.  When the radio is in AT mode automatically sending analog data  from pin 0 it works fine.  When I turn this off and try to have the Arduino send the data it gives me a bad start byte error.

I am using the example code and have only modified the XBee address for the coordinator radio.  Ultimately I need 3 radios. 1 coordinator in API mode 1 end radio in AT mode and 1 router in AT mode.
What am I missing here?


Code: [Select]
* Copyright (c) 2009 Andrew Rapp. All rights reserved.
* This file is part of XBee-Arduino.
* XBee-Arduino is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* XBee-Arduino is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with XBee-Arduino.  If not, see <http://www.gnu.org/licenses/>.

#include <XBee.h>
  long previousMillis = 0;        // will store last time LED was updated
  long interval = 1000;           // interval at which to blink (milliseconds)

This example is for Series 2 XBee
Sends a ZB TX request with the value of analogRead(pin5) and checks the status response for success

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

uint8_t payload[] = { 0, 0 };

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

int pin5 = 0;

int statusLed = 13;
int errorLed = 13;

void flashLed(int pin, int times, int wait) {
    for (int i = 0; i < times; i++) {
      digitalWrite(pin, HIGH);
      digitalWrite(pin, LOW);
      if (i + 1 < times) {

void setup() {
  pinMode(statusLed, OUTPUT);
  pinMode(errorLed, OUTPUT);

void loop()
   unsigned long currentMillis = millis();
   // break down 10-bit reading into two bytes and place in payload
    pin5 = analogRead(5);
  // pin5 = 7;
  // payload[0] = pin5 >> 8 & 0xff;
  // payload[1] = pin5 & 0xff;
    payload[0] = 1 >> 8 & 0xff;
   payload[1] = 1 & 0xff;
    // flash TX indicator
    flashLed(statusLed, 1, 100);
    // after sending a tx request, we expect a status response
    // wait up to half second for the status response
    if (xbee.readPacket(500)) {
        // got a response!

        // should be a znet tx status           
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {
       // get the delivery status, the fifth byte
           if (txStatus.getDeliveryStatus() == SUCCESS) {
            // success.  time to celebrate
              flashLed(statusLed, 5, 50);
           } else {
            // the remote XBee did not receive our packet. is it powered on?
              flashLed(errorLed, 3, 500);
    } else {
      // local XBee did not provide a timely TX Status Response -- should not happen
      flashLed(errorLed, 2, 50);


Here is what I get through CoolTerm with the coordinator hooked up to my computer.
The eighth set of numbers indicates if the if the message is good or not.
Any hints as to why I get a bad start Byte?

Bad  - with Arduino Diecimila telling XBee to send the data

7E 00 10 10 01 00 7D 33 A2 00 40 49 A8 25 FF FE 00 00 00 01 E5 8C
33 indicates bad start byte

Good   - with XBee sending data

7E 00 12 92 00 13 A2 00 40 7A 1F 83 E6 C1 01 01 00 00 01 02 12 9E
00 indicates good start byte


i think you have to dig into the xbee manual and look for the data format of api packets.

firstly you have two different data packets. the "bad" one is a TX request (frame type 0x10), the good one is a RX I/O data received packet (frame type 0x92).

An example for the packet you think is "bad":

TX request data format (0x10):
0x10 frame type TX request
0x33 according to the api format this is part of the 64-bit destination address and doesn't tell something about the condition of a request.

the same is for the second "good" data packet where the eigth field (0x00) is also part of the destination address.

so you compare absolut different packets.

i'm not sure what you are doing as you get analog sample data with the 0x92 = RX I/O data packet (look for 0x2 0x12 = decimal 528 which means you have ~ 619 mV at the ADC connected).

maybe you can elaborate a bit more (schematic, parts, connections etc.)


XBee blog: http://lookmanowire.blogspot.com/


Thanks Markbee,
As you probably noticed I'm new to XBees, but not Arduino.
I have the coordinator radio in API mode.  It is getting power from an Arduino Uno and has the TX & RX lines connected as well.
I am also using an LCD screen on the following pins  7, 8, 9, 10, 11, 12.  This is powered from a 9V wall wart

I have a router radio in AT mode connected and getting power from an Arduino Deciemilia connected to a computer.
This radio is on a breadboard and is connecting fine as I have an LED on the RSS pin.
Both Arduinos are using the XBee library and am now trying those examples. 
I have been using the the Book Wireless Sensor Networks and have gotten through the first 3 or 4 examples fine. 
Now I am trying to setup a weather station. 
What is the proper way to set these to radios up to talk properly when sending actual data from the Arduino?


hi pauly

i don't use the xbee library because i build and parse the xbee packets by myself so i can't say much about the library.

if you want to stay in api mode for the coordinator instead of just relaying data when in transparent(AT) mode you will have to have a deeper look into the api data packet structure (which is very well described in the book).

i don't know if the sensors are connected to the xbee or attached to the arduino, but when operating in api mode you could also get rid of the remote arduino and attach the sensors direct to the xbee (that's what i'm doing most of the time). unfortunately that's not possible for sensors with i²c or one wire etc.

for debugging you could start reading the serial data which arrives at the base station with the coordinator attached. start with something like

      int status = Serial.read();
      Serial.print(status, HEX);

to read the incomig data. you might identify the different packets from the remote xbee.

XBee blog: http://lookmanowire.blogspot.com/


Thanks Markbee. . 
I already have another radio in AT mode with a temperature sensor attached to it with no Arduino. 
This is working fine for now.   I'll give the rest of it another go this weekend.

Go Up