Overview
This is an Arduino library for communicating with XBees in API mode, with support for both Series 1 (802.15.4) and Series 2 (ZB Pro/ZNet). This library Includes support for the majority of packet types, including: TX/RX, AT Command, Remote AT, I/O Samples and Modem Status.Note: This software requires API mode, by setting AP=2. If you are using Series 2 XBee, you'll need to install API Firmware (they ship with AT firmware), then set AP=2. This software will not work correctly with AP=1 Refer to XBeeConfiguration and WhyApiMode for more info.
News
- 10/15/12 Release 0.4 (beta) is available. Paul Stoffregen (Teensy creator) has contributed a patch that allows for using SoftwareSerial for XBee communication! This frees up the Serial port for debug or to use with other hardware. Try it out and report any issues on the Google group page. Important: See SoftwareSerialReleaseNotes as it was necessary to change the API to support this feature.
- 12/21/11 Release 0.3 is now available. This release includes support for Arduino 1.0 along with some bug fixes and a new setSerial function for using alternate serial ports (e.g. Mega). This release is compatible with previous Arduino releases as well.
- 4/3/11 I have created an XBeeUseCases wiki on XBee API that describes several use cases for communicating with XBees.
- 11/14/09 Version 0.2.1 is available. This release contains a bug fix for Remote AT
- 10/26/09 XBee-Arduino 0.2 is now available. This release adds support for AT Command, Remote AT, and I/O sample (series 1 and 2) packets. Along with this release I have created several new examples.
- 8/09/09 I have released Droplet, a wireless LCD display/remote control with support for Twitter, Google Calendar, weather etc. It uses this software to send and receive XBee packets.
- 4/19/09 Release 0.1.2: In this release I added some abbreviated constructors for creating basic Requests and get/set methods to facilitate the reuse of Requests
- 3/29/09 Initial Release
Documentation
API docsExample
I have created several sketches of sending/receiving packets with Series 1 and 2 XBee radios. You can find these in the examples folder. Here's an example of sending a packet with a Series 2 radio:// Create an XBee object at the top of your sketch XBee xbee = XBee(); // Tell XBee to start Serial xbee.begin(9600); // Create an array for holding the data you want to send. uint8_t payload[] = { 'H', 'i' }; // Specify the address of the remote XBee (this is the SH + SL) XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x403e0f30); // Create a TX Request ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload)); // Send your request xbee.send(zbTx);See the examples folder for the full source. There are more examples in the download.
See the XBee API project for Arduino < - > Computer communication.
To add XBee support to a new sketch, add "#include <XBee.h>" (without quotes) to the top of your sketch. You can also add it by selecting the "sketch" menu, and choosing "Import Library->XBee".
Learning/Books
If you want to learn more about Arduino and XBee, check out these books:- Wireless Sensor Networks: with ZigBee, XBee, Arduino, and Processing (Available in Kindle)
- Programming Arduino Getting Started with Sketches
- Making Things Talk
- Getting Started with Arduino (Make: Projects (Available in Kindle)
- Arduino Cookbook (Oreilly Cookbooks) (Available in Kindle)
Hardware
I highly recommend using an Arduino that has 2 serial ports, such as the Arduino Leonardo. The reason is the XBee requires one serial port and it's useful to have another serial port available for debugging. The Arduino Leonard actually has one hardware serial port and one virtual (usb serial port). The hardware serial port is for use with XBee (Serial1) and the virtual serial port (Serial) may be used to send debug info to the console. The Arduino Mega is another popular choice as it has 4 hardware serial ports, along with additional memory and I/O. Both boards are compatible with XBee Shields. The Teensy board, by PJRC, may be a good choice for some advanced users. It is not 100% Arduino compatible but PJRC provides a plugin to the Arduino IDE. They also sell an XBee Adapter to interface XBee with Teensy (requires soldering).- Arduino Leonardo (recommended)
- Arduino UNO R3 (note: only has one serial port)
- Arduino Mega 2560
The Arduino XBee Shield is the best choice for connecting the XBee to an Arduino
You can find XBee Shields on ebay, often for less, but keep in mind delivery may be slow when shipped from China. I don't recommend the SparkFun XBee Shield since it requires soldering headers (not included) to connect to an Arduino board
An XBee Explorer is highly recommended for updating firmware and configuring the radio. This is also useful for interfacing an XBee with a computer. If you are using Series 2 radios you'll need an XBee Explorer to upload API firmware to the radio (they ship with AT firmware).
See the xbee-api Hardware wiki for more parts links.
For interfacing with Arduino clones that are not shield compatible, such as Modern Device's http://shop.moderndevice.com/products/rbbb-kit, you will need 3.3V power and logic shifter or voltage divider to convert Arduino's 5V to an XBee safe 3.3V.
Installation
Arduino 16 (or earlier):Download the zip file, extract and copy the XBee folder to ARDUINO_HOME/hardware/libraries If you are upgrading from a previous version, be sure to delete XBee.o
Arduino 17 (or later):
Determine the location of your sketchbook by selecting "preferences" on the Arduino menu. Create a "libraries" folder in your sketchbook and unzip the download there. See this for more information.