Alright, so you have X-CTU installed on a Windows machine, two XBee modules, a USB interface and the XBee shield (this can be found here on the Sparkfun website as a retail kit), now how do you make it work? First, you will need to configure one XBee to be the coordinator (the sender). Plug the XBee module into the USB Explorer (or any USB interface device, I used this one) and then into the computer. If you are running Windows Vista or higher, the drivers should already be installed to read this device. If not, or you are running Windows XP, you will need to obtain the FTDI drivers from here, just select your operating system and follow the instructions. Simply put, these drivers allow the computer to read your USB device as a serial port since the XBee modules act as serial modems. Next, we will need to read the XBee module. After plugging in the USB device, open the X-CTU application and leaving all the settings at their defaults, go to the modem configuration tab and click on "Read." This will read the current data on the XBee module and display then in a screen much like this one:
So what do all these values mean? For a thorough overview with a complete description of each command you can check out the XBee manual here. I found this to be of very little value, especially if you're looking to just configure the modules for basic use. For this example, we will only be passing integers across the network, therefore, the default packet sizing will suffice. If we were to pass, say Arduino programs across the network, we would need to set the packet size much larger to allow larger files and data rates to transfer.
CH: The CH (Channel) is simply which channel you wish to operate. For the purposes of this demonstration, the default "C" channel. It is important that which ever channel you choose to use, that both XBee modules are set on the same channel.
ID: The ID (Pan ID) is the numeric value of the network. This can be any 4 digit number as long as the ID on both modules is set the same.
DL: The DL (Destination Address Low) is the address of the module you are sending data to. The DL of the sender will be the MY of the receiver.
MY: The MY (16-bit Source Address) is the address of the module which is being used. This functions similar to the way your IP address works on your computer. This is the address which is needed to connect to this device.
A2: A2 (Coordinator Association) is where you set whether this module is a coordinator, in other words, if it is a sender of data or a receiver. A sender is 1 and a receiver is 0.
BD: The Interface Data Rate (BD) is the baud rate at which the serial port is used. For use on the Arduino, this is the value which the Serial.begin(...) command is opened on. The default value is set to 3-9600. This is the most common and unless you are needing to read at a faster value, will do just fine for most Arduino applications.
To configure the first XBee module for use as a coordinator, simply change the following settings:
- ID = 1113
- DL = 1234
- MY = 5678
- A2 = 1
- BD = 3-9600
Next we will configure the receiver. This can be done by exiting out of X-CTU, switching out the XBee modules (keep track of which one is which as they are not interchangeable). Open X-CTU again, going to the modem configuration tab and reading the module. This time we will set the attributes as follows:
- ID = 1113
- DL = 5678
- MY = 1234
- A2 = 0
- BD = 3
Here, we are setting the Pan ID the same as the previous since we want this device to read data on the same network as the coordinator. The Destination Address will be the same as the coordinator here so the device can communicate back (if you want to send data back and forth). The 16-bit Source Address is the same as the Destination Address on the coordinator module. This allows the other device to see this as the destination of the data it's sending. We do not want to enable this device to coordinate, so we leave A2 as zero. We leave the baud rate as 3-9600.
We need to write these attributes to the module by going to the "Write" button just as we did for the coordinator.
Now these two devices are set up to communicate one way from either the computer or an Arduino to another computer or Arduino. Let's test to make sure it works. First you will need to solder up the XBee shield for the Arduino and then plug that into the Arduino. Upload the following code to the Arduino before inserting the XBee into the slot:
void setup()This program will let us pass serial values to the Arduino using the built in serial monitor within the Arduino GUI. After writing this program to the Arduino memory, insert the sending XBee module into the USB explorer and connect it to the computer. Make sure the proper device is selected under the serial port within the Arduino GUI interface. Open the serial monitor. Now connect the receiving XBee module to the Arduino by placing it within the shield and connect an external power supply to the VIN and GND ports. You can not power the Arduino using a USB cable since the Arduino is seen as a serial device. There will be a conflict between the serial USB and the XBee. Next, type in the window an "a" without quotations and you should see the LED on pin 13 (connected on the board already) light up. If you type a "b" and send it, the LED should turn off.
{
Serial.begin(9600);
Serial.flush();
pinMode(13, OUTPUT);
}
void loop()
{
char val = Serial.read();
if(val == 'a')
{
digitalWrite(13, HIGH);
}
if(val == 'b')
{
digitalWrite(13, LOW);
}
}
If you want to have two Arduinos connect to each other, you can write a program to pass values through the sending XBee modules (you will need another XBee shield to make this work) to the other Arduino. One way to check this is working is to flash a program that writes an "a" and then a "b" every second to the serial port. The LED on the receiving Arduino should flash on and off every second.
No comments:
Post a Comment