# Decoding XBee Series 1 API Packet

I'm having issues trying to decode a XBee API packet. I start decoding it, but I'm not sure what my actual analog data should be. Several of them look like:

7E 00 12 83 56 78 43 00 05 02 00 00 00 03 FF 03 FF 00 00 00 00 60
7E 00 12 83 56 78 43 00 05 02 00 03 E8 03 FF 00 2A 00 00 01 C8 84
7E 00 12 83 56 78 43 00 05 02 00 03 FF 02 DE 00 0D 00 00 03 FF 73
7E 00 12 83 56 78 42 00 05 02 00 03 FF 00 00 00 00 03 DB 03 FF 83


So far I have:

7E - start
00 - length byte 1
12 - length byte 2
83 - API identifier
56 - source address byte 1
78 - source address byte 2
43 - RSSI value bytes
00 - option byte
05 - sample quantity byte
02 00 - channel indicator 0000 0010 0000 0000  (A0 is active) (IO header) (I'm not sure if this is right)
last byte is chechsum


I'm using the XBee series 1 using XB24 firmware. I have a Lilypad temperature sensor based on the MCP9700.

The documentation for the XBee module is: http://ftp1.digi.com/support/documentation/90000982_G.pdf

Every time I try to get the ADC data I get a huge number like 51228675.

The doc also says if any of the DIO lines are the first two bytes are the DIO sample. Why do I get "03 FF" or "E8 03" and sometimes "00 00" if I don't have any of the DIO lines active?

Schematic: Lilypad Temperature Sensor (pin S) --> Xbee (pin AD0)

Any help is greatly appreciated trying to find the sensor output.

## 3 Answers

You are doing something very wrong if you get a large number like 51228675 - the datasheet you linked to says that the ADC output is a 10 bit number right-justified inside of two byte (16 bits). That means that the maximum value should be 0000 0011 1111 1111b which is equivalent to 1,023 decimal. So if you get something that large you're including more bits than you should.

Which bytes do you think are the ADC data in your examples above?

• I do have a second XBee and its connected to a Arduino UNO using this shield sparkfun.com/products/9976. The code just sees if there is serial data available and if there is it prints it in hex. I don't have any code that gave me 51228675, I got that after converting what I though was the data. For example using the last packet, assuming the "03" and "FF" are DIO info and ignored, my data would be: '00 00 00 00 03 DB 03 FF' Which is 64685055 in decimal, but it cant be greater than 1023 so I'm lost where my analog data is. Thanks for the help! – user1247595 Apr 3 '12 at 20:48
• @user1247595 - You've pasted a 64-bit number in hex, AngryEE has given you your number in binary. You're looking at 4 separate values, one of which is (hex) 0x03DB = (binary) 0b0000 0011 1101 1011 = (decimal) 987. – Kevin Vermeer May 3 '12 at 21:29

The format for that frame is on page 13 of the XBee doc. The DIO lines are never active, therefore the DIO samples are skipped and the next two bytes are immediately the analog samples. The A0 readings are:

• 00 00 = 0
• 03 E8 = 0x3E8 = 1000
• 03 FF = 0x3FF = 1023
• 03 FF = 0x3FF = 1023

You should never get anything higher than 1023 for the ADC reading, because it's only a 10-bit number.

How are you receiving the frames? I presume you have a second XBee that's connected to something and it's spitting out the frame data. Can you post the code that's giving you 51228675?

• I do have a second XBee and its connected to a Arduino UNO using this shield sparkfun.com/products/9976. The code just sees if there is serial data avaiable and if there is it prints it in hex. I dont have any code that gave me 51228675, I got that after converting what I though was the data. For example using the last packet, assuming the "03" and "FF" are DIO info and ignored, my data would be: 00 00 00 00 03 DB 03 FF – user1247595 Apr 3 '12 at 20:35
• Which is 64685055 in decimal, but it cant be greater than 1023 so I'm lost where my analog data is. Thanks for the help! – user1247595 Apr 3 '12 at 20:54

Maybe using a library is the best solution. For Arduino there's

http://code.google.com/p/xbee-arduino/

and for Java:

http://code.google.com/p/xbee-api/

I've used both and they're good. Only a catch though, if you intend to use the arduino library, do not forget to set API mode=2 (AT command AP, value 2), otherwise you'll wonder why nothing is being sent. (AT AP=2 is the API dialect where certain characters are escaped. The library uses that dialect. The Java library takes care of initializing things properly, but the Arduino library leaves that to the user)

• Hey! I tried using the arduino library and unfortunately I get no output. I used to Series1_IoSamples sketch and it uploaded fine, and I have ATAP=2 for both XBee modules. I set it through a terminal. Does the Enable API and "Use escape characters" have to be checked in X-CTU ? Every time I check them, the setting doesn't seem to stay, even after I write the settings. And one more thing, do you know what pins should be set for ssRX and ssTX when using this shield sparkfun.com/products/9976 I appreciate all the help !! – user1247595 Apr 3 '12 at 20:48
• In my case ATAP=2 had to be sent from the Arduino every time at the start of the conversation. From the Sparkfun page seems like ssRx/Tx are on digital pins 2 and 3. Can you get the xbee connected to a computer so you can debug using the java api? In my experience, juggling with ports, especially with hardware and software serial at the same time, is prone to timing errors. – Erion Apr 5 '12 at 17:13