For those who have no clue what these modules can do, here some specs:
- Power output: 1mW
- Indoor/Outdoor range: Up to 30/100 m
- RF data rate: 250 Kbps
- Interface data rate: Up to 115.2 Kbps
- 6 x 10-bit ADC inputs
- 8 x Digital I/O
- Configuration: API or AT (Hayes) Commands.
- Operating frequency: 2.4 GHz
- Networking topology: Point-to-point, point-to-multipoint, & peer-to-peer
- Addressing: 65,000 network addresses available for each channel
- Supply voltage: 2.8 - 3.4 VDC
- Transmit current: 35/45 mA @ 3.3 V for normal/boost mode
- Receive current: 50 mA @ 3.3 V
- Sleep current: <10 A
- Interface options: 3V CMOS UART
- Size: 24 x 28 mm
- Weight: 3g
Primary goal for getting these 2 XBee modules was to get familiar with the XBee/Zigbee concept and do some experiments with these modules. For example, i wanted to see if I could get my Arduino wireless. After a lot of reading I decided to give it a try; and here is a summary of how surprisingly easy it was to get the 2 XBee modules working and getting my Arduino wireless as an extra bonus.
<b>Buying</b>
The first experiment was to connect one Xbee module to my PC and another one to my Arduino.
For that I bought the following items:
<u>2 x Digi XBee 802.15.4 (Series 1) module</u> (Digi Article Number XB24-ACI-001)
<u>2 x Xbee Adapter kit</u>
This adapter is used to plug in the XBee modems and takes care of:
- Onboard 3.3V regulator to power the XBee;
- Level shifting circuitry that makes it easy to connect it to 5V circuitry such as an Arduino;
- Two LEDs, for activity (red) and power (green)
- 10-pin 2mm sockets included to protect the modem and allow easy swapping, upgrading or recycling
- http://www.adafruit.com/index.php?main_ ... cts_id=126
- Specifically created for use with the FTDI cable mentioned below.
<u>1 x USB TTL-232 cable - TTL-232R 3.3V</u>
This is a cable with a FTDI FT232RL usb/serial chip embedded in it. It has a 6-pin socket at the end that connects perfectly to the Adapter Kit mentioned above.
<b>Soldering & Configuration</b>
After soldering the 2 Adapter kits and plugging the Xbee modules into the adapter, connecting the USB cable to an adapter and the PC, the green LED started blinking right away; so far so good! Make sure you have the latest FTDI drivers on your PC, otherwise the cable wont work.
After testing both combinations of adapter and module, I could have started working with the Xbee modules right away, but I chose to change a few things in the modules before doing that:
- updating the Xbee modules firmware to the latest version;
- selecting my own PAN ID instead of leaving it to the factory default.
Changing the baud rate is another useful option to consider at this point. I left the baud rate to 9600 for now.
Configuration can be done in different ways. Either by use of a terminal program (Hyperterminal or whatever your favorite is) or by using a (Windows only) tool made by Digi, called X-CTU. If youre using a terminal program make sure you set the COM port settings to 9600,8,N,1. Connect, and type +++. The Xbee module should respond with an OK. Sounds familiar, right? Yep ,the XBee module can be configured with AT commands. For example, ATBD 3 means setting the baud rate to 9600, ATBD 4 will set it to 19200 baud. ATWR saves the new settings to the flash memory.
If you dont want to look up all the AT commands you need to configure the Xbee module the way you want, the X-CTU tool from Digi is the easiest way. This is what X-CTU looks like:
Very easy to use; you can perform firmware upgrades with it, save configuration profiles and reload those into the Xbee module, it has some testing tools like a terminal window, etc. It works very easy; no need for F1. (maybe thats why it doesnt even have a help file). For Linux users, AFAIK, the only option is by means of a terminal program. More experienced users should be able to make a script to send all the necessary AT commands to the serial port.
XBee module connected to PC:
<b>"The other side"</b>
Ok, now we have 2 Xbee modules, configured and ready to use. Now it's time to prepare the other side, my new Arduino. So i placed 1 XBee adapter on the breadboard next to the Arduino that was still running its silly 3 blinking LEDs test sketch.
Now it was time to make that sketch a bit more interactive so i created a new sketch that will scan the Xbee Serial data arriving at the Arduino for ASCII characters R, Y, G and (space). The R will toggle the Red LED, the Y will toggle the Yellow LED, the G will toggle the Green LED and the (space) will toggle all LEDs. Just a simple sketch to start with.
Code: Select all
//
// LED switching by means of XBee
// Sep 2009
//
#include <NewSoftSerial.h>
NewSoftSerial XBSerial = NewSoftSerial(2, 3);
int ledPinR = 10; // Red LED connected to digital pin 10
int ledPinY = 11; // Yellow LED connected to digital pin 11
int ledPinG = 12; // Green LED connected to digital pin 12
int Rval = LOW; // initial state of Red LED
int Yval = LOW; // initial state of Yellow LED
int Gval = LOW; // initial state of Green LED
void setup() {
// Set all pins for OUTPUT
pinMode(ledPinR, OUTPUT);
pinMode(ledPinY, OUTPUT);
pinMode(ledPinG, OUTPUT);
// Set all LEDs to initial state
SetPin(ledPinR, Rval);
SetPin(ledPinY, Yval);
SetPin(ledPinG, Gval);
// Setup SoftwareSerial port
XBSerial.begin(9600);
// send informational message to terminal window
XBSerial.println("Setup finished.");
}
void loop() // run over and over again
{
if (XBSerial.available()) {
// read serial data byte by byte
byte inByte = XBSerial.read();
// scan for specific characters: R,Y,G and space.
switch (inByte) {
case 82: // R toggles Red LED
Rval = Rval==HIGH?LOW:HIGH;
SetPin(ledPinR, Rval);
break;
case 89: // Y toggles Yellow LED
Yval = Yval==HIGH?LOW:HIGH;
SetPin(ledPinY, Yval);
break;
case 71: // G toggles Green LED
Gval = Gval==HIGH?LOW:HIGH;
SetPin(ledPinG, Gval);
break;
case 32: // Spacebar toggles all LEDs
Rval = Rval==HIGH?LOW:HIGH;
SetPin(ledPinR, Rval);
Yval = Yval==HIGH?LOW:HIGH;
SetPin(ledPinY, Yval);
Gval = Gval==HIGH?LOW:HIGH;
SetPin(ledPinG, Gval);
break;
}
// echo the inByte
// (no specific purpose)
XBSerial.print((char)inByte);
}
delay(10);
}
void SetPin(int pin, int value)
{
digitalWrite(pin, value);
}
Another cup of coffee and finally: Compile, Upload, Running!
Here's the Arduino board with the other XBee module:
The Xbee adapter is now powered with 5V from the Arduino (red and black wires) and the adapters RX/TX lines go to pins 2 and 3 (green and white). Normally you would use pins 0 and 1 for that, cause those 2 pins are designated for serial I/O, but that would mean I would lose the USB connection to upload sketches to the Arduino. And with very little programming experience on the Arduino that didnt look like a good idea. Fortunately theres a library called NewSoftSerial that makes it possible to do Serial I/O on other pins as well.
Now, when I have a terminal window open and connected to the Xbee module, I can use the keyboard to toggle the 3 LEDs. Yeah, I know, this wont win any "most innovative project" price, but at least I can see my 2 Xbee modules communicating with each other, and my Arduino is wireless. Mission accomplished!
Afterwards i made a small executable with 4 buttons that illustrates it all:
And what has actually been created here? The basics for a wireless, programmable interface with 14 Digital I/O Pins (of which 6 can provide PWM output) and 6 Analog Inputs! If that aint nice
Total costs:
Code: Select all
Arduino 22,50
USB cable 18,50
2 XBee modules 31,30 ($ 46,00)
2 XBee adapters 13,60 ($ 20,00)
<b>Total 85,90</b>
- Getting hold of another kind of Xbee adapter that will Ethernet-enable a Xbee module so I can talk to it from my HA system;
- Integrating Xbee/Arduino combo in my HA system as an additional Interface so I can make use of all of the capabilities the Arduino has to offer from within my HA system;
- Buying a Pan & Tilt mechanism (to cheap to DIY) and hooking it up to the Arduino to learn more of the I/O capabilitys of the Arduino;
- And probably the most important one to result in more new ideas: exploring the capabilities of a stand alone Xbee module (as in: what can you do with the onboard Analog and Digital I/O an Xbee module has to offer)!
To be continued...
<hr noshade size="1"><font size="1">Robert
http://www.hekkers.net <i>Digit's Online Home.</i></font id="size1">