Arduino‎ > ‎Brewing Arduino‎ > ‎

Arduino & XBee Quickie

posted Apr 10, 2011, 4:14 AM by Haris Hashim   [ updated Feb 10, 2012, 2:13 AM ]





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!

  1. Download and install latest X-CTU program from this link --> Digi XCTU Knowledgebase
  2. Plugged in XBee Module into XBee USB Adapter. Make sure it is not reversed. !!!Critical!!! double check to make sure it is not reversed!
  3. 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.
  4. 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.
  5. Start the X-CTU program. It should start and show the first tab entitle "PC Settings". If not, change to the tab.
  6. 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).
  7. 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.
  8. 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.
  9. 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).
    1. Under "Modem: XBEE" there is a drop down box. Select it according to the device type discovered in step 7.
    2. Under "Function Set" there is a drop down box. Select "ZNET 2.5 ROUTER/END DEVICE AT"
    3. 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.
    4. Click the "Write" button and wait for the write process to complete successfully.
    5. 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.
  10. 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.
  11. 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.
  12. 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).
    1. Under "Modem: XBEE" there is a drop down box. Select it according to the device type discovered in step 7.
    2. Under "Function Set" there is a drop down box. Select "ZNET 2.5 COORDINATOR AT"
    3. 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.
    4. Click the "Write" button and wait for the write process to complete successfully.
    5. 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.
  13. 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.

I am using DFRobot IO Expansion Shield. But the various XBee Shield including DFRobot XBee Shield should work the same.

Arduino &amp; XBEE

Tips: if there is problem uploading sketch to Arduino, disconnect XBee shield or just the XBee module itself from Arduino board and try to upload the code again.
  1. Let's start with our favourite Arduino board (Duemilanove, Uno or Mega) not connected to any shield. 
  2. Upload the following simple sketch just to say hello to our new toy!

    void setup()  {
      Serial.begin(9600); 
     
    void loop() { 
      Serial.println("Hello XBee!"); 
      delay(1000); 
    }

  3. After sketch is successfully uploaded, unplug the USB cable to power down the board. 
  4. Mount XBee module configured as Router / End Device on the shield and then mount the shield on Arduino. Important! Make sure the xbee module is mounted correctly and not in reversed position.
  5. Power up the board using USB and pay attention on red LED in the vicinity of the XBee module. This LED is steady when the module is not associated with a Coordinator configured module. Since we left the Coordinator configured module connected to the XBee USB Adapter. In a verry short time, this LED will transition from steady to blinking about twice per second.
  6. How to know that the sketch is working? Open up the X-CTU windows used in the configuration steps to view the Terminal tabs. The greeting "Hello XBee" should be seen once every second.
Welcome to the exciting world of wireless communication!
Comments