(edit sidebar)
Intro to Physical Computing Syllabus

Research & Learning

Other Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


Xbee Basics

Resources


Overview

This tutorial is intended to provide information for getting started with XBee and XBee Pro 802.15.4 modules.

XBee radios are 2.4GHz radio transceivers that can be used in two ways. They can be used as pass through data modems, to send serial data from one computer or microcontroller to another. They also have their own digital and analog I/O pins on board that you can use to collect sensor data or to control remote devices. They are addressable, so you can set up a network of several radios as well.

When used as serial radios (called serial mode or AT mode), they simply take in whatever comes in their serial input and send it out over 2.4GHz radio waves to a destination radio. When used as standalone devices with sensors or actuators attached (called API I/O mode), they gather data from their inputs and transmit it using their API protocol. They can also receive transmissions that set their output pins using this protocol.

You generally choose to work in either API mode and AT mode and can't use both at the same time. However the exception is that even radios running in AT mode will still produce API-formatted packets when they receive I/O information from other radios set up as standalone sensors.

There are several varieties of XBee radios, the Series 1 radios (also called the 802.15.4 OEM Modules), the Series 2 radios (also called the ZigBee OEM Modules). This tutorial deals only with the 802.15.4 modules, which are the easiest to start with.


Parts

For this lab you will need to have the following parts:

  • A SERIES 1 XBee or Xbee Pro mounted on a breakout board
  • Wire
  • Two LED's
  • A USB-to mini cable (to plug from your computer to the USB-to-serial adaptor)
  • Alternatively, you can use the Sparkfun Xbee Explorer, the New Micros Xbee dongle (more expensive), or Adafruit models which give you direct access to the serial and programming pins on the XBee unit without a breadboard.


1. Connect an XBee to your personal computer via USB

There are two ways you can do this. You can use a pre-made USB-to-serial board like the Xbee Explorer shown here:

Or you can build your own USB-to-serial adaptor using an XBee breakout board and a USB-to-serial adaptor as shown below:

Set up a breadboard as shown in the photos below:

The above images show an XBee Module connected to a FTDI USB-to-serial adaptor. The USB adaptor draws power from the USB bus, and the XBee draws power from the adaptor via its 3.3 voltage output. Note that the adaptor shown is an older model, and the pin positions on newer models have changed. Check the datasheet on the model you bought, and connect the XBee's transmit pin (TX or DOUT) to the adaptor's receive pin (RX or DIN) and vice versa.

Important: XBees can only take 3.3 volts max. Always check to see that your voltage is not above this level before you put your XBee into your board.

Once you've got the XBee module's circuit built and powered,The LED on pin 13 should stay on steadily, and the LED on pin 15 will blink. The former is lit (LED is on) when the module is active. And the later blinks when the radio is associated with a network (LED blinking) or not (LED on steadily). Make sure your circuit is connected to your computer and open Processing (you can also use your favorite serial terminal program if that is more familiar).


2. Configure the XBee Modules Serially

The next thing that needs to be done to start using your XBees, is to communicate with each radio module serially in order to set its local address and destination address.

XBee AT commands are all terminated by a carriage return ('\r', or ASCII 0x0D). If your terminal program allows you to set the string terminator (i.e., the characters sent when you press return), set it to 0x0D. CoolTerm allows you to do this, and is cross-platform. Here's a screenshot of the Options panel from CoolTerm, set up to work with XBees:

If you can't use CoolTerm, Tom Igoe has written an XBee Serial terminal for processing that makes things easy by printing newlines for return characters. Download it here and open it up in Processing. Make sure the sketch is working.

There is one thing that you might want to do before you start serial communication. Get a piece of tape (masking tape works well) tear off a small square and stick it on your XBees. (you don't have to remove it from the board you just built). With a marker, give your XBee a number. "1" works well. This will be your XBee's id and will be used later when you program it. Go ahead and label your second XBee, "2".

Now that you've named your individual XBees, you need to set up a PAN ID for them. All radios with the same PAN ID can talk to each other and ignore the radios on a different PAN ID. Go to the PANID page Choose a series of letters or numbers-- hopefully ones you can remember, and input them on the page so that someone else at ITP won't be trying to talk on the same network as you.

Now we're ready. In order to program the XBee, you first need to put the XBee is in command mode. Xbees essentially have two modes:

  • Data Mode-- where they transmit and receive data
  • Command Mode-- talk to the XBee itself to program it etc.

You put the XBee into command mode by typing "+++" (that's plus, plus, plus without the quotes, and WITHOUT hitting a return afterward).

Try programming the XBee by clicking on the processing sketch and typing the following commands:

  1. Type +++
  2. you should see an OK response in the top window
  3. type AT and see if you get another OK response
  4. if you don’t you’ve gone back out of command mode, so do +++ again (Xbees will automatically go out of command mode if you wait too long to type something).
  5. type ATID to see the current (default) PAN ID
  6. type ATID followed by your PAN ID to set it (if your PAN ID is 1437 then you’d type ATID1437)
  7. type ATID to see the current PAN ID again. It should be changed to 1437 now.
  8. type ATMY followed by the number you have given to the XBee you are programming. In this case, it would be 1, so type ATMY1 and hit return.
  9. type ATMY to see that it has been changed to 1.
  10. type ATDL followed by the number you have given to the other XBee (the XBee you want this XBee to communicate with). In this case, it would be 2, so type: ATDL2 and hit return.
  11. type ATDL to see that it has been changed to 2.
  12. type ATCN to finish.
from Tom's Processing Sketch

Congratulations, you have just configured your First XBee. Wondering what all of that stuff meant? To program an XBee, you use "AT" commands. Some of the ones we just used are described below:

Commonly Used XBee "AT" Commands

  • ATMY my address (the address of the radio you are programming)
  • ATDL destination address (the address of the radio that you will be talking to)
  • ATID personal area network ID (all the XBee's have a group or Personal Area Network (PAN) ID. All radios with the same PAN ID can talk to each other and ignore the radios on a different PAN ID.
  • ATRE Resets the Xbee to its original settings
  • ATWR write settings to firmware

Typing only ATID and hitting return will output the current address for the XBee you are programming. To actually change the address, you will need to enter the AT command, followed by the ID you wish to set. So, you would enter: ATID1437(or whatever you choose for your PAN) and then hit return.

You just did the following commands for Radio 1 (in Column 1). You will now need to do the commands for Radio 2, to program it.

AT COMMANDS

RADIO 1

Radio 2

+++

+++

ATMY 1

ATMY 2

ATDL 2

ATDL 1

ATID 1437 (YOUR PANID)

ATID 1437 (YOUR PANID)


Quit the Processing sketch, and unplug your board from your computer. Next, remove the XBee from the circuit, insert the second XBee and configure it using the same procedure as listed above. Change ATMY to 2, and ATDL to 1. Don't set the radio's destination address to the same value of its source address, or it will talk only to itself.


  Edit | View | History | Print | Recent Changes | Search Page last modified on March 10, 2010, at 08:23 AM