Teensy and XBee

In this article I am going to describe how to set up an RF wireless network with XBee modules and the Teensy USB development board.

Teensy is a fairly well documented and easy to use development board. In this example I am using Teensy 2.0. Two good things about Teensy are that it has an USB serial port and an additional serial port that supports UART. This way you can easily connect Teensy to the XBee module using serial connection and still be able to debug and communicate with Teensy using the USB serial port. Another good thing about Teensy is that you can use a simple hardware modification to make it run with 3.3V, which is the supply voltage for the XBee module.

you can follow these instructions to get started with Teensy and then follow this instruction to setup Teensyduino, which let you easily program Teensy using the Arduino platform and Arduino libraries.

There are two XBee operation modes, transparent operation and API operation. Transparent Operation is easier to get started with, it acts as a replacement of the serial communication. You set a fix destination address, this means that this XBee modul will only talk to the XBee module in its network that has this specific destination address as my address. You can also broadcast to every module in the network by setting the destination address to ffff.  When the module receives an RF packet, the data is sent out the DO pin with no additional information. API operation requires that communication with the module be done through a structured interface. Using API operation you are able to transmit data to multiple destinations without entering Command mode, get receive success and failure status, and identify the source address of the received package. The different package structures can be found in the data sheet 3.4.1 API Frame Specifications. We are using Series 1 XBee modules.

XBee Seris 1 datasheet

Connect Teensy to the XBee module

  1.  Connect Teensy ground pin (GND) to XBee module ground pin (pin 10)
  2.  XBee supply voltage is 2.1 – 3.6 V! Use these instructions to change Teensy’s operation voltage to 3.3V. Connect Teensy supply power pin (VCC) to XBee module power pin (pin 1)
  3.  Connect Teensy RX pin (pin 7) to XBee module DOUT pin (pin 2)
  4.  Connect Teensy TX pin (pin 8 ) to XBee module DIN pin (pin 3)
  5. optional: connect XBee module RSSI PWM pin (pin 6) to a digital input pin on Teensy for example D1 (pin 6)

Transparent Operation 

Program the XBee module

The easiest way to program the XBee module is to use  a XBee Explorer  and X-CTU or a serial terminal program like Tera Term, HyperTerminal for Windows and CoolTerm, Zterm for Mac.

X-CTU

  1. in the tab PC Settings select the Com Port that your XBee is connected to and click Test / Query. Continue if the test is successful.
  2. click Restore to reset the parameters
  3. in the tab Modem Configuration click Read.
  4. set PAN ID for example to 3002. Every Xbee module in your network need to have the same PAN ID in order to communicate to each other.
  5. set My address to a unique address for each module
  6. set Destination address high to 0 (we use 16bit address)
  7. set Destination address low to any unique My address of a different module that this module wants to talk to or to ffff if you want this module to broadcast to every other module in the network

Serial Terminal Program

if you use a serial terminal program you can use the AT commands to configure the XBee module

  1. send +++ to enter command mode, you should receive OK
  2. sent ATID 3002 to set PAN ID to 3002, you should receive OK
  3. send ATID, you should receive the current pan ID 3002
  4. send ATMY 1 to set your My address to 1, you should receive OK
  5. send ATMY, you should receive your current My address 1
  6. send ATDH 0 to set Destination address high to 0 (we use 16bit address), you should receive OK
  7. send ATDL 2 to set you Destination address low to 2 (send ATDL ffff to broadcast), you should receive OK
  8. send ATDL, you should receive you current Destination address low 2

Teensyduino program

use the Teensy USBtoSerial Example (file->examples->teensy->USB_Serial->USBtoSerial)  to test the wireless connection. Upload the program on to your Teensy board using USB connection to your computer. You need two Teensy boards, two XBee modules and two computers OR one Teensy board, two XBee module, one XBee Explorer and one computer to test the wireless communication. In the first case use the Serial Monitor in Arduino to send and receive  messages. In the second case use Arduino and for example X-CTU (Terminal tab) to communicate.

Read RSSI pin 

If you are interested in the signal strength of the received radio signal  (measured in –dBm), which is a indicator for the distance of the radio modules you can read the RSSI PWM pin that we connected to D1 on the Teensy board. The RSSI is encoded as the pulse width of the RSSI PWM signal.  The RSSI PWM runs at 15.625 khz and has 445 total counts.

dB above Sensitivity             PWM percentage (high period / total period)
10                                                  41%
20                                                 58%
30                                                 75%

  1. enable RSSI/PWM by setting P0 to 1 (send command ATP0 1 and apply changes send ATAC or use x-CTU, it is enabled by default)
  2. The duration of the signal is  determined using the RP command (send ATRP 14 (set timer to 2 seconds) and apply changes ATAC or use x-CTU)
  3. use Adruino function pulseIn to read RSSI pulse width: rssi_counts= pulseIn(rssi_pin, HIGH)
It is also useful to connect the RSSI PWM pin to a LED to create a visual feedback for received package. Connect the pin to a resistor and a led in series and connect the other end to ground similar to this Arduino setup.

API Operation

Program the XBee module

To program the XBee module follow similar steps described in transparent operation. The easiest way to program the XBee module is to use  a XBee Explorer  and X-CTU or a serial terminal program like Tera Term, HyperTerminal for Windows and CoolTerm, Zterm for Mac.

X-CTU

  1. in the tab PC Settings select the Com Port that your XBee is connected to and Test / Query. Continue if the test is successful.
  2. click Restore to reset the parameters
  3. in the tab Modem Configuration click Read.
  4. set PAN ID for example to 3002. Every Xbee module in your network need to have the same PAN ID in order to communicate to each other.
  5. set My address to a unique address for each module
  6. set Destination address high to 0 (we use 16bit address)
  7. set Destination address low to ffff
  8. DIFFERENT than transparent operation: set AP to 1 API enabled

Serial Terminal Program

if you use a serial terminal program you can use the AT commands to configure the XBee module

  1. send +++ to enter command mode, you should receive OK
  2. sent ATID 3002 to set PAN ID to 3002, you should receive OK
  3. send ATMY 1 to set your My address to 1, you should receive OK
  4. send ATDH 0 to set Destination address high to 0 (we use 16bit address), you should receive OK
  5. send ATDL ffff to set you Destination address low, you should receive OK
  6. DIFFERENT than transparent operation: send ATAP 1 to enable API and send ATAC to apply changes

Teensyduino program

Fortunately there is a Aduino library that you can use to communicate in API operation mode. You could use two Teensy boards, two XBee modules and two computers to do a quick test. Upload Series1_rx Example (file->examples->xbee->Series1_rx)  to one Teensy board (how to upload the program). Upload the Series_tx Example (file->examples->xbee->Series1_tx) to the other Teensy board. Instead of using the LED for debugging you could use Serial.print() and Serial Monitor to print status messages.  Now you can use rx16.Rssi() to get the signal strength indicator.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s