Arduino Demo Sketch of Andrew Rapp's Xbee-arduino Library

Using the Xbee-arduino Library with XBee ZNET 2.5 modules.

Andrew Rapp has written a very nice Arduino library that permits Arduinos to talk in API mode to XBee modules. The library can be found at the Google Code xbee-arduino site. The library can interface both Series 1 (802.15.4) or Series 2 (ZNET2.5/ZB) modules, giving the developer much more comtrol over communications than can be had using the transparent "AT" mode.

I've used XBee ZNET2.5 modules on a few projects, but only in transparent "AT" mode. This mode is akin to a dial-up modem, where the module is told a destination address and sends ann traffic there until told otherwise. For my next project, I need my XBee modules to function as true network nodes, being able to send and receive packets to any other node at will. The first part of the proejct wil be a simple responder, where a node sends a simple text-based command to another node, which will respond back to the sending node.

Mr. Rapp provides some nice sample sketches for his library, but each sketch only shows a "receive" or a "transmit" configuration. Mr. Rapp's sketches were helpful, but didn't explain how to extract data from a received packet and use the data create a response to the sending node. I spent some time trying to figure out how to receive data packets then respond to the sender, and came up with an Arduino sketch that simply "echoes" received data back to the sending node. It's not very useful, but it does demonstrate the principle and how to get from the library the various pieces of data required to create a response.

Demo Hardware Setup

I developed this sketch using:

I tested the setup using another Series 2 XBeePRO Module (ZNET 2.5) running "Router/End Device AT" firmware (v1247), installed in an Adafruit XBee Adapter kit connected to a terminal emulator, and configured with the API-mode Xbee as its Destination Node (ATDN). The goal was to enter characters or strings into the terminal emulator and have the Arduino/API-mode Xbee echo the data back to the terminal emulator.

The Arduino Sketch

Click here to obtain the sketch.

The Sketch presumes that "XBee.h" and XBee.cpp" in the same folder with the sketch, rather than in the Arduino Library as Mr. Rapp recommends. This can be changed back to Mr. Rapp recommendation by changing the delimiters in the XBee include line from quotes to the standard "less than" and "greater than".

I have extensively (almost painfully) commented the Sketch heavily to point out what I think is happening in almost every line that has to do with Receive and Transmit Packet handling. I've also tried to point out the "whys" behind the code. I don't promise it's prefect, but I think it's very close. The Sketch is only built to demonstrate Zibgee Receive packets (0x90) and Zigbee Transmit Requests (0x10) and doesn't deal with other packet types.

The sketch is also written to provide addressing and data information about each reeived data packet to a Software Serial port on Arduino Pin D2 at 9600bps. This is leftover code from my investigations but may be useful, so I left it in.

I hope you find this useful.

Thanks to Andrew Rapp for the library and LadyAda for the great parts...

Disclaimer. Any and all opinions expressed on this page are solely those of the author. The author accepts no responsibility for the accuracy of data provided on this web site, nor does the author accept any responsibility for the use and /or misuse of information provided on this web site. It is the full and sole responsibility of the user to determine whether and/or how best to use the information provided within their own circumstances, and it is the full and sole responsibility of the user to accept any and all benefits and/or consquences of their actions. Please see my Privacy Policy.

Copyright 2001-2009, Tim Sharpe. You are free to use this information for personal, non-commerical use without restriction. All rights reserved for commerical, organizational, or government use. Questions or comments to Flames to /dev/nul.

[Python Powered]
All the Perl that's Practical to Extract and Report

07277 visits since