Xbee Pro

/media/uploads/tristanjph/08742-03-l.jpg

The Xbee Pro is a wireless unit based on the zigbee stack. There are several different models that can be purchased. This example was tested using a series 1 Xbee pro found here. The whole list of devices that should work with this example can be found here.

Xbee_lib Hello World program

Connect A to your computer and fire up your favourite serial terminal

Import program

00001 #include "mbed.h"
00002 #include "xbee.h"
00003 
00004 xbee xbee1(p9,p10,p11); //Initalise xbee_lib
00005 Serial pc(USBTX, USBRX); //Initalise PC serial comms
00006 
00007 int main()
00008 {
00009     char send_data[202]; //Xbee buffer size is 202 bytes
00010     char read_data[202]; //Xbee buffer size is 202 bytes
00011 
00012     while(1) {
00013         pc.scanf("%s",send_data); //Read data from serial console
00014         xbee1.SendData(send_data); //Send data to XBee
00015         xbee1.RecieveData(read_data,0); //Read data from the XBee
00016         pc.printf("You said:%s",read_data);
00017     }
00018 }

Download this to B and send it some data!

Import program

00001 #include "mbed.h"
00002 #include "xbee.h"
00003 
00004 xbee xbee1(p9,p10,p11); //Initalise xbee_lib
00005 
00006 int main()
00007 {
00008     char read_data[202]; //Xbee buffer size is 202 bytes
00009 
00010     while(1) {
00011         xbee1.RecieveData(read_data,0); //Read data from the XBee
00012         xbee1.SendData(read_data); //Send data to XBee
00013     }
00014 }

Wiring up the Xbee Pro

For the example to work you only need to connect up 5 pins, VDD, GND, TX, RX and Reset. The Xbee pro has 2mm pitch sockets, so you might want to get a breakout board that increases the spacing to the standard 0.1". These can be ordered from sparkfun here.

The xbee will operate on any voltage from 2.8-3.4V. Because of the radio transmission a good stable power supply is vital to get good, reliable transmissions. VDD should be connected to xbee pin 1 and GND to xbee pin 10. The reset line should be connected to pin 5. The reset can be connected to any digital out mbed pin, in this example were using mbed pin 11.

The data in (RX) and data out (TX) lines need connecting to one of the serial ports on the mbed. Because this example was tested on the LPC11U24, were going to connect TX to mbed pin 9 and RX to mbed p10. The TX is then going to connect to xbee pin 3 and the RX to xbee pin 4.

/media/uploads/tristanjph/xbee_wiring.png

Using the Xbee-Pro

The commands that xbee_lib currently supports are:

  • Entering/Exiting config mode
  • Getting the device serial number
  • Setting the network security key
  • Setting the PAN ID of the network
  • Writing the settings to non volatile memory
  • Sending Data
  • Receiving Data
  • Resetting the Xbee

Things to be careful of:

  • The Xbee will take 2 seconds to enter into config mode
  • Resetting the Xbee will take 1 second
  • Settings will only be saved if written to non volatile memory
  • All the devices that you want to communicate with need to have the same PAN ID and security key

Xbee_lib library

Import library

Public Member Functions

xbee (PinName tx, PinName rx, PinName reset)
Configure serial data pin.
int ConfigMode ()
Puts the Xbee into config mode.
int GetSerial (int *)
Gets the serial number/mac address of the Xbee and places it into serial_no.
int SetKey (int *)
Sets the encryption key to the one stored in security_key.
int SetPanId (int)
Sets the id of the PAN network for the Xbee to use.
int WriteSettings ()
Writes the settings to the Non volatile memory on the Xbee.
int ExitConfigMode ()
Exits config mode.
int SendData (char *)
Sends data in the send_Data buffer.
void RecieveData (char *, int)
Recieves data sent to the xbee.
void Reset ()
Resets the Xbee.

Data Sheet: http://ftp1.digi.com/support/documentation/90000982_G.pdf

If your Xbee stops working use a serial loop through program on an LPC1768 and run this program to restore defaults: http://ftp1.digi.com/support/utilities/40003002_B.exe


All wikipages