XBee ZNet 2.5 Wireless Accelerometer

I managed to put together a wireless accelerometer the other night using my two new XBees, an Arduino XBee shield, an XBee Explorer USB, an ADXL330, and some Python. I struggled a bit with some of it, so here's what I learned:

First, a parts list.
I'm not sure exactly what the specs are on the XBee that comes with the Arduino shield. But, it is definitely a series 2.5.

The first thing to do is to configure and upgrade the firmware on your XBees. To do that, you'll need X-CTU (for the firmware upgrade at least, but it's also nice for configuration) which, unfortunately, is only available for Windows. But, it works fine from VMware. First up, the XBee we'll hook up to the computer to read incoming data from the accelerometer:
  • Plug one of the XBees into the Explorer (it's also possible to do this from the Arduino shield by shifting the two XBee/USB jumpers to USB and removing the MCU) and plug it into your USB port.
  • Crank up X-CTU, select the appropriate USB communications port (com port), click "Modem Configuration" and then "Read." This will determine what XBee is connected and what firmware is on the device.
  • Select "Always update firmware."
  • Click "Download new versions..."
  • Select the latest version of ZNet 2.5 Router/End Device API. The API version is necessary in order to read the incoming data on the computer. Only API firmware will write incoming sensor data to the device's UART so it can be read over USB/serial.
  • Click "Write." You may get an error after the writing is complete. That's normal. It's because you've changed the way the XBee communicates over it's UART. Go back to the "PC Settings" tab, select "Enable API" and then click "Read" on the "Modem Configuration" tab again.
  • Under "Networking," change NI (Node Identifer) to something like "ARDUINO". I named mine Arduino because I used the Arduino and XBee shield to provide a USB connection to the computer.
  • Click "Write" and hook it up to your computer. This is the XBee that your accelerometer will be sending data to. We'll hack up some Python to read that data later.
Next up is the XBee we'll hook to the accelerometer:
  • Follow the same steps as before until you reach the firmware selection.
  • Select the latest version of ZNet 2.5 Router/End Device AT.
  • Under "Networking," change NI (Node Identifer) to something like "ACCELEROMETER".
  • Under "I/O Settings," change D0-D2 to 2-ADC. These pins will be used to read from the accelerometer.
  • Again under "I/O Settings," change IR (sample rate) to 1F4 (hex for 500 milliseconds).
  • Click "Write."
  • Go to the "Termainal" tab. To enter command mode on the XBee, send it "+++" (do not press enter). It will respond with "OK". Next type "ATDNARDUINO" (or whatever you called your other XBee). That will set the destination node to your other XBee. It should respond with "OK". Next, send it "ATWR". That will write the settings to memory so that they aren't lost when the XBee is powered off.
    +++OK
    ATDNARDUINO
    OK
    ATWR
    OK
  • Finally, hook up your XBee and ADXL330. You can power both with 3.3V (3V works too). Unfortunately, the XBee 2.5 series ADCs only accept voltages in the range of 0-1.2V. To get better results, you'll need to add voltage dividers on the X, Y, and Z axes. I don't have those in the schematic. If you use 3V, it works well enough to detect motion. For finer mesurements, you'll need the dividers.


Now, you should be able to test that everything is working. Connect to the Arduino XBee with the X-CTU terminal. Assuming your accelerometer XBee is powered on, you should see lots of data flying by. The data is transmitted in API packets over the XBee's UART, to the FTDI chip, to your computer's USB-serial device. The API packet specification is in the XBee 2.5 manual. Here's some Python that does part of the decoding.
import xbee
Just kidding. Although there is a XBee Python library, it doesn't currently support series 2.5 modules.
import serial  # pySerial
import struct
import sys

THRESHOLD = 5

tty = sys.argv[1]

s = serial.Serial(tty, 9600)
movement = None
while True:
if s.read() == chr(0x7e): # Packet start indicator.
length, api_id = struct.unpack('>Hc', s.read(3))
if api_id == chr(0x92): # IO packet type.
# Lots of bytes we don't care about followed by 3 shorts.
z, y, x = struct.unpack('>xxxxxxxxxxxxxxxHHH',
s.read(length - 1))
print z, y, x
if (movement is not None and
abs(z + y + x - movement) > THRESHOLD):
print 'You moved!'
movement = z + y + x
If you read the spec for API packets, you'll notice I'm glossing over a lot of details. The analog IO bytes are always at the end of the packet. Since we enabled only 3 ADCs, we can just grab the last three shorts.

Finally, here is a picture of my breadboarded version (with voltage dividers) of this. It works great. I'm currently working on a PCB so that the whole thing is compact enough to be wearable.


Some further notes:
  • The chip antenna versions are pretty directional. There's a lot of interference in my apartment (a long story for another post) and I don't get very good range. I plan to buy some more 60mW XBee Pros with wire antennas in the future. I'd recommend getting the high power ones unless you're really concerned about battery life. I wish I had.
  • Digi's tech support is really pretty great. I had some trouble flashing one of my XBee's and they got in contact with me on the same business day.
  • Unfortunately, the XBee only has 4 ADCs. If it had one more, you could add a pitch and roll gyro to the mix without an additional MCU. Oh, well.
  • The XBee pin spacing doesn't match standard breadboards. But, the XBee Explorer USB doubles as an XBee breakout board for breadboard designs (as seen in the photo above) if you solder on some additional headers.

23 comments:

  1. Here's an xbee api for Java that supports both series 1 and series 2 xbees

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

    ReplyDelete
  2. im getting problem on connect with api enabled, the modem query said cant detect modem type and firmware version is there any way to fix this?

    ReplyDelete
  3. Make sure you've flashed the API version of the firmware to the XBee. If you haven't, API mode will not work to communicate with it. Try unchecking "Enable API" in X-CTU and then clicking "Read" under the "Modem Configuration" tab. If you're still having problems, the Digi support forums are quite useful.

    ReplyDelete
  4. Sorry for the late comment on old post. I got to the part where I am supposed to "Select the latest version of ZNet 2.5 Router/End Device API." My problem is that when I select download new version, I don't get anyting to select. I am using the web instead of file for my update source? What am I missing?

    ReplyDelete
  5. Think I figured it out. The Xbee that came with the Arduino shield works just the way you suggest. The "other" one I purchased seems to be older, and only has 3 functions available, none of them being ZNet 2.5 Router/End Device API.

    ReplyDelete
  6. Hi everyone,

    Please could someone explain the difference between series 1 and series 2 versions of XBee? I am not sure what ZNet 2.5 means. Is it better than series 1? Looking at prices for the development boards, there appears to be no difference..

    Thanks

    ReplyDelete
  7. Hello Damon. I saw a post of yours in the Digi support forum about replacing the chip antenna of your XBee module.

    I wanted to ask you if you tried and/or could do it, beacause I'm thinking seriously of doing that.

    Thank you very much.

    PS: Sorry about any grammatical errors, I'm not a native english speaker

    ReplyDelete
  8. @Miguelio
    I have not actually tried to replace the antenna yet. I'm not sure I will either. I could use an excuse to buy more Xbees!

    ReplyDelete
  9. Hi, I am trying to communicate between two Xbee 2.5. I did all the updates etc.. But I am not using an Arduino board, instead I am directly true UART pins, communicating a micro (89C51) to a UFL Xbee module with a 2.4GHz Wifi Antenna. But so far I wasn't successful in receiving the data on the other side.

    I am using a UFL module with a wire antenna module, they both use 2.4GHz antennas so I guess that does not make a difference? Or do both Xbee modules that need to communicate with each other need be the same, as in Chip antenna with chip antenna only?

    another problem is, I am using the Explorer board, so far so good, I love it, but where do you actually see the numbers fly as you have stated in your article? Does the X-CTU show the results that are being sent from the Coordinator module, such as "Temp 24'C" etc .. ?

    I found a lot of help regards Xbee communication in the digi forums, but I didn't find a single post regards Xbees being used with micros only, without using any Arduino or Zbee shields etc..

    Any help will be greatly appreciated.

    ReplyDelete
  10. I want to know if somebody can help me on the following
    I am trying to communicate between two Xbee 2.5. I did all the updates etc, the first step is to bring the end device id , I am directly true UART pins, communicating a micro (89C52) to a Xbee module with a 2.4GHz Antenna,I’m trying to send the ATND command using assembly language from my board witch contents( atmel 89c52 with xbee coordinator ,LCD to see the transmit and received command) , I am having troubles getting the ATND response ,I received only tow byte ,but the LED connecting to the pin 6 is glow. Also I changed to the API mode for the coordinator and the end devices, to send the ND command (0x7E 0x00 0x04 0x08 0x01 0x4E 0x44 0x64 ),I get the same problem ,the response is a labels rubbish , I didn't find anything regards Xbees being used with microcontroller only, without using any Arduino or Zbee shields etc..anyone can help pliz.

    ReplyDelete
  11. I want to know if somebody can help me on the following
    I am trying to communicate between two Xbee 2.5. I did all the updates etc, the first step is to bring the end device id , I am directly true UART pins, communicating a micro (89C52) to a Xbee module with a 2.4GHz Antenna,I’m trying to send the ATND command using assembly language from my board witch contents( atmel 89c52 with xbee coordinator ,LCD to see the transmit and received command) , I am having troubles getting the ATND response ,I received only tow byte ,but the LED connecting to the pin 6 is glow. Also I changed to the API mode for the coordinator and the end devices, to send the ND command (0x7E 0x00 0x04 0x08 0x01 0x4E 0x44 0x64 ),I get the same problem ,the response is a labels rubbish , I didn't find anything regards Xbees being used with microcontroller only, without using any Arduino or Zbee shields etc..anyone can help pliz.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. Do you need to hit enter after adtnarduino?

    ReplyDelete
  14. hi,
    in znet 2.5 router/end device at(and api) "Node Identifier" is under adressing in my x-ctu. i changed the value and did anything as described but after executing the atdn command i receive "error".
    i use 2 xb24-b modules both with firmware 1247. one of them with "at" and the other with "api" function set.

    thanks in advance

    ReplyDelete
  15. I have the same issue as de_dirk said.
    I receive error after executing the atdn command i receive "error". I did whatever is written in the article. Instead, I tried with atdl command and it works. But, still trying to figure out if that is right.
    Does any1 know??
    Also, what needs to be done for voltage level shifting from 3.3v to 1.2v for ADCs.
    Please let me know asap.
    Thanks in advance.

    ReplyDelete
  16. Hi Damon, I noticed that you connected ground to the 1st GND pin on the USB explorer. Would there be a difference if you connect it to the 11th GND pin instead?
    Cheers

    ReplyDelete
  17. I'm not sure, but in general ground is ground. Or at least you want it to be.

    ReplyDelete
  18. I have a similar setup using a Gyro breakout board from SFE and instead of the usb explorer, I use the XBee breakout board from SFE. I have 2 analog inputs going to DI0 & DI1. I find that the XBees become unstable after a while and can't be read by X-CTU and the sampling rate is also inconsistent. Do you have that problem?

    ReplyDelete
  19. I'm not sure, sorry. I haven't played with this in a long time.

    ReplyDelete
  20. I'm sorry, I'm new to Arduinos and Xbees, so this might be a stupid question. Why do we need the Arduino Xbee shield here? Does this connect the Xbee to the computer? Because the Xbee connected to the accelerometer is simply on the Xbee explorer USB from what I can tell from your diagram and photo. How is the other XBee connected to the PC, and if this is where you need the shield, why is another XBee explorer USB not enough?

    ReplyDelete
  21. In this example, the shield is being used in the same way as the XBee explorer.

    ReplyDelete
  22. Okay, so I could just use a second explorer?

    ReplyDelete
  23. I have not actually tried to replace the antenna yet. I'm not sure I will either. I could use an excuse to buy more Xbees!

    portable wireless router

    ReplyDelete