The XBee RF radio is certainly not new technology, but it remains a tried-and-true means of communicating with microcontrollers in DIY electronic projects. For those of you unfamiliar with the XBee, it is an RF radio module that can be attached to a circuit via a breakout-board and used to communicate wirelessly with that circuit, or to send sensor data to another XBee (presumably attached to a computer.) Working with XBees is not all crackers and cheese, however. Those familiar with the XBee know it is a device of both promise and sorrow, a ‘veil of tears’ as Allan Schindler would say. Common issues include platform programming differences, firmware version confusion, hardware compatibility questions, and basic functionality of the device. There is a lot of information out there about XBee radios, but finding this information and putting it into practice can “bee” difficult. (Wow. You would hope that sort of thing would be illegal by now.) All I hope to do with this post is save you some time by linking to the sites/how-tos/books that helped me get my “bricked” XBee into action. (And maybe explain some things about XBee, Zigbee, and Microcontrollers controlling along the way.)
Before We Get Started
If you are new to XBee and wireless communications in DIY projects, I highly recommend getting Building Wireless Sensor Networks by Rob Faludi. You can also get somewhat of an idea of what’s out there and what you can do with it from Sparkfun’s “XBee buying guide” but it is no substitute of the in-depth knowledge of Rob’s book.
A (very) Short Introduction to the XBee
Here’s the trick, the XBee is stupid; it has no logical functionality. All it does is act as a gateway transferring information from one place to another. The beautiful thing is that it does it wirelessly. Here’s a quick rundown on what has to happen between the time you pull the XBee from its protective foam block and when it tells you how far your cat is from the fish bowl.
You will need the right hardware to program your XBee and get it working within your project. Picking the right XBee module, breakout board, microcontroller, and other components is extremely important. If you pick the wrong board, for example, you may have to hack it to be able to write new firmware to it. See below for a basic hardware requirement list. Be sure to check your project requirements though!
Flashing/Firmware Writing Phase
- The XBee may or may not have to be flashed (firmware written to it) when you first get it. Series 2 need flashing. AFAIK, the other gens just need programming. To do the flashing/programming you need a USB breakout board; some way to communicate with the XBee.
- The Breakout board has to be wired correctly or the firmware cannot be written. For example, you have to hack the Arduino Shield if you want to flash the firmware using it. I’ve had no problems with the Sparkfun Explorer linked to below. You can also make your own provided you know what you’re doing.
- The XBee can only be flashed using X-CTU, a Digi software program designed to write firmware and functions sets to the XBee. X-CTU is Windows only, so writing firmware on a Linux or Mac machine is a no-go*. (*See below.)
- The basic personality of the XBee must be set to Coordinator, Router, or Sensor. Each functions differently within your Zigbee network. You have to know how many XBees you need for a project and what function set you need for each one: these are not one-trick ponies.
- There is a bunch of individual XBee module data that has to be recorded and programmed at the beginning of the process so the modules can communicate with each other. (for example you will need to program the serials of each of the XBees in this phase so they know who to communicate with and how.)
- The XBees have to be connected to a breakout board to make their pins work with the standard bread board spacing. Typically this means soldering headers (0.1 spaced) onto the breakout board so you can plug it into a project board or custom circuit board. **You should be aware that the pinout of the XBee may or may not match that of your breakout board. The Sparkfun board I use, for example, is different, so I keep the data sheet for the XBee close so I can be sure what I’m wiring up is correct.**
- Once connected to the circuit, the XBee will have to be powered and most likely connected to a microcontroller that will do the brain work of the project.
- Additional components must be connected to the XBee/MC as required by the project.
Getting Started: Pick a Project
The first thing you should do is check out some websites and/or read a book and pick a project that you want to work on. It may seem counterintuitive to have a project in mind before even having your hardware setup (or knowing how to use it), but it makes sense if you think about it. Every good project site or book project will tell you what firmware and instruction set you should be using with your XBees, what microcontroller you will need, and what additional components your project requires. Here are a few resources for project ideas/tutorials.
- Building Wireless Sensor Networks is the bible of zigbee and XBee if there is one. There are projects that you complete while you learn.
- Building Wireless Sensor Networks: http://shop.oreilly.com/product/9780596807740.do
- Also of interest is Robert Faludi’s personal site where you can find lots of example code and projects.
- Robert Faludi’s personal site: http://www.faludi.com/
- Chapters 6 and 7 in Making Things Talk have projects for communicating with XBees and provide instructions for programming them. The 2nd edition is now out.
My 2 cents on project requirements
For hardware you will need at least:
- 1-2 XBee radios depending on your project. As in life and love, more fun is always had with 2. (or more…)
- 1-2 breakout boards to plug the XBee into. I recommend the Sparkfun XBee Explorer USB. Why? Because I know it works and it’s waaaaaay cheaper than the digi board (less than half the cost) and the Arduino shield.
- 1-2 miniUSB to USB cables to plug the breakout boards into your computer for programming
- 1-2 microcontrollers (Arduino, etc.) to run the project
- a computer to program the XBees and the microcontrollers (a PC with windows is easiest)
- Sensors and components of your choice as required by your project (photoresistors, pots, accelerometers, etc.)
For software you will need at least:
- an operating system (obviously?): Windows, Linux*, or Mac OS**
- * if Linux you will need Wine (a windows ‘emulation’ layer)
- ** if Mac OS, Parallels or another emulation program (I’ve never gotten this to work)
- X-CTU: the Digi program used to update firmware and function sets on the XBee
- Arduino or other microcontroller programming language/program
- a serial shell emulator (required for serial communication with the XBee)
Once you have everything in-hand it is time to program your XBees and build the project. The programming is done through the X-CTU program by Digi, the makers of the XBee. This program is windows-only. If you have a windows PC, you can follow the instructions in your book/site/tutorial without worry. If you have a linux or mac machine, well, the story gets complicated so see the next section.
Datasheet for the XBee. (always good to have at-hand!)
Instructions for updating the XBee firmware set.
Configuring XBees how-to from instructables.
Bildr has a good tut for the series one XBee (if you are stuck with the older series.)
Great post on the differences between the XBee series and firmware versions. Also has instructions for hacking the Arduino XBee Shield to work when updating firmware. (Necessary if you want to use his Python program.)
And then it gets weird… or not (Mac/Linux)
There are sites that say you can get X-CTU working on Linux using Wine. This process basically consists of the following:
- Installing Wine
- Using wine to install X-CTU
- Linking the XBee (/dev/tty*) to the .wine/dosdevices directory
- manually entering the linked XBee (com device) in X-CTU
Here are my personal findings. All tests performed with multiple XBee modules and both the Sparkfun XBee Explorer and the Arduino XBee Shield.
FAIL: Dell D620, Ubuntu 11.04
FAIL: Asus EeePC 901, Ubuntu 10.11
FAIL: Homemade Desktop — AMD 1.8gHz (Frogger!), Ubuntu 9.04*
FAIL: Macbook Pro, Lion (10.7.1), Windows 7 in VirtualBox (latest)
*For this test, the machine actually got past the old “could not open com port” error and got to a completely different error that stated I should hit the reset button on my XBee breakout board. Of course, I could not read nor write to the XBee, so this was also a fail.
Of course my findings are not indicative of whether or not X-CTU and serial communication are possible on Linux, they are simply my results. Your mileage may vary ;) For what it is worth, the following are links to sites with different information on working with XBees of different generations on Linux.
Here is a Python alternative to X-CTU. Never got it to work…
Updating the XBee firmware with the XBee Arduino Shield on Linux.
Also, just for your information: here is the digi.com firmware selection page
You can also just get the firmwarez from their FTP site and skip all the dead links and sorrow on this page.
Beware that it will take a minute or so to load the page in a browser. You are better off opening CyberDuck and entering:
and under the “More Options” tab:
The latest firmware (at the writing of this post) was the XB24-ZB_218C firmware.
When I first started working with my XBees, they were completely unresponsive and unprogrammable. They would spew errors and fail every time I tried to program them. Here’s why, from the Sparkfun Introduction and buying guide.
XBee Znet 2.5 (Formerly Series 2) Retired- These are the fun ones. Series 2 modules must be configured before they can be used. They can run in a transparent mode or work with API commands, but this all depends on what firmware you configure these with. These also can run in a mesh network making them highly configurable and awesome modules. It also makes them harder to use modules. These modules are in no way compatible with the Series 1 modules so stop thinking about trying! These modules are no longer sold but are being replaced with the mostly compatible ZB modules.
The only instructions I found that helped were from this post. I have copied his instructions below for convenience, but they are his instructions not mine.
- Connect the interface board to the computer via appropriate cable (USB or Serial) (If using Serial, connect power as well)
- Make sure the XBee module is NOT plugged into the interface board
- Open the X-CTU program and select the proper COM port.
- The first screen you see in on the PC Settings tab. On this tab please change the baud rate to 38400 and put a check in the “No Baud Change” check box.
- Navigate to the Modem Configuration tab
- Select the proper modem type, function set and firmware version from the 3 drop down menus located about 1/3 of the way from the top of the window.
- Click on the Show Defaults button and put a check in the “Always update firmware” check box.
- Click on Write. (Yes, the module is NOT plugged in) An Action Required box will appear. This is good. When this happens, hold in the config/reset switch on the interface board and CAREFULLY plug in the module and then release the config/reset button.
- You should now see that box disappear and a progress bar will appear along the bottom of the window. You will see the bar progress and then the box will appear again. This is good. Just hold in the reset switch on the interface board for about 1-2 seconds and then release. The box will disappear and the status at the bottom of the window will show that the write was complete.
- Go back to the PC Settings tab and change the baud rate back to 9600 and uncheck the “No baud change” check box.
- Click the “Test/Query” button. You should get a clean bill of health.
Note his method of plugging in the XBee after X-CTU is looking for it. This is a hack that fakes a reset. You can also wire a switch between the reset pin and the ground pin on the XBee and throw that if you want to avoid possibly damaging your module during insertion.
I am still new to the world of Zigbee and XBees, so I will edit and add content as I work more with them in different projects. If you know of misinformation stated here, or have suggestions or fixes, I am more than happy to edit this post to reflect them. If you post to state that you HAVE in fact gotten X-CTU working on Linux or Mac (which I would be very happy to hear about), please be specific with your hardware and software setup (computer make and model and Linux distro) including the breakout board used, firmware set, and model of XBee.
Cheers, and happy wireless communications!