Introduction
This write up initially is intended as one stop introduction to Arduino and XBee. However it takes so long to cover everything. Thus it is renamed "Arduino XBee Quickie"! Perhaps it will evolve in the future to cover many other things. So like much of other article in this site, it is brewed to change and grow.
Ramblings
Back to the topic. One of the challenge in getting XBee working with Arduino is that it require several component needed to make it work. At minimum, the 3 component is Arduino (Uno or Duemilanove or other compatible board), XBee Shield (I use DFRobot XBee shield) and XBee module (any series 2 will do, series 1 should work, but this article is for series 2).
That should be enough but in truth, it is not! Let me explain. Imagine that you have 2 of everything, including 2 Xbee module. This 2 XBee module need to communicate with each other. The simplest way is to set one as coordinator and the other as end device. Both of the module most likely arrive to your door step pre-configured as coordinator. Additionally they might be configured using Zigbee protocol. As per this tutorial, they need to be configured to ZNet.
To reconfigure (it is actually re-flashing the firmware), one can use Arduino and the XBee shield connected to PC using Arduino USB cable. However this will not work unless either of bellow workaround is done:
- The MCU chip is unplugged.
- Put the MCU in perpetual reset state (actual technique is left to reader imagination due to it's dangerousness).
So, there is a need for one component that helps in the configuration step. This fourth component is known as XBee explorer among Sparkfun customer. DFRobot sell a similar product named XBee USB Adapter.
Like the name, XBee USB Adapter connects PC (or notebook) to XBee module through USB. We can then re-configure the module using a program called X-CTU (free program from XBee main manufacturer which is Digi, don't mistake this company with DiGi in Malaysia). But that is not all. Now that we have a way to connect XBee to PC. It can also act as a modem to allow the XBee to communicate with the rest of XBee network!
Remember I did mention about having 2 of everything to make them communicate. So the (previous) setup should be like bellow
PC <-- Arduino <-- XBee Shield <-- XBee module (coordinator) <== ==> XBee module (end device) --> XBee Shield --> Arduino
With XBee USB Adapter, we no longger need the additional Arduino XBee shield. So things got simplified as bellow
PC <-- XBee USB Adapter <-- XBee module (coordinator) <== ==> XBee module (end
device) --> XBee Shield --> Arduino
You would agree that this is one really usefull bugger ;).
XBee Module Configuration Step
*Notes: This step are for specific hardware bought from H&T online shop. Applying bellow step on different set of hardware are not advisable and may cause damage or bricking the device. Please be careful! As rule of thumb, if the device is not identified as "XB24-B", most probably bellow step is not correct for that module.
Bellow step is to configure 2 XBee module. Note that both module must be of the same series (for instance series 2). Please follow the step in exactly order!
- Download and install latest X-CTU program from this link --> Digi XCTU Knowledgebase
- Plugged in XBee Module into XBee USB Adapter. Make sure it is not reversed. !!!Critical!!! double check to make sure it is not reversed!
- Plugged in XBee USB Adapter to the PC using appropriate USB cable. XBee USB Adapter and the XBee module should power up and light the relevant LED.
- Go to Device Manager and double check the resulting serial port. If not sure which one, plug and unplug while paying attention to the changes in device manager serial port entry.
- Start the X-CTU program. It should start and show the first tab entitle "PC Settings". If not, change to the tab.
- In "PC Settings" tab select the correct Com Port. The Baud rate setting is always 9600 *unless it has been changed*. Rest assured that if you don't change it, the default is 9600. No other setting changes is necessary (YMMV).
- Click the "Test/Query" button to verify the connection. A message box should pop up. Take note of the XBee module device type in the popped up message box. Mine is "XB24-B". Device type is needed in the next step.
- If everything is okay, open up the "Modem Configuration" tab and click the "Read" button. This will read current configuration of the XBee module. Note that this step will also show device type, you can compare with device type noted in previous step. It might take sometime to read current configuration.
- We are going to reconfigure the series 2 device as end device and using ZNet 2.5 function set (or protocol). Take caution in this step to select only function set that end with "AT" in the name.
Otherwise the module will no longer accept serial command. To the point that is no longer configurable by X-CTU (actually there is a way but it is PITA).
- Under "Modem: XBEE" there is a drop down box. Select it according to the device type discovered in step 7.
- Under "Function Set" there is a drop down box. Select "ZNET 2.5 ROUTER/END DEVICE AT"
- The
version should be the latest (or not). You can also click "Download New
Versions ..." button to get the latest firmware. However this is not
really critical.
- Click the "Write" button and wait for the write process to complete successfully.
- It
is good idea to read the configuration again and double check. However,
this is not necessary since successful write implies that the
configuration is changed.
- Disconnect the XBee USB adapter from PC (to power it off), unplug the module and put it aside. It is a good idea to somehow mark the module in order not to mix them up later.
- Done reconfiguring one of the module as end device! One more to go.
Which need to be configured as Coordinator. Redo step 2, 3, 6, 7 &
8.
- We are going to reconfigure the series 2 device as coordinator and using ZNet 2.5 function set (or protocol). Take caution in this step to select only function set that end with "AT" in the name.
Otherwise the module will no longer accept serial command. To the point
that is no longer configurable by X-CTU (actually there is a way but it
is PITA).
- Under "Modem: XBEE" there is a drop down box. Select it according to the device type discovered in step 7.
- Under "Function Set" there is a drop down box. Select "ZNET 2.5 COORDINATOR AT"
- The
version should be the latest (or not). You can also click "Download New
Versions ..." button to get the latest firmware. However this is not
really critical.
- Click the "Write" button and wait for the write process to complete successfully.
- It
is good idea to read the configuration again and double check. However,
this is not necessary since successful write implies that the
configuration is changed.
- There is no need to unplug the XBee module from the XBee USB Adapter, since it is already configured as coordinator. We are going to use it in the next steps.
* Notes : It is a good idea to check each module PAN ID setting in X-CTU. They should be the same number for both, which is the case by default.
Arduino Interfacing
With above step completed, the other side of the fence is really piece of cake.