Introduction
XBee modems are one of the easiest ways to create a wireless point-to-point or mesh network. They have error correction, are configured with AT commands, come in multiple flavors and can create a wireless serial link out of the box.
Other Good things
- Low power for long battery life - <50 mA when working hard, <10 uA when sleeping
- 9 input/output lines for analog and digital IO
- Addressing—65,000 network addresses for each of 16 address channels - you can have LOTS of these boards in a network if you want
- Cheap (sort of)
- Wireless
- Easy serial interface
- Small
- Standardized
XBee Modules
You need a pair (or more) XBee modules - one for each of the devices you want to communicate between.There are two options for the modules - the normal version and the Pro version.
normal | Pro |
---|---|
The normal version, the Digi’s XBee 802.15.4 Wireless Modules (formerly called XBee Series 1), has a range of 100 feet indoors, and 300 feet outdoors (clear line of sight). | The Pro version has a range of 300 feet indoors, and 1 mile outdoors (clear line of sight). |
The Pro version consumes a bit more power than the normal version. |
Where to find them
- XBee (normal) module - around $19, part # XB24-AWI-001-ND at www.digikey.com
- XBee Pro module - around $32, part # XBP24-AWI-001-ND at www.digikey.com
LadyAda's breakout board
- On board 3.3V regulator to cleanly power your XBee, up to 250mA
- Level shifting circuitry means that its trivial to connect it to 5V circuitry such as an Arduino without risk of damage
- Two LEDs, one for activity (RSSI), the other for power (Associate)
- 10-pin 2mm sockets included to protect the modem and allow easy swapping, upgrading or recycling
- All the commonly used pins are brought out along the edge, making it easy to breadboard or wire up
- For use with any XBee/Pro pin-compatible module (check your module datasheet to verify power needs)
- Specifically created for use with an FTDI cable to connect to a computer via USB. This means that you can use, configure or upgrade the adapter painlessly simply by plugging in a cable.
- 3V pin - this is either an input power pin (if 5V is not provided) or an output from the 250mA regulator if 5V is provided
- DTR - "Data terminal ready" this is a flow control pin used to tell the XBee that the microcontroller or computer host is ready to communicate.
- RST - this pin can be used to reset the XBee. By default it is pulled high by the 10K resistor under the module. To reset, pull this pin low.'
- Ground - common ground for power and signal
- CTS - "Clear to Send" this is a flow control pin that can be used to determine if there is data in the XBee input buffer ready to be read
- 5V - this is the power input pin into the 3.3V regulator. Provide up to 6V that will be linearly converted into 3.3V
- RX - This is the XBee's serial recieve pin. Serial data is sent on this pin into the XBee to be transmitted wirelessly
- TX - This it the XBee's serial transmit pin. Serial data is sent on this pin out of the XBee, after it has been transmitted wirelessly from another module
- 0 RTS - "Ready to Send" this is a flow control pin that can be used to tell the XBee to signal that the computer or microcontroller needs a break from reading serial data.
- see pin #1
By far the easiest way to connect to a computer is to use an FTDI cable - use either 3.3V or 5V. These cables have a USB to serial converter chip molded into them and are supported by every OS. Thus configuring or upgrading or connecting is really trivial. Simply plug the cable into the end of the module so that the black wire lines up with GND. There is a white outline showing where the cable connects.
Make one now: LadyAda's breakout board
Talking to XBee
Once you have the XBee connected to a computer, you can experiment with connecting, configuring and upgrading the modules to the latest firmware.
- With the FTDI cable, connect the module to your computer.
If the module has correct power, the green LED should be blinking.
If it isn't, check the wiring and verify that the XBee is getting power.
- Plug in the FTDI
cable to your XBee on the breakout board.
Open CoolTerm.app - Click on the Option Button
- Click on the Re-scan Serial Ports button until the usbserial shows up
- You want to configure for 9600 bps, 8 bit, No parity, 1 s
top bit and no flow control. Also check the Local Echo checkbox
-
Now type in +++ (three plus signs) in quick succession.
If the XBee is connected up properly you will get an OK in response
- If you got an OK that means the XBee is powered and wired up
correctly! If its not working, check:
- Try again, be sure to wait 10 seconds between each attempt at typing in +++ and type the +'s quickly
- Is the module powered? Green LED should be blinking
- Are RX & TX swapped?
- Do you have the correct baud rate? By default it should be 9600 baud 8 None 1, but if it has been used for something else the baud rate might be different.
- Try again, be sure to wait 10 seconds between each attempt at typing in +++ and type the +'s quickly
-
Next try typing inWhen you receive OK type
+++
and press return. You should get another OK .AT
This is basically how you can configure the XBee, by sending it AT commands (they all start with AT for ATtention). After a while, the XBee times out of configuration mode and goes back to pass-through connection mode. So if you want to get back to config mode, just type in +++ and it will start responding again. - You can change the baud rate using the ATBD command with a number afterwards that selects which baud rate to use:
- 0 = 1200
- 1 = 2400
- 2 = 4800
- 3 = 9600
- 4 = 19200
- 5 = 38400
- 6 = 57600
- 7 = 115200
+++ (get into AT mode) <- OK AT (check if XBee modem is responding) <- OK ATBD (get current baud rate as above) <- 3 (9600) ATBD 4 (set baud rate to 19200) <- OK ATBD (check again) <- 4 ATWR (write the baud rate change to flash) <- OK
- Reset the module, either by pulling the reset pin low for a second or removing power (unplugging cable, etc) To connect now, set the terminal to use 19200 baud, otherwise the module will not respond! You can set it back to 9600 baud by giving it the command ATBD 3 and then ATWRiting it to the flash
AT commands
How to write an AT Commands
AT+ASCII+ SPACE+ parameter(hex)
AT->OK ATMY ->my address ATDH.ATDL ->destination address hi/of-destination of ATID->personal area network ID ATCN->end command mode ATD0..D8->set pins ATDX0-disabled ATDX1-undefied ATDX2-analog input ATDX3-digital input ATDX4-digital output low ATDX5-digital output high ATIR->sets sample rate in milliseconds -sampling local pin (10times per second) 0x14 ATIT->how many samples to collect ATP0-P1->PWM configuration ATPX ATIU->1/o input enable (UART) ATAI->I/O input address-what address do I want to pay attention to? who do I want to be paired with
Each radio needs an address of its own. Need your own personal area network panid
example:
ATMY7 (number for this XBee)
ATDL8-who you are talking to
/ /Computer Chat
Parts
- 2 XBee 802.15.4 Radios
- 2 XBee Adapters
- 2 Two computers
- Configure the Radio:
- Mark the first XBee you’re going to work on with an A.
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Open CoolTerm and click Options
- Choose the serial port that starts with usbserial… If you’re not sure which serial port to select, look at the list of available ports and then disconnect the XBee Explorer from your computer. Click Re-Scan Serial Ports and check which serial port disappeared. Reconnect your XBee, click Re-Scan Serial Ports and choose that port.
- Be sure Baudrate is set to 9600.
- Be sure Data Bits is set to 8.
- Be sure Parity is set to none.
- Be sure Stop Bits is set to 1.
- In the list on the left side of the options window, click Terminal.
- Enable Local Echo. This will allow you to see what you’re typing into the terminal.
- Click OK to save those settings and close the Options window.
- Click Connect on the toolbar.
- You should see Connected on the status bar at the bottom of the window.
- Type +++ to enter command mode. You should see the reply OK.
- Here’s a chart of the commands settings to set
Function Command Parameter PAN ID ATID 3001 (any address from 0 to FFFE will do) MY Address ATMY 1 Destination address high ATDH 0 (indicates a 16-bit address) Destination address low ATDL 2 - Type in each command followed by its parameter and hit enter.
- You can verify the setting by typing the command without a parameter.
- Type ATWR to save the settings.
- Click disconnect in CoolTerm and remove the XBee A
- Mark the first XBee you’re going to work on with an A.
- Configure the Second Radio:
- Mark the first XBee you’re going to work on with an B.
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Open CoolTerm and click Options
- Choose the serial port that starts with usbserial… If you’re not sure which serial port to select, look at the list of available ports and then disconnect the XBee Explorer from your computer. Click Re-Scan Serial Ports and check which serial port disappeared. Reconnect your XBee, click Re-Scan Serial Ports and choose that port.
- Be sure Baudrate is set to 9600.
- Be sure Data Bits is set to 8.
- Be sure Parity is set to none.
- Be sure Stop Bits is set to 1.
- In the list on the left side of the options window, click Terminal.
- Enable Local Echo. This will allow you to see what you’re typing into the terminal.
- Click OK to save those settings and close the Options window.
- Click Connect on the toolbar.
- You should see Connected on the status bar at the bottom of the window.
- Type +++ to enter command mode. You should see the reply OK.
- Here’s a chart of the commands settings to set
Function Command Parameter PAN ID ATID 3001 (any address from 0 to FFFE will do) MY Address ATMY 2 Destination address high ATDH 0 (indicates a 16-bit address) Destination address low ATDL 1 - Type in each command followed by its parameter and hit enter.
- You can verify the setting by typing the command without a parameter.
- Type ATWR to save the settings.
- Mark the first XBee you’re going to work on with an B.
- Connect A to a different computer.
- Open CoolTerm and connect to it as outlined in the previous steps.
If you’re still in command mode on either module, you can type ATCN to get out of command mode without waiting for the 10 second timeout.
- If everything is set up properly, the text that you type in the serial terminal program on the first computer will be relayed to the second computer and appear on its serial terminal screen as well.
- See how far apart the modules can go before you lose the connection.
- The 802.15.4 protocol not only allows for point-to-point communication, but it also allows for point-to-multipoint communication. If you have more than two XBees, set them all to the same PAN ID (with ATID) and then set the destination low address on the broadcaster to FFFF (with ATDL FFFF). Now, when you type into the broadcaster’s terminal, you should see the text appear on all the other terminals.
/ /Sensing Data
Photocells let you sense and take action based on the amount of light hitting the cell. The resistance across the two leads of the cell varies according to the amount of light hitting the cell. The more light that hits the cell, the less the resistance is. Less light means greater resistance. You are going to use the XBee 802.15.4 radio’s analog-to-digital converter (ADC) to send various light levels out into the airwaves as digital data.
Parts
- XBee 802.15.4 Radio
- Photocell
- 1 1-10 KResistor
- Breadboard
- Jumper cables
- XBee Breakout Board
- XBee Adapter
- A DC power source, 2.8 – 3.3V
- Configure the Radio:
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Open CoolTerm and click Options
- Choose the serial port that starts with usbserial… If you’re not sure which serial port to select, look at the list of available ports and then disconnect the XBee Explorer from your computer. Click Re-Scan Serial Ports and check which serial port disappeared. Reconnect your XBee, click Re-Scan Serial Ports and choose that port.
- Be sure Baudrate is set to 9600.
- Be sure Data Bits is set to 8.
- Be sure Parity is set to none.
- Be sure Stop Bits is set to 1.
- In the list on the left side of the options window, click Terminal.
- Enable Local Echo. This will allow you to see what you’re typing into the terminal.
- Click OK to save those settings and close the Options window.
- Click Connect on the toolbar.
- You should see Connected on the status bar at the bottom of the window.
- Type +++ to enter command mode. You should see the reply OK.
- Here’s a chart of the commands settings to set
Function Command Parameter Reset ATRE N/A (resets the radio to its factory settings) PAN ID ATID 3001 (any address from 0 to FFFE will do) MY Address ATMY 1 Destination address high ATDH 0 (indicates a 16-bit address) Destination address low ATDL 2 (the address of the receiving radio) Pin 0 I/O Configuration ATD0 2 (analog input) Sample Rate ATIR 14 (20 ms, 14 in hexadecimal = 20 in decimal) Write to memory ATWR N/A (save the settings to flash memory) - Type in each command followed by its parameter and hit enter.
- You can verify the setting by typing the command without a parameter.
- Type ATWR to save the settings.
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Wire up the circuit:
- Place the XBee adapter into the breadboard and wire up the power buses to each other.
- Connect the VCC terminal of the XBee adapter to the positive rail and the ground terminal to the negative rail.
- Connect the VREF terminal of the XBee adapter to the positive rail. This will give the XBee a reference for what voltage an analog sensor is working with.
- Connect one lead of the photocell to the positive voltage rail, and the other lead to pin 20 of the XBee. It doesn’t matter which sides of the photocell you choose, it’s not polarized. Place the resistor between ground and the photocell lead that connects to the XBee. This creates a simple voltage divider circuit.
- This is what the voltage divider looks like as a schematic diagram.
- Here’s how your circuit might look as laid out on a breadboard.
- Insert the XBee into the breakout board and connect the battery pack.
- Place the XBee adapter into the breadboard and wire up the power buses to each other.
- test it out
Buttons
XBee radios can be configured for up to 8 digital input pins that can directly control the output pins on a second radio. In this tutorial, you'll see how to program the radio and wire up a simple button to an XBee so that you can use it to make your digital electronics project wireless.
Parts
- XBee 802.15.4 Radio
- Switch
- 10K resistor
- Breadboard
- Jumper cables
- XBee Breakout Board
- XBee Explorer USB
- A DC power source, 2.8 – 3.3V
- Configure the Radio:
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Open CoolTerm and click Options
- Choose the serial port that starts with usbserial… If you’re not sure which serial port to select, look at the list of available ports and then disconnect the XBee Explorer from your computer. Click Re-Scan Serial Ports and check which serial port disappeared. Reconnect your XBee, click Re-Scan Serial Ports and choose that port.
- Be sure Baudrate is set to 9600.
- Be sure Data Bits is set to 8.
- Be sure Parity is set to none.
- Be sure Stop Bits is set to 1.
- In the list on the left side of the options window, click Terminal.
- Enable Local Echo. This will allow you to see what you’re typing into the terminal.
- Click OK to save those settings and close the Options window.
- Click Connect on the toolbar.
- You should see Connected on the status bar at the bottom of the window.
- Type +++ to enter command mode. You should see the reply OK.
- Here’s a chart of the commands settings to set
Function Command Parameter Reset ATRE N/A (resets the radio to its factory settings) PAN ID ATID 3001 (any address from 0 to FFFE will do) MY Address ATMY 1 Destination address high ATDH 0 (indicates a 16-bit address) Destination address low ATDL 2 (the address of the receiving radio) Pin 0 I/O configuration ATD0 3 (digital input) Sample rate ATIR 14 (20 ms, 14 in hexadecimal = 20 in decimal) Pull-up resistors ATPR 0 (disable internal pull-up resistors on all pins) Write to memory ATWR N/A (save the settings to flash memory)
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Wire the circuit:
- Place the XBee adapter into the breadboard and wire up the power buses to each other.
- Connect the VCC terminal of the XBee adapter to the positive rail and the ground terminal to the negative rail.
- One side of the switch gets connected to I/O pin 0, which is physical pin 20, on the top right side of the XBee. The other side of the switch gets connected to the positive bus.
- Add a 10K resistor between the negative power bus and the side of the switch that connects to the XBee. This acts as a pull down resistor. Since digital inputs must be connected to either high or low levels, it ensures the input is connected to ground (low) when the switch is not being pushed.
- Insert the XBee into the adapter.
- Connect the battery pack.
- Diagram of the circuit
- Place the XBee adapter into the breadboard and wire up the power buses to each other.
- Test the circuit
/ /Output
XBee radios can be configured for up to 8 digital output pins that can be directly controlled by input pins on a second radio. In this tutorial, you'll learn how to blink an LED wirelessly.
Parts
- XBee 802.15.4 Radio
- LED
- Breadboard
- Jumper cables
- XBee Breakout Board
- XBee Adapter
- A DC power source, 2.8 – 3.3V
- Configure the Radio:
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Open CoolTerm and click Options
- Choose the serial port that starts with usbserial… If you’re not sure which serial port to select, look at the list of available ports and then disconnect the XBee Explorer from your computer. Click Re-Scan Serial Ports and check which serial port disappeared. Reconnect your XBee, click Re-Scan Serial Ports and choose that port.
- Be sure Baudrate is set to 9600.
- Be sure Data Bits is set to 8.
- Be sure Parity is set to none.
- Be sure Stop Bits is set to 1.
- In the list on the left side of the options window, click Terminal.
- Enable Local Echo. This will allow you to see what you’re typing into the terminal.
- Click OK to save those settings and close the Options window.
- Click Connect on the toolbar.
- You should see Connected on the status bar at the bottom of the window.
- Type +++ to enter command mode. You should see the reply OK.
- Here’s a chart of the commands settings to set
Function Command Parameter Reset ATRE N/A (resets the radio to its factory settings) PAN ID ATID 3001 (any address from 0 to FFFE will do) MY Address ATMY 2 Pin 0 I/O configuration ATD0 5 (digital output, HIGH on startup) I/O input address ATIA 1 (address of the transmitting radio) Write to memory ATWR N/A (save the settings to flash memory)
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Wire the circuit:
- Place the XBee adapter into the breadboard and wire up the power buses to each other.
- Connect the VCC terminal of the XBee adapter to the positive rail and the ground terminal to the negative rail.
- Connect the anode lead of the LED (the longer wire) to I/O pin 0, which is physical pin 20, on the top right side of the XBee. The cathode lead (the shorter wire) gets connected to the ground bus.
- Insert the XBee into the adapter.
- Connect the battery pack. Since we set the I/O mode of the pin to be HIGH on start up with the command ATD0 5, the LED will illuminate as long as there’s no radio configured to transmit a low signal to our receiving radio. If you'd like the LED to be off on startup, you can use the command ATD0 4
- Here is the Fritzing :
- Place the XBee adapter into the breadboard and wire up the power buses to each other.
- Test the circuit
- Use a photocell to turn on the LED
/ /PWM
In the potentiometer tutorial, you used the XBee's built-in analog-to-digital converter (ADC) to convert the analog voltage values from a potentiometer to digital information that the XBee could transmit. Like the Arduino, the XBee has the ability to use PWM.
PWM, or pulse-width modulation, is a way for digital devices to emulate an analog signal using a digital to analog converter (DAC). They do this by switching the pin between high and low with different duty cycles. A full 3.3 volts from the XBee will have a 100% duty cycle. That is to say, the PWM output pin will always be high. If you want something half-way between off and on, 1.65 volts, the DAC will keep the pin high for 50% of the time and low for the remaining 50%. This happens so fast—about 16,000 times per second.
XBee radios have two PWM outputs. You are going to connect an LED to one of the PWM outputs to control the brightness of the LED wirelessly.
Parts
- XBee 802.15.4 Radio
- LED
- Breadboard
- Jumper cables
- XBee Breakout Board
- XBee Adapter.
- A DC power source, 2.8 – 3.3V
- Configure the Radio:
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Open CoolTerm and click Options
- Choose the serial port that starts with usbserial… If you’re not sure which serial port to select, look at the list of available ports and then disconnect the XBee Explorer from your computer. Click Re-Scan Serial Ports and check which serial port disappeared. Reconnect your XBee, click Re-Scan Serial Ports and choose that port.
- Be sure Baudrate is set to 9600.
- Be sure Data Bits is set to 8.
- Be sure Parity is set to none.
- Be sure Stop Bits is set to 1.
- In the list on the left side of the options window, click Terminal.
- Enable Local Echo. This will allow you to see what you’re typing into the terminal.
- Click OK to save those settings and close the Options window.
- Click Connect on the toolbar.
- You should see Connected on the status bar at the bottom of the window.
- Type +++ to enter command mode. You should see the reply OK.
- Here’s a chart of the commands settings to set
Function Command Parameter Reset ATRE N/A (resets the radio to its factory settings) PAN ID ATID 3001 (any address from 0 to FFFE will do) MY Address ATMY 2 PWM Pin 0 Configuration ATP0 2 (PWM output) I/O input address ATIA 1 (address of the transmitting radio) Write to memory ATWR N/A (save the settings to flash memory)
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Wire the circuit:
- Place the XBee adapter into the breadboard.
- Connect the VCC terminal of the XBee adapter to the positive rail and the ground terminal to the negative rail.
- Connect the LED’s cathode side (the shorter lead) to the ground bus and the anode side (the longer lead) to the PWM0 pin, which is the 6th pin down on the left side.
- Insert the XBee into the breakout board.
- Your circuit should look something like the diagram
- Connect the battery
- Place the XBee adapter into the breadboard.
- Test the circuit
- Use a photocell to control an LED. Make sure the transmitter's address is set as the receiver's I/O input address setting (ATIA).
PWM
FSRs
Force sensitive resistors (FSRs) can sense how hard a user is pressing down because the resistance across the two leads on the sensor varies based on how much pressure is on the pad. With no pressure, there's no continuity between the two leads. When you push softly, a connection is made between the two leads with some resistance. As you push harder, the resistance drops.
By connecting an FSR to one of the two analog inputs on an XBee, you can create a wireless force sensor.
Parts
- XBee 802.15.4 Radio
- Force sensitive resistor
- Resistor – The resistance will depend on your FSR (it should be on the same order of magnitude as the resistance on your FSR).
- Breadboard
- Jumper cables
- XBee Breakout Board
- XBee Explorer USB
- A DC power source, 2.8 – 3.3V
- Configure the Radio:
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Open CoolTerm and click Options
- Choose the serial port that starts with usbserial… If you’re not sure which serial port to select, look at the list of available ports and then disconnect the XBee Explorer from your computer. Click Re-Scan Serial Ports and check which serial port disappeared. Reconnect your XBee, click Re-Scan Serial Ports and choose that port.
- Be sure Baudrate is set to 9600.
- Be sure Data Bits is set to 8.
- Be sure Parity is set to none.
- Be sure Stop Bits is set to 1.
- In the list on the left side of the options window, click Terminal.
- Enable Local Echo. This will allow you to see what you’re typing into the terminal.
- Click OK to save those settings and close the Options window.
- Click Connect on the toolbar.
- You should see Connected on the status bar at the bottom of the window.
- Type +++ to enter command mode. You should see the reply OK.
- Here’s a chart of the commands settings to set
Function Command Parameter Reset ATRE N/A (resets the radio to its factory settings) PAN ID ATID 3001 (any address from 0 to FFFE will do) MY Address ATMY 1 Destination address high ATDH 0 (indicates a 16-bit address) Destination address low ATDL 2 (the address of the receiving radio) Pin 0 I/O Configuration ATD0 2 (analog input) Sample Rate ATIR 14 (20 ms, 14 in hexadecimal = 20 in decimal) Write to memory ATWR N/A (save the settings to flash memory)
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Wire the circuit:
- Place the XBee adapter into the breadboard and wire up the power buses to each other.
- Connect the VCC terminal of the XBee adapter to the positive rail and the ground terminal to the negative rail.
- Connect the VREF terminal of the XBee adapter to the positive rail. This will give the XBee a reference for what voltage an analog sensor is working with.
- Connect one lead of the FSR to the positive voltage rail, and the other lead to pin 20 of the XBee. It doesn’t matter which sides of the FSR you choose, it’s not polarized. Place the resistor between ground and the FSR lead that connects to the XBee. This creates a simple voltage divider circuit.
- Voltage divider
- Circuit
- Insert the XBee into the breakout board and connect the battery pack.
- Place the XBee adapter into the breadboard and wire up the power buses to each other.
- Test the circuit
- Control the dimming of an LED with an FSR
/ /Adding a Joystick
You can use XBees and joysticks to create wireless controllers.
Parts
- XBee 802.15.4 Radio
- Joystick
- Male headers
- Breadboard
- Jumper wires
- XBee Breakout Board
- XBee Adapter
- A DC power source, 2.8 – 3.4V
- Configure the Radio:
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Open CoolTerm and click Options
- Choose the serial port that starts with usbserial… If you’re not sure which serial port to select, look at the list of available ports and then disconnect the XBee Explorer from your computer. Click Re-Scan Serial Ports and check which serial port disappeared. Reconnect your XBee, click Re-Scan Serial Ports and choose that port.
- Be sure Baudrate is set to 9600.
- Be sure Data Bits is set to 8.
- Be sure Parity is set to none.
- Be sure Stop Bits is set to 1.
- In the list on the left side of the options window, click Terminal.
- Enable Local Echo. This will allow you to see what you’re typing into the terminal.
- Click OK to save those settings and close the Options window.
- Click Connect on the toolbar.
- You should see Connected on the status bar at the bottom of the window.
- Type +++ to enter command mode. You should see the reply OK.
- Here’s a chart of the commands settings to set
Function Command Parameter Reset ATRE N/A (resets the radio to its factory settings) PAN ID ATID 3001 (any address from 0 to FFFE will do) MY Address ATMY 1 Destination address high ATDH 0 (indicates a 16-bit address) Destination address low ATDL 2 (the address of the receiving radio) Pin 0 I/O configuration ATD0 3 (digital input) Pin 1 I/O configuration ATD1 3 (digital input) Pin 2 I/O configuration ATD2 3 (digital input) Pin 3 I/O configuration ATD3 3 (digital input) Change detection ATIC F (bitmap field: first four inputs send samples on change, SEE BELOW for more information) Write to memory ATWR N/A (save the settings to flash memory)
- Insert the XBee into the Adapter and connect it to your computer with a USB cable.
- Wire the circuit:
- Place the XBee adapter into the breadboard and wire up the power buses to each other. Next, connect the VCC terminal of the XBee adapter to the positive rail and the ground terminal to the negative rail.
-
The joystick is really a set of four switches that all share a common ground. To make it easier to connect them to a breadboard, you can solder male header pins onto each. We kept the common wire (typically the black one) separate so that it could be connected directly to the negative power rail.
-
Connect the common wire to the ground power rail. Connect the remaining joystick switch wires to XBee input pins D0, D1, D2 and D3 (physical pins 20, 19, 18 and 17 on the right-hand side of the XBee).
-
We made it easier to attach the battery holder to the breadboard by soldering some male headers onto its positive and negative wiring leads.
-
Connect the battery pack directly to the ground and power rails.
-
Insert your configured XBee into the breadboard adapter.
breadboard layout of the circuit along with a schematic.
- Place the XBee adapter into the breadboard and wire up the power buses to each other. Next, connect the VCC terminal of the XBee adapter to the positive rail and the ground terminal to the negative rail.
- Test the circuit
- Add leds: Joystick and LEDs
/ /Telephone Game
Parts
- Arduino
- Protoshield
- LED
- 220Ω resistor
- 10KΩ resistor
- Tactile button
Radio Setting Chart
Radio | MY | DL |
---|---|---|
Radio 1 | MY1 | DL2 |
Radio 2 | MY2 | DL3 |
Radio 3 | MY3 | DL4 |
Radio 4 | MY4 | DL5 |
Radio 5 | MY5 | DL6 |
Radio 6 | MY6 | DL1 |
The most basic way to communicate using the XBee modems is point to point. That means one modem communicating with another modem. Serial data goes in one XBee, is transmitted wirelessly, and goes out the other & vice versa.
Since you all have XBees, you need a way to set the the network ID (otherwise known as the PAN - Personal Area Nework - ID) to a common value. By default all XBee's use PAN ID #3332. The ID is 4 bytes of hexadecimal and can range from 0x0000 to 0xFFFF.
Changing the PAN is easy.
- Plug in the FTDI
cable to your XBee on the breakout board.
Open CoolTerm.app - Click on the Option Button
- Click on the Re-scan Serial Ports button until the usbserial shows up
- You want to configure for
- 9600 bps
- 8 bit
- No parity
- 1 stop bit
- no flow control
- Start by first resetting your XBEE. Type ATRE.
- Next set the PAN ID. The PAN ID numbers need to be the same for the modems to talk to each other.
- Set the baud rate to 9600.You can change the baud rate using the ATBD command with a number afterwards that selects which baud rate to use:
- 0 = 1200
- 1 = 2400
- 2 = 4800
- 3 = 9600
- 4 = 19200
- 5 = 38400
- 6 = 57600
- 7 = 115200
- Set your MY numbers according to the chart and what you were assigned.
- Set your DL numbers according to the chart and what you were assigned.
- Connect your XBee to the Arduino. Connect +3.3V and Ground to provide power.
- Wire up an led and a pulldown button to your Arduino. Use any of the digital pins greater than or equal to 4.
- In the picture below the Arduino uses a Software Serial program and pin #2 of the Arduino becomes the RX pin (INPUT) and pin #3 of the Arduino becomes the TX pin (OUTPUT). This allows you to use the default hardware USB serial port without conflicts.
If you're not using SoftwareSerial then do NOT plug the XBee into the RX and TX pins until after you have programmed the microcontroller. When you have programmed your Arduino, connect the RX line (input) of the XBee to the TX line (output) of the microcontroller (1) and vice versa TX of XBee to RX of Arduino (0). - Open Arduino and upload this sketch:
#include <SoftwareSerial.h> SoftwareSerial mySerial(2, 3); int led=_; int btn=_; void setup(){ pinMode(led,OUTPUT); pinMode(btn,INPUT); mySerial.begin(9600); } void loop(){ if(digitalRead(btn)){ blinkLED(_); sendMsg(); } if (mySerial.available()>0) { if (mySerial.read()=='T') { blinkLED(_); sendMsg(); } } } void sendMsg(){ //print for next radio mySerial.print('T'); } void blinkLED(int times){ for(int i=0;i<times;i++){ digitalWrite(led,HIGH); delay(500); digitalWrite(led,LOW); delay500; } }
- Upload and test.
/ /Making Noise
Repeat the telephone game, but this time each Arduino should do something unique and preferably using some sort of mechanism. So make sound, move something, flash some lights, etc.
/ /Making Random Noise
This project is similar to the last project, but uses a library to dynamically assign the message to a random radio on the same network.
/ /Telephone Song
This assignment gets way more complicated. You need to do the following:
- Write a song
- Wire a circuit so that you interface the Arduino and XBee.
- When a switch is pressed on your circuit, send your song wirelessly to other XBee chips.
- When you receive a song from another radio, play their song and send yours on to another radio.
Every radio/arduino will send, receive, and play a song.
You will all need to follow the same protocol in order to communicate with each other.
Protocol:
-
Reset factory defaults
- Set the Baud rate to 9600
- Set the PAN (personal area network) ID to a number we've all agreed on
- Set the MY to some number between 1-number of students. Record this number here so we don't get duplicates.
- Set the DL to next radio.
#include <Tone.h> Tone ________; int count=0; int len; byte names[] ={'0','c', 'd', 'e', 'f', 'g', 'a', 'b', 'C','D','E','F','G','A','B'}; int notes[] = { 0, NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5, }; byte newSong[100]; byte noteDurations[100]; //compose song in array byte mySong[]={'c',1,'a',4,'g',2}; } void setup(){ ________.begin(__); Serial.begin(9600); } void loop(){ if(digitalRead(btn)){ doMyThing(); sendMsg(); } if(Serial.available()>1){ //did you get the start byte if(Serial.read()==255){ len=Serial.read(); while(Serial.available()<len){ //do nothing ; } //may need a timeout fn here for(int i=0;i<len/2;i++){ newSong[i]=Serial.read(); noteDurations[i]=Serial.read(); } doMyThing(); sendMsg(); } } } void doMyThing(){ for(int i=0;i<newSong.length;i++){ playTone(newSong[i], noteDurations[i]); } } void sendMsg(){ sendSong(); } void sendSong(){ //start byte Serial.print(255,BYTE); //send length Serial.print(mySong.length,BYTE); //iterate over your song and send each byte for(int i=0;i<mySong.length;i++){ Serial.print(mySong[i],BYTE); } } void playTone(byte n,byte d){ for (int i=0;i<=names.length;i++) { if (names[i] == n) { _______.play(tones[i]); // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000/d; delay(noteDuration); _______.stop(); int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); break; } } }
1-whole
2-half
4-quarter
8-eighth
16-sixteenth
Have fun writing a song that will be recognizable and distinctly your own. A minimum of 20 notes and at least one pause is required per song. No song can have a length greater than 100.
start | length | note 1 | note 2 | ~note 3 |
255 | n | c | d | E |
/ /Common Mistakes
Your XBee project isn’t working? Here’s some common mistakes that people make:
- Not using the latest firmware (especially if ATD0 or ATIR is giving an error)*
- No reference voltage to VREF pin on the 802.15.4 radios (analog and digital reads give wrong values)
- Forgetting that AT commands use hexadecimals
- Hitting return after +++ (or otherwise not respecting 1 second default guard time)
- Conversely, not hitting return after an AT command
- Letting the XBee time out of command mode before issuing an AT command (you’ll know because you get no response)
- Forgetting to write the configuration to firmware with ATWR (unless your application configures the radio interactively)
- Not using ATRE (restore factory defaults) before re-configuring a previously used radio (previous settings lurk unless you manually reset them all)
- Looking for analog output on the analog input pins instead of pins 6 and 7 (P0, P1)
- Using a voltage regulator without decoupling capacitors (10uF on input, 1uF on output is good)
- Mixing up TX and RX pins (fastest way to check this is switch the wires and see if it starts working)
- Using ZigBee version (ZB Pro or ZNet 2.5) when 802.15.4 version would do just fine (if you don’t need to make a mesh )
- Trying to read more than 1.2 Volts on the ZB Pro and ZNet 2.5 analog inputs (that’s the limit)
- Buying Pro radios when you don’t need them. (Cost more, bigger, use a lot more battery)
- Deciding the XBees are flaky. (You may not be using them correctly, but they are very reliable)
- Deciding an XBee is burned out when it’s set to a different baud rate (check ON and ASSC lights)
- Deciding an XBee is burned out when it is just sleeping (Check ON light to see if it blinks occasionally)
- Forgetting to supply power or ground (ON light may go on and ASSC light may blink but both will be significantly dimmer)
- Not contacting Digi sooner for support, especially if your radio seems dead or you keep getting an error you don’t understand.
- Sending continuously without any delay (try 10ms delay)
- Not removing RX and TX connections before uploading code (Arduino will give an error)
- Not removing RX connection when reseting, if you are continuously receiving data. (Arduino will never reset)
- Hooking up more than 4 Volts to the 3.3V pin
- Using switches without pull-down resistors (but not if you use the internal pull-ups)
- Not using a pull-up or pull-down resistor on pins 5 and 7 (these don’t have internal pull-ups at all)
- Using sensors without voltage divider resistors (if your sensor needs that circuit)
- Using too-resistive conductive thread for power and ground (try fabric or wires)