AVR Serial Communications Using XBee RF Modules
I was contacted by Element 14 (Newark.com) recently about doing some product test drives using some of the products from their line card. I took two to three seconds to think about it. I know, tough one...
I have been chomping at the bit to use ZigBee wireless technology in a project. Digi International makes some REALLY cool and easy-to-use ZigBee RF modules that bring ZigBee technology down to a level that even I can implement without more than a few terse passes at a wireless book and a couple of datasheets. So, the first piece of loot I requested from Element14 was an XBee S2 module. I would love to link you to this module at Newark.com, but it appears to be gone. That is sad. BAck to our story... There was a spending limit on my test-drive loot. I ordered one XBee S2 module on my tab. The other XBee module was sent to me courtesy of Element14.com.
The ultimate project is based on a need at our house: We hang out on the back patio quite a lot and when we invite guests over, even after we ask them to just come on in, they ring the doorbell and we can't hear it out on the back patio. The leave disappointed that we would not be home when we said we would be. I'm kidding. Usually they do walk right in.
The first drawring I made used a brass marine-type bell with a string that was routed from the front door around to the back patio. Guests could simply tug on the string to get our attention. My wife wasn't keen on the network of pulleys and string required to make that happen. The drawring above is the watered down, no-fun-havin' version. Awe, who are we kidding? It's still fun. It's ALL fun! What's not to love about electricity and radio frequency waves making things do stuff??
Plan B for the remote doorbell is much cooler and much more electronic: Rig XBee to the house doorbell system so that it can signal a solenoid type of thing to plink a brass bell on the back patio. Not as Wallace & Gromit as the pulleys and string, but still pretty darn cool.
Oh, let me get this out early: Yes, übernerd, I know that XBee is overkill for a simple remote doorbell. The final version of this thing will use a simple little OOK (on-off key) RF module pair that simply sends on or off (button pushed or not). For now, though, this is a great way to get to know Señor XBee and his amigos.
Before I go any deeper into this project, I want to HIGHLY recommend a book on the subject of AVR/Arduino microcontrollers and ZigBee networks. If you're interested in this stuff, go out and get a copy of Building Wireless Sensor Networks by Robert Faludi, published by O'Reilly. I also highly recommend you do NOT do what I did: Do not buy the book, read it cover-to-cover, and do absolutely nothing hands-on. I wound up having to re-read large portions of the book again to get my bearings with the XBee modules from Digi. Try to have an AVR microcontroller (or Arduino) and a couple of XBee modules on hand when you start reading the book.
Now, the first thing I have to say about these modules is that they are stupidly simple to setup and get running, as you'll see in this post. I was asked to do a write-up by Element14.com and this is an easy one: These are AWESOME. There are plenty of sources on the Web for connecting XBee modules. I won't go into major detail, but I will show you how quickly you can get to AVR microcontrollers talking wirelessly with two Digi International XBee S2 ZigBee RF modules. Keep reading...
The process for getting two XBee modules talking, or, in this case, two AVR microcontrollers talking via XBee modules, it this:
- Get two XBee modules (Farnell.com part 1690810) and a handful of 10-pin, 2mm headers used to adapt the non-breadboard-friendly XBee pins to your breadboard
- Get one or two AVR microcontollers with UART capability (and supporting components) or one or two Arduinos
- Build cheesy adapters for the XBee modules so that they fit your breadboards
- Download the X-CTU Windows program to upload newer firmware and appropriate firmware to the XBee modules (this relates to setting up one XBee module as the "coordinator" and one as the "router" [see book above])
- Put some serial-savvy code on an AVR chip or Arduino and connect its UART pins to one XBee module's DIN and DOUT pins
- Connect the other XBee module's DIN and DOUT pins to a serial cable to your computer
- Send commands through the air to the AVR from your favorite terminal program
OK, that's oversimplified, but if you're comfortable with building circuits and working with Arduino or AVRs, that's all there is to it. Take a look at this setup in action (and please forgive the hastily shot and edited video):
If you're a Mac person, and I know I am, you're going to disappointed in the lack of a Mac firmware updater for XBee modules. However, it is pretty darn simple to fire up Boot Camp or VMware and update the radios the way the aforementioned book suggests. I just picked up my breadboard with the two radios and the AVR and the USB-RS232 cable and plopped it on my desk next to my iMac and fired up VMware and did it. Nice and easy, save for one issue: Once the upload of the firmware was complete, Windows XP Pro went to a BSoD (Blue Screen of Death). Pretty awesome. Let me say that it is no secret that I hate Windows. I'm disappointed in Digi for note having a Mac client to update firmware on the XBee modules. Maybe someday...
If you follow the book, you can get two AVRs or a computer and an AVR communicating in pretty short order. The code I wrote for the AVR to receive the serial commands from the computer to switch the traffic LEDs was easy and it actually worked the first time. It's really cool when stuff works as advertised.
If you've got some communicating you need to do between your microcontrollers, especially multipoint stuff, XBee modules are the way to go. Soooooo easy to setup and use. Head over to Newark.com or your favorite source for Digi International products and start mesh networking your DIY gadgets.
This post was originally about the remote doorbell idea. I'll write a separate post about that completed project using simpler RF modules from SparkFun, as ZigBee is WAY overkill for a remote doorbell, unless you're putting little remote bells or buzzers all over your mansion.