Page 1
802.15.4 protocol. For more information, check out the Exploring XBees and XCTU tutorial. The XBee Shield gives your Arduino a seamless interface to XBee -- one of the most popular wireless platforms around. With XBee, instead of being tied down by a serial cable -- inches away from a paired device -- your Arduino can pass data over the air to another device hundreds of feet away.
Page 2
SparkFun XBee 3 Wireless Kit KIT-15936 Product Showcase: SparkFun XBee 3 Wireless Kit Product Showcase: SparkFun XBee 3 Wireless Kit Part of what makes XBee so popular is its simplicity. XBees are controlled over a serial UART interface -- in the most basic operation they can be used as a wireless serial cable.
Page 3
We'll begin by examining the schematics and hardware of the XBee Shield, then move on to example code. First we'll set up a test program to make sure our XBees are communicating with each other. Then we'll move on to the remote control Arduino sketch.
Page 4
Suggested Reading Before reading through this tutorial, we highly recommend checking out the Exploring XBees and XCTU tutorial. Exploring XBees and XCTU MARCH 12, 2015 How to set up an XBee using your computer, the X-CTU software, and an XBee Explorer interface board.
Below we'll go more in-depth on the most important components of the shield. UART/Software Serial Switch One of the most important components on the XBee Shield is the DLINE/UART switch. This switch controls which Arduino pins interface with the XBee.
Page 6
"DLINE" position when uploading sketches. Status LED Indicators There are 5 LEDs on the XBee Shield. Each of these LEDs connects to a pin on the XBee, which does most of the LED driving. Here's a table explaining the operation of each LED:...
Page 7
(sending a stronger signal). Assembly Tips Before you can use the XBee Shield with your Arduino, you'll need to solder in some headers. Check out the assembly page of our Shield tutorial for all of the tips and tricks related to header installation.
Page 8
XBee Socket There is some white silkscreen on the Shield PCB to help orient your XBee as you're plugging it in. Make sure to match up the XBee's two diagonal edges with the two diagonal lines on the PCB. With everything installed, you're ready for the next step! Time to code... Example: Communication Test Note: This example assumes you are using the latest version of the Arduino IDE on your desktop.
Page 9
Exploring XBees and XCTU MARCH 12, 2015 How to set up an XBee using your computer, the X-CTU software, and an XBee Explorer interface board. This example assumes you have XCTU installed and two compatibly-configured XBees -- one connected to your computer via a USB Explorer (or Dongle, or Serial Explorer) and another plugged into the Shield/Arduino.
Page 10
/***************************************************************** XBee_Serial_Passthrough.ino Set up a software serial port to pass data between an XBee Shield and the serial monitor. Hardware Hookup: The XBee Shield makes all of the connections you'll need between Arduino and XBee. If you have the shield make sure the SWITCH IS IN THE "DLINE"...
Page 11
5V/16MHz, Pro Micro 3.3V/8Mhz, FioV3, etc.), you would need to re-define the software serial pin definitions, remove the solder jumpers for pin 3 & 2, and reroute the pins. For more information about the limitations, try looking at the Arduino reference language for the Software Serial library. ARDUINO SOFTWARE SERIAL LIBRARY Pin Definitions To use re-define the software serial pins on an Arduino Mega 2560 or Arduino Leonardo, you would just need...
Page 12
Warning for Users NOT Using the Arduino Serial Monitor! If you are using Digi's X-CTU or a serial terminal to configure or connect to an XBee by using a RedBoard/Arduino Uno as a serial passthrough, you may need to add a jumper wire between the RST and 5V pin to prevent the Arduino from resetting. Basically when the XCTU or serial terminal opens a COM port to the Arduino, computer resets the microcontroller while looking for the XBee.
Page 13
/***************************************************************** Leonardo_XBee_Serial_Passthrough.ino Set up a serial port to pass data between an XBee Shield and the serial monitor. Hardware Hookup: The XBee Shield makes all of the connections you'll need between Arduino and XBee. If you have the shield make sure the SWITCH IS IN THE "UART"...
Page 14
Example: Remote Control Arduino Setting up a chat system is fun, but where XBees and the XBee Shield really shine is in passing data to and from an Arduino, so you can remotely control it or receive data from it. In this example, we'll create a simple serial interface, which can be used to set and read analog and digital pins.
Page 15
Jim Lindblom @ SparkFun Electronics Original Creation Date: May 7, 2014 This sketch requires an XBee, XBee Shield and another XBee tied to your computer (via a USB Explorer). You can use XCTU's console, or another serial terminal program (even the serial monitor!), to send commands to the Arduino.
Page 16
// rate matches your XBee setting (9600 is default). XBee.begin(9600); printMenu(); // Print a helpful menu: void loop() // In loop() we continously check to see if a command has been received. if (XBee.available()) char c = XBee.read(); switch (c) case 'w': // If received 'w' case 'W':...
Page 17
pin = ASCIItoInt(pin); // Convert ASCCI to a 0-13 value pinMode(pin, OUTPUT); // Set pin as an OUTPUT digitalWrite(pin, hl); // Write pin accordingly // Write Analog Pin // Send 'w' or 'W' to enter // Then send a pin # Use numbers for 0-9, and hex (a, b, c, or d) for 10-13 (it's not smart enough (but it could be) to error on a non-analog output pin)
Page 18
// Read Analog Pin // Send 'a' or 'A' to enter // Then send an analog pin # to be read. // The Arduino will print the analog reading of the pin to XBee. void readAPin() while (XBee.available() < 1) ;...
Page 19
// Everything is "F()"'d -- which stores the strings in flash. // That'll free up SRAM for more importanat stuff. XBee.println(); XBee.println(F("Arduino XBee Remote Control!")); XBee.println(F("============================")); XBee.println(F("Usage: ")); XBee.println(F("w#nnn - analog WRITE pin # to nnn")); XBee.println(F(" e.g. w6088 - write pin 6 to 88")); XBee.println(F("d#v - digital WRITE pin # to v"));...
Page 20
GitHub Repo -- This is where you'll find the latest PCB design files. With XBee and the XBee Shield you have all of the tools necessary to take your project to the airwaves. What are you going to make? Need some inspiration? Check out these related tutorials: XBee WiFi Hookup Guide -- Take the next step with XBees, using the XBee WiFi.
Page 21
Experiment Guide for RedBot with Shadow Chassis This Experiment Guide offers nine experiments to get you started with the SparkFun RedBot. This guide is designed for those who are familiar with our SparkFun Inventor's Kit and want to take their robotics knowledge...
Need help?
Do you have a question about the XBee Shield and is the answer not in the manual?
Questions and answers