XBee 802.15.4 to PC Demo [P8X32A]

posted in: Tutorials 0

The XBee 802.15.4 to PC Demo provides an example of communication between any Series 1 XBee Module and the PC, using the XStick 802.15.4 (Parallax #28186, discontinued). This demo is a modified version of the RN-42 Bluetooth to PC Demo using the same components except the radio transceiver. The RN-42 to PC project is also included in the download zip for this project.

The demo provides a two-way communication channel for a remote device which has two functions: one is to send system telemetry from on-board sensors, the other is to receive and act upon known commands from a remote serial terminal or command interface; in this case a PC.

While this demo application is small, it represents a scalable real-world application where you might be receiving weather or sensor telemetry from a farm or industrial control system and need to be able to then send commands to such a system, perhaps to open or close a valve in response to data received.

What’s Required:
  • (1) Propeller Board of Education (#32900, discontinued)
  • (1) Any Series 1 XBee Module (#32405 used in this demo, discontinued)
  • (1) XStick 802.15.4 (#28186, discontinued)
  • (1) ADC0831 8-bit A/D Converter (#ADC0831)
  • (1) DS1620 Digital Thermometer (#604-00002, discontinued)
  • (1) PING))) Ultrasonic Sensor + Mounting Bracket (#910-28015A)
  • (1) Photoresistor (#350-00009, discontinued)
  • (1) 10K, 1/4W Resistor (#150-01030)
  • (1) 4.7K, 1/4W Resistor (#150-04720)
  • (1) Li-ion Power Pack Charger (#28986)
  • (2) High-Capacity Li-ion Cell (#28987)
  • (1) Veho 360 Speaker (#900-00018)
  • (1) Veho Speaker Stand for Propeller BOE (#725-32900, discontinued)
  • (1) 2 GB microSD Card (#32319)
  • Connecting wires
  • USB Adapter for connecting microSD card to PC and load WAV files
  • Mounting plate or chassis for PING))) Mounting Bracket and PCB

Note: Many of these parts are discontinued for sale or manufacture by Parallax, but may be found through other retailers, or have suitable replacements available through Parallax or other retailers.

XBee and USB Connections

Since this demo is a modified version of the RN-42 Bluetooth to PC Demo Project, please refer to that project for build details. For this demo we’ll just cover the installation and connection of the XBee Module and USB interface, since that is the only difference.

Figure 1 – RN-42 Bluetooth to PC Demo Conversion

If you’re converting the RN-42 Bluetooth to PC Demo, remove the RN-42 Bluetooth module from the breadboard and all the wires used to connect it. See Figure 1.

Since power is already provided to the socket you only need to connect the signal pins. In this case we’re only going to connect DI and DO. You may connect RST, RTS and CTS but they won’t be used in the code. P1 should connect to DI on the socket in the center of the board. P2 should connect to DO.

Figure 2 – XStick 802.15.4 Dongle

Now for the PC side. Figure 2 shows the XStick 802.15.4 dongle, which resembles a USB memory stick. Be sure you have the latest USB drivers from FTDI installed on your PC. If you have any Parallax USB devices you probably already have these. If not, go to the FTDI website under drivers and VCP drivers.

Figure 3 – Insert the XStick into the PC. Note the orientation.

Once the drivers are installed, insert the XStick into a USB port on your PC (Figure 3). Once driver installation has completed, a new COM port will be assigned to the XStick.

As you add each component to the Propeller BOE you should run the associated test code for that device. For example, once the DS1620 is connected, run the Test_DS1620.spin code. Once the ADC and photoresistor are connected run the Test_ADC0831.spin code.

The Parallax Serial Terminal will display the results @ 9600 bps connected to the COM Port used to program the Propeller BOE. There are test programs included with this project for all sub-systems connected to the Propeller BOE.

Testing Communications

Load the XBee PC_Prop-BoE Demo V1.0 program. Communication with the demo unit is done by connecting via the XStick from your PC. Open the Parallax Serial Terminal (or any terminal program) to the XStick COM Port created by your O/S. The port
speed should be set to 9600 bps. Be sure the Propeller BOE power switch is in the second position (2) so the PING))) Sensor and servo are powered up.

Figure 4 – Terminal Screen Output

Once connected the demo unit should start sending telemetry. At this point you should be seeing this data from the demo unit as shown in Figure 4. Temperature, light level and distance as determined by the PING))) Sensor. You can also send commands to the demo unit. The demo unit understands the following commands sent from the terminal:

  • !clr – clear the terminal screen, and refresh the telemetry data
  • !svo1 – move the servo to position one (90 degrees right)
  • !svo2 – move the servo to position two (center position)
  • !svo3 – move the servo to position three (90 degrees left)
  • !snd# – where # is a number from 0-9 corresponding to a WAV file to play
  • !inr0 – turn Red LED off
  • !inr1 – turn Red LED on
  • !ing0 – turn Green LED off
  • !ing1 – turn Green LED on
  • !inb0 – turn Blue LED off
  • !inb1 – turn Blue LED on

Each command starts with an exclamation point. The next three letters are the command. Three letters were chosen to keep things simple for the parser code. Some commands have a parameter that follows. Once the full command is understood it is executed, no carriage return and/or linefeed are required. All commands are in lowercase.

The only command that would affect the telemetry is the ‘svo’ command, since the direction the PING))) Sensor faces may change the distance. Watch the RN-42 Bluetooth to PC Demo Video for an example of how everything works. That video shows all commands, as well as disconnecting and reconnecting.

About the Code

All of the objects used for the various functions were obtained from the Propeller Library (built into the IDE), the OBEX (Object Exchange), or the Parallax Forums. Everything works together with very little work to balance things out. All required objects are included in the ZIP file in the resources section.

The telemetry code is launched into a new cog. Its function is to read the sensors and send the data, wait one second and repeat. It runs completely independent of the other functions. Each of the three telemetry sections calls a method in the appropriate object setting a variable and then formatting that data out to the terminal.

The command parser evaluates incoming commands and executes them when a complete command is detected. It does this by first evaluating every character starting with the “!” character. Once this character is received the next character is checked against possible matches. If at any point the next character is not a match the whole evaluation resets. In the parser section the various levels are indented in such a way that commands are evaluated on through until completion or a wrong character.

For example, once the “!” is received the next character is compared against “c”, “s” or “i”. If “s” is received the next character is compared against “v” or “n”. If “v” is received the next character is compared against “o”. If it does not match, the parser won’t evaluate again until “!” is received again. This level-nested evaluation is an easy way to parse commands, even if they have
similar characters at the beginning as the “svo” and “snd” commands do.

Resources

RN-42 Bluetooth to PC Demo – Tutorial

RN-42 Bluetooth to PC Demo – Video

Discuss this tutorial on Savage///Chats

Released under MIT License

Copyright (c) 2014 Chris Savage – Savage///Circuits.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

PLEASE FEEL FREE TO LEAVE YOUR COMMENTS, QUESTIONS, SUGGESTIONS OR FEEDBACK ON THIS POST.

Leave a Reply