Tutorial: XBEE Basics

  1. lnxfergy's Avatar
    lnxfergy lnxfergy is offline Mech Warfare Organizer Alumni
    How To, DIY

    XBEE Basics

    Parts Required

    • 2x XBEE

    • 1x XBEE Explorer

    • 1x LP2950 3.3V 100mA Regulator (optional)

    • 2x 1k8 Resistor (optional)

    • 1x 3k3 Resistor (optional)

    • 1x XBEE Breakout board (optional)

    Tools Required

    • Python (FREE)

    • XBEE terminal (FREE)

    XBEE Basics
    What's cooler than a robot? A robot with a wireless network adapter! The XBEE wireless radio modules from Maxstream are a quick, inexpensive, and easy way to implement a wireless serial interface between two devices. They are practically a drop in replacement for a TTL-level serial cable. They have a low (~ 50mA) current consumption, and long range (rated at 300ft line of sight, but I have at least full speed coverage throughout a two-story house).

    An important note: Series 1 XBEE devices cannot talk to Series 2 (or series 2.5 devices)

    Wiring Options
    Connecting to the XBEE devices is quite easy, however, just remember that they are 3.3V devices. The regular ol' XBEE will draw about 50mA (the PRO modules may draw upwards of 300mA). We can easily power our regular XBEE from an LP2950 3.3V 100mA regulator.

    There are a variety of easy to use modules for setting up your XBEE:

    • An XBEE USB Explorer can be used to connect an XBEE directly to your PC. It is a compact circuit board that already hhas a 3.3V regulator, plus a USB connection to commiunicate with your computer. It draws power directly from the serial port. Simply plug it into a USB port and you're ready to go. I always keep an Explorer handy to do setup on my XBEE devices. (The XBEE Explorer is the red circuit board shown in the picture below).
    • You can also connect an XBEE directly to an FTDI breakout board.XBEEs unfortunately use 2mm headers, rather 0.1" that we are all so accustomed to, however a breakout board that converts the 2mm layout to a breadboard-accessable 0.1" one is available for only a few dollars. The breadboard below shows an FTDI breakout board, connected to and powering an XBEE breakout board.
    • An XBEE can be directly coupled to the TX/RX lines of a 3.3V or 5V microcontroller. In either case, it will still require a 3.3V power source. It is recommended that you use several resistors for a voltage divider if using the XBEE with a 5V microcontroller, however, I don't. The following schematic shows both a circuit with voltage divider resistors and without, regardless, the XBEE always requires a 3.3V power supply:
    Most users will find they already have the FTDI drivers, but you may find that you need to install drivers for the XBEE Explorer or FTDI breakout. They can be found at http://ftdichip.com/Drivers/VCP.htm

    Pairing and Other Parameters
    If you want to have your XBEEs communicate at high speed, with the automatic resending of lost packets, you'll want to pair them. And trust me -- you want the automatic resending capability! This is very easy, we just need to set a few registers in the device. XBEE devices have several settings that we will use, and many more that we won't be using right now. XBEE modules use standard AT commands. This is a protocol left over from the days of serial modems, but it still works for us now. These commands allow you to edit the registers found inside the XBEE. Each register has a name, prefixed by AT, such as ATBD, which is the Baud Rate register.

    First off, XBEE radios only operate at a given baud rate, this is the number of bits per second that the XBEE can send. A brand new xbee will default to 9600bps, which is pretty slow. We can change the baud rate, by changing the ATBD register. Both of our XBEEs have to be the same baud rate to talk to one another. The available baud rates (and corresponding ATBD value) are:

    • 1 = 2400bps
    • 2 = 4800bps
    • 3 = 9600bps
    • 4 = 19200bps
    • 5 = 38400bps
    • 6 = 57600 bps
    • 7 = 115200 bps
    The next parameter of interest is the Personal Area Network ID. This is a number shared amongst each XBEE in a network. For now, we are only using 2 XBEEs, but we could have many, many more in a single network. XBEEs on different networks do not "see" each other. The default PAN is 3332, so you should avoid that number. The PAN ID is stored in ATID

    Once both of our XBEEs are on the same network, we can give each one an address number, denoted by ATMY. We can also set the destination address, which is what address number to talk to, denoted ATDL (for destination low, we really don't need to use the high bytes if we keep our address numbers < 16 bits in length). A sample setup of two XBEEs that will talk directly to one another, at 38.4kbps:

    ATID = 1111
    ATMY = 10
    ATDL = 11
    ATBD = 5
    ATID = 1111
    ATMY = 11
    ATDL = 10
    ATBD = 5

    Additionally, XBEE devices are 2.4Ghz radios. The 2.4Ghz band is currently used by many, many devices. None of them operate at exactly 2.4Ghz, there are several different channels which are in the 2.4Ghz band. We can change which channel the XBEE devices are on, ATCH, but again, devices on different channels cannot talk to one another.

    Using the MaxStream Software
    MaxStream distributes a piece of software called X-CTU which allows you to set all of the parameters we describe above, using a Graphical User Interface. Unfortunately, the software is a Windows application, but luckily for those of you using Linux (like myself), X-CTU can be run under Wine, here's how.

    When we start X-CTU, we need to select the baud rate and port that our XBEE is connected to:

    It's a good idea to click Test/Query to check that your baud/port are correct. If so, you'll see a box that says:

    Once we know we have a good connection, we'll switch over to the Modem Configuration tab, and click Read. The items of interest are obviously the Channel (CH), PAN ID, Destination Low (DL), and Source Address (MY).
    We have to scroll down a ways to see the Baud Rate (BD) setting:

    Once we make any changes, click Write to send them out to the XBEE. The write phase could take a little time.

    Using the XBEE-API Terminal to Send AT Commands Directly
    The XBEE-API Terminal is a simple to use python program that allows you to interact with an XBEE directly, sending AT commands. Why can't we just use any old terminal? First, we want to send carriage returns rather than newlines, but also, we don't want to send a carriage return on some transmissions.

    To setup the XBEE-API Terminal, you will need Python 2.5, and the PySerial package installed. You'll then want to pull down xbeeterm.py and xbee.py and put them on your path:

    This same API can be used to programmatically interact with XBEEs quite easily. Setting this up to run, is just like any other python script.

    Before we can send AT commands, we need to get the XBEE into AT command mode, by sending "+++" and nothing else, for at least 3 seconds. We should have a short pause and then see "OK". The XBEE will automatically exit AT command mode after 10 seconds of inactivity. We can then send data to our XBEE, or read back. With our example XBEE still in the XBEE Explorer, we would see:

    > +++
    > ATBD
    > ATID
    > ATDL
    > ATMY
    > ATND
    That last command is quite interesting. ATND tells the XBEE to do a Node Detection, which lets us find what devices are on around us. In this case our Arduino XBEE was on, we can now see what the key registers are set to, and how strong our connection is.

    We can also easily set parameters. An important thing to note though, is that changes we make are stored in temporary memory, if we power the XBEE device off, they are lost. We need to send ATWR to write the changes to non-volatile memory. If we decide to change our settings:

    > +++
    > ATID2222
    > ATMY12
    > ATID
    > ATWR
    Our PAN is now 2222, and our ID is 12 rather than 10. Our XBEEs will no longer talk to each other, or even see one another. You should change it back before continuing!

    Testing our setup with an Arduino
    To test our setup, we can use an Arduino to loopback our data. In this example, the Arduino will recieve data from the XBEE, and then send it back out, after incrementing by one. Thus if we send "Hello", we should see "Ifmmp". Hook up one of our XBEEs as shown above with our Breadboarded Arduino Connection, and plug our other into the XBEE Explorer. NOTE: You will have to remove the XBEE from the breadboard when downloading code onto the Arduino.

    // this is where we will put our data
    int myData = 0;
    void setup(){
        // Start up our serial port, we configured our XBEE devices for 38400 bps. 
    void loop(){
        // handle serial data, if any
        if(Serial.available() > 0){
            myData = Serial.read();
            if(myData == '\n')
                Serial.print(myData + 1, BYTE);
    Notes About Protocols
    Being a wireless network, there will eventually be lost information -- even though the XBEE has automatic resend of lost packets. For mission critical stuff, I recommend adding your own data integrity or checksum/resend protocols on top of the hardware resend built into the XBEE.
    Attached Files

Page 2 of 2 FirstFirst 12
Replies to Tutorial: XBEE Basics
  1. dariush_abbasi868 Guest

    Re: XBEE Basics

    I test it but only +++ reply to ok .
    other at command nothing!
    I wait for several second after ok of +++ and also send at command and send enter key . after at command !
    pls help me.

  2. homero Guest

    Re: XBEE Basics

    I would like to know is there a way to change the channel from the arduino, while not connected to a computer?

  3. Re: XBEE Basics


    I have a problem triggering digital output (like DO0) on the remote ZigBee.

    Case 1:
    I know I can trigger it like this:
    - setting digital input on the base ZigBee
    - setting digital output on the remote ZigBee (DO LOW)
    - and if configured right the input state on the base ZigBee is transferred to the digital output on remote ZigBee
    I managed to do that, but I would like to trigger it via data packets.

    Case 2:
    So I tried with setting API packets that set the digital output on the remote ZigBee. I managed to change the digital output on remote ZigBee with commands ATD0=4 (DO LOW) ATD0=5 (DO HIGH).

    DO LOW API command:
    7E 00 10 17 05 00 13 A2 00 40 08 C9 80 00 02 02 44 30 04 21

    DO HIGH API command:
    7E 00 10 17 05 00 13 A2 00 40 08 C9 80 00 02 02 44 30 05 20

    But the problem I have is that sometime the communication between the base and remote might be lost. And if the digital output on the remote ZigBee is set to 3,3V (DO HIGH) and the communication is lost, the digital output would stay at the 3,3V. I want it to "reset" to 0V. In "case 1" when I tried to trigger the digital output with digital input, you can set the reset timer for that digital output (command ATT0) and it did the work (the digital input reset to value 0V), but you can't use that in the case 2.

    Does anybody know what is the API format of the packet to simulate case 1 - I/O line passing (case 1 data packets)?
    Do you have any other ideas how to "reset" the digital output to 0V.

  4. Re: XBEE Basics

    Please post questions as a thread in the forum -- the tutorial section doesn't get as much traffic from people who can answer questions as the main forum.


  5. apoorv.S Guest

    Re: XBEE Basics

    thanks for the tutorial...I m an electronics engineer but i am new to Xbee. this tutorial has helped me a lot but I have some Query reguarding the communication betwwen the 2 Xbees.
    Actually I am making a PC controlled wireless robo using Xbee interface with arduino.
    My Question is- Is it possible to transmit the input directly via Xbee explorer to the receiving end of the Xbee of the destination..? Also
    Is there a need of two arduinos (one for TXing & one for RXing) for making a communication betwwen PC and Robo, or a single arduino will do..??

    reply eagerly awaited..

    thanks and regards

  6. v1c Guest

    Re: XBEE Basics

    This tutorial is very useful! but... i have a doubt, suppously we have 16 chanels to use, but for example, if i want to have like... lets say, 50 conections point to point in a house, is this possible to do? and trying not to have interferences between each conection point to point.
    What i wanto to do is a sensoring control, but each control have dierent signlas.

  7. calexander Guest

    Re: XBEE Basics

    The Ardunio testing instructions are not clear; at least for me as other people somehow got it with no problem.
    When uploading example code and then hooking up one xbee to an Arduino Uno (COM11) - using Ardunio's 3.3v, Gnd and Rx/Tx (D0,D1) to Xbee's DIN,DOUT, I connect the other Xbee to an Explorer and connect to it using the terminal in X-CTU (COM12).

    Opening the serial terminal in Arduino's program on COM11, typing in there I get the expected text. But that's because the code is local to that board. However, typing anything in the other terminal on COM12, does not produce anything. I've double/triple checked the ID's, Network, Baud - everything is as it should be. I even tried with different XBee modules with the same result (all are Series 1 modules).

    Anyone have this kind of problem or have an idea on what's wrong?

  8. Samwell Guest

    Re: XBEE Basics

    Thanks! For hooking up an XBEE to an arduino without doing any configuration, and using 5V there is this nice tutorial from lucidtronix. They have a schematic, sample code, and a parts list with links.

  9. Canto Guest

    Re: XBEE Basics

    I'm trying to comunicate two Xbee S2 one as a Coordinator and the other one as End Device.
    I used Moltosenso Iron to configurate them in the same network with this AT commands:

    ATID 1111
    ATBD 3
    ATCH 14
    ATMY 0
    ATDH 000d6f00
    ATDL 00068924

    ATID 1111
    ATBD 3
    ATCH 10
    ATMY 5F10
    ATDH 000d6f00
    ATDL 00068924

    Then i tryed this code in the EndDivece to see if works:

    __________________________________________________ ___
    /* Serial Test code
    Sends "testing..." over the serial connection once per second
    while blinking the LED on pin 13. Used for testing serial devices
    such as the XBee.
    Adapted from the SoftSerial Demonstration code

    #define ledPin 13
    byte pinState = 0;
    void setup() {
    pinMode(ledPin, OUTPUT);
    void loop() {
    // toggle an LED just so you see the thing's alive.
    void toggle(int pinNum) {
    // set the LED pin using the pinState variable:
    digitalWrite(pinNum, pinState);
    // if pinState = 0, set it to 1, and vice versa:
    pinState = !pinState;
    __________________________________________________ ___

    But it does'nt.
    I don''t know where is the problem.
    I'll appreciate if someone how know xbee could help me.


  10. danipi Guest

    Re: XBEE Basics

    Thanks this will be really helpful!

Closed Tutorial
Page 2 of 2 FirstFirst 12