A Friendly Introduction to XBee

Digi XBee radios sure are handy for wireless communication in embedded systems, so let’s take a look from a newbie perspective at how to get two of ’em talking to each other quickly.                       Home

This tutorial can be applied generically to any setup with any two XBee radios, so long as you have them plugged in and ready to work with a serial port. That being said, this is a list of parts used in this tutorial:

As far as software goes, we’re going to need to use the one and only Xbee programming tool, XCTU from Digi (Windows, Mac OS, and Linux). Although, I suppose if you were hardcore, you could program using raw AT commands at the console, but I doubt that’s a path you’re willing to take at this time!

We’ll start with installing the software, configuring the XBee radios, installing them, and finally get them talking to each other.

Digi XCTU Software

Installation of the Digi XCTU software should be straightforward enough. Head over to the XCTU download page, download it for your platform, and follow the install instructions.

When you’ve installed it, open it up. Here’s what you should see:

Okay! Now, we’ll move onto hooking up the XBee radios using the XBee explorer breakout board and configuring them using our newly installed XCTU program.

Configuring the XBee Radios

Here’s where the rubber meets the road, so to speak! We’re going to break out the SparkFun XBee Explorer and program both of the XBee radios so they can talk to each other. All we need here is a USB Mini-B cable to connect the XBee Explorer in with our computer with XCTU installed. Grab one of the XBee radios and install it into the XBee explorer, then plug the XBee explorer into the USB cable connected to the computer.

Once you’ve made the connections, open XCTU (if you haven’t already) and click on the “Discover devices” button. From here, you just have to scan for your device plugged into the XBee Explorer.           Home

Now, before we continue, there are a couple of concepts and some terminology we’ll need to be familiar with.

With an XBee network like we’re setting up, there needs to be a coordinator and an end device. You can almost think about it as having a router and a computer.

  • With an XBee network like we’re setting up, there needs to be a coordinator and an end device. You can almost think about it as having a router and a computer.
  • We need both of the radios to be on the same channel and network, or PAN in this case.
  • Every option is abbreviated with a two letter key. The ones we’re concerned with for this guide are:
    • CH – Channel
    • ID – PAN ID
    • MY – 16-bit Source Address
      • This is the address of the current device and can be any 16 bit number.
    • DL – Destination Address Low
      • DL is the address of the device you want to talk to, it can be any other 16 bit number other than MY.
    • CE – Coordinator Enable
    • BD – Interface Data Rate (Optional)
    • CT – AT Command Mode Timeout (Optional)
  • The XBee radios are programmed using AT commands over serial console. The XCTU program makes programming the XBee incredibly easy as it takes care of running all the AT commands transparently in the background.

Pro Tip: Save yourself some headaches and label your XBee radios in order to tell them apart. A piece of tape or tiny post-it note and permanent marker will do just fine. Label one with “C”, for “Coordinator” and the other with “ED”, for “End Device”. You could also write the MY, 16-bit Source Address, for extra clarity.

Program the Coordinator

Okay, let’s take our first XBee radio, which we’ll designate as our Coordinator (and will ultimately be installed in the TS-7553-V2), and open the “Configuration” window in XCTU. This is what you should be looking at:

Pro Tip: XCTU is pretty well designed, with handy little UI gems like a blue ‘dog ear’ triangle to mark which settings have changed from defaults. Firmware updates, updating individual settings, and more come in pretty handy. Be sure to familiarize yourself once you’re ready.                   Home

Here’s what we’re going to set on our coordinator:

CH, Channel = D
ID, PAN ID = DA
DL, Destination Address Low = BEEF
MY, 16-bit Source Address = BFFO
CE, Coordinator Enable = Coordinator [1]

These two configuration changes are optional, but if you do change them, make sure to set the same on both XBee radios. We found these additional settings make things run smoother and more responsive.

BD, Interface Data Rate = 57600 [6]
CT, AT Command Mode Timeout = 1770

Once you’ve set these configurations, make sure to click on the “Write” button to save the changes to the XBee radio. Once it’s finished writing, go ahead and unplug the XBee Explorer and take out the XBee radio.

Installing the Coordinator

This is where our TS-7553-V2 comes into play. This guide is going to assume you’re already familiar with getting the TS-7553-V2 powered on and ready for development. If you’re not there yet, you can take a look at the “Practical Guide to Getting Started With the TS-7553-V2”. There’s a XBee socket on the TS-7553-V2 that shows up under the /dev/ttymxc7 serial device.

Before we can plug in our XBee radio, we need to remove or bend pin 8 of the XBee radio in order to avoid conflicts (to be fixed in a later revision).

Then, plugin the XBee radio we’ve designated as the coordinator like this:

Pro Tip: Make sure that the flat end of the XBee radio is facing back towards the USB and Ethernet connectors. Otherwise, you may do permanent damage to the XBee radio.

Then, let’s be sure that the XBee radio is powered on and ready to communicate. First, issue the command to make sure it’s turned on (it should be by default):

root@ts-imx6ul:~# echo 1 > /sys/class/leds/en-xbee-3v3/brightness

Then, let’s open a serial connection with the XBee radio using picocom, making sure that the baud rate is set to the same value as BD, Interface Data Rate on the XBee radios.

root@ts-imx6ul:~# picocom -b 57600 /dev/ttymxc7

Perfect! Now, we’re ready for the next step.

Program the End Device

Now, we’re going to install the second XBee radio into the XBee Explorer and then plug in the XBee Explorer into the computer. We’re going to designate this radio as our End Device. Do the same thing as before and click on the “Add devices” or “Discover devices” buttons to find your device and load up the “Configuration” window, like so:

Here’s what we’re going to set on our end device:               Home

CH, Channel = D
ID, PAN ID = DA
DL, Destination Address Low = BFF0
MY, 16-bit Source Address = BEEF
CE, Coordinator Enable = End Device [0]

And again, these are optional, but they must be the same on both devices.

BD, Interface Data Rate = 57600 [6]
CT, AT Command Mode Timeout = 1770

Great! Now, we’re going to leave this one plugged into the XBee explorer for the next step.

Time to Start Talking!

[gfycat data_id="SillySnoopyAfricanwilddog"]

Now, the exciting part, communicating wirelessly over a serial port provided by the XBee radio. We start off by going back to our XCTU program where we left off and open the “Console” window, like so:

We’re now going to send a packet to the coordinator installed in our TS-7553-V2 from our end device. Click on the plus icon (+) next to the “Send packets” field. Here, type in your ASCII message. Something as simple as “Testing” will work. Save the packet once finished. Then, select the new packet and click on the “Send selected packet” button. Head over to the TS-7553-V2 picocom session we opened earlier and you should now see “Testing” written on the screen! Start typing in picocom, like “Testing back!”, and you should see the message being written in the Console log field of the XCTU program!

Congratulations on setting up your wireless serial console connection! You’re well on your way to creating something awesome using XBee radios!

Conclusion and Next Steps

In this guide, we walked through what it took to install, configure, and wireless transfer data over two XBee radios. Now that you have the basics out of the way, it’ll be time to dive into a wireless XBee world with different topologies and configuration options.

If you have any further questions, or feel like we’ve forgotten to mention anything, please let us know in the comments below!   Home

Leave a Reply

Your email address will not be published. Required fields are marked *