Xbees are nice small part used to help small stuff, like Jaluino Bee, communicating together. These are wireless modules, implementing ZigBee protocol. This is quite a tough one, luckily using XBees themselves remains something accessible for the mere mortals. While you could use Bluetooth modules, you may still be interesting in using Xbee as they can join together to build a multi-point network. That is, having several modules talking each others, not just point-to-point communications.
Xbee in transparent mode
I’ve been using two XBees for month, in transparent mode. In this mode, point-to-point is implemented. This is basically a serial over-the-air link, it works very nicely, and most importantly, reliably.
I’ve been using Xbee series 2 only, as series 1 is becoming deprecated. While series 1 works right out-of-the-box, series 2 requires you upload a specific firmware. I strongly suggest you follow this great tutorial, explaining all the steps in details. (note this PDF file can be found on many different sites, I wish I could credit the author but nothing except his first name — or last –, Cairn). I also strongly suggest you buy two XBee adaptors like the ones Cairn is using, you can find some for few bucks on eBay. And you’ll save a lot of time in the end.
So, this is transparent mode: in AT mode, a “Router / End Device”, typically your Jaluino Bee, is talking to a “Coordinator”, typically your PC, collecting data. This is not what we want here, but that’s a start, and that’s a first step before going further so make sure you’ve been able to have your xbees talking each other, through a point-to-point link.
Entering XBee API mode
Now, what if you add a third Xbee ? Well, that’s what I’m facing right now, as I want to add another monitoring station, collecting data to some IOT platform like Pachube. So, this third Xbee is going to cause a lot of pain if plugged as-is over your point-to-point link. Basically, Coordinator (PC) will receive characters from the other two xbees, without knowing which is talking. Conflicts, collisions. You could adapt your communication protocol, where the Coordinator would poll others Xbee, but you’d then implement retry on error, End Devices wouldn’t be able to talk without being explicitely asked to…
That’s what API mode is made for. In the mode, XBees can send data frame to each other, without any risk of collision. In order to achieve this, we need to access XBee through API commands. This isn’t transparent anymore, this adds complexity, but not much compared to what it brings on the other hand.
So, for this first part, we’ll make sure our XBees are properly configured. We won’t use any Jaluino Bees for now, just two XBees connected to a PC.
Plug a XBee on an adaptor, in the same configuration used in previous transparent mode tutorial (see PDF file link above). Wire this adaptor to USB-to-serial adaptor (again, see PDF tutorial).
My setup: on top, USB-to-serial converter, connected to, on bottom, XBee adaptor.
Open X-CTU, you should be able to see a USB serial port. Select it (mine is COM4), run “Test / Query”, to make sure you’re able to talk to your Xbee.
Now switch to “Modem Configuration” tab, click “Read”. In the dropdown list, select “ZNET 2.5 COORDINATOR API”. Click “Write”.
Selecting Coordinator API firmware
Go back to PC settings, run “Test / Query”. It fails. Why ? Because now we need to tell X-CTU it should access XBee in API mode. Check “Enable API”, and re-run test. It works.
Using “Enable API”, we can talk to Xbee again
We now need to fine tune Coordinator configuration, specifically setting “Escape mode”. Back to “Modem Configuration”, click “Read”. Scroll down and set “API enable” to 2. This means some characters will be escaped, basically those used to form data frame. This ensure there won’t be collision between user data and API specific chars. Click “Write” again. You can also set a “Node Identifer” string, like “COORD”.
API Enable = 2 means some chars will be escaped. While testing comms on “PC Settings” tab, you’ll need to check “Enable API” and “Use escape chars” to talk to your XBee !
Important: note the following parameters, we’ll need them later.
- Serial Number High: 13A200
- Serial Number Low: 40301109
We’ll proceed the same, except we’ll select “ZNET 2.5 ROUTER/END DEVICE API”. Make sure you have “Enable API” set to 2.
- Serial Number High: 130200
- Serial Number Low: 4054F82F
Testing API Mode
You have one Coordinator, one End Device. Plug them on their respective adapter. You should now have two Serial USB port, one for each. In the following test, Coordinator will send data to a specific End Device.
We’ll use the following python script in order to test our setting. These scripts use the excellent python-xbee library, you’ll need to install it:Â http://code.google.com/p/python-xbee/
Edit “receive_samples.py”, and change PORT to whatever your port is. Mine is COM13 for End Device (remember, End Device will receive data).
Now edit “send_samples.py”, change serial port as well, and then change the value of DEST_ADDR_LONG. Here’s mine:
DEST_ADDR_LONG = "\x00\x13\xA2\x00\x40\x54\xF8\x2F"
Gasp,what is this ? Well, first, this is the destination address for End Device we want to talk to. That is, its “serial number high” concatenated to its “serial number low”. Have you noted these values ? Great. This address is 64-bits long, so you may pad values with 0s if needed.
My serial number high isÂ 130200. I need two more bytes to have 32-bits, so that’s 00130200. My serial number low isÂ 4054F82F. No 0s needed. So, final address is:
This is in hexadecimal format. We need to tell python about this. So we add “\x” in front of each byte:
Now run the sample on different cmd shell.
It works !
You can try to switch address to End Device will talk to Coordinator. Plug Coordinator first and run receive sample. Then plug End Device, don’t run python sample. In this configuration, you’ll notice something interesting: when End Device is up, Coordinator will receive a data frame about it. Particularly, End Device sends its own address, something interesting to build generic host application where devices auto-register to the Coordinator Xbee.
Devices sends information to coordinator about itself when powered up
What’s next ?
In next part we’ll see how to plug this on a Jaluino Bee, and make it talk to the PC.
Any questions ? Join Jaluino forums.