Let's Make Robots!

Wireless upload / link of Arduino using Xbee modules

Gives you a wireless connection to your robot
Xbee_manual.pdf1.34 MB
X-CTU_manual.pdf477.24 KB
Base_Xbee_configuration.pro614 bytes
Robot_Xbee_configuration.pro615 bytes

Recently I tried to set up a wireless link between my laptop and a robot so that I could upload new sketches and adjust certain parameters of the program while the code was running. This was not as easy as I thought.

Xbee modules are a fantasic way for your robot to communicate with a PC or other robots. They are very small, have built in analog inputs, digital I/O pins and have many configutation options that make them ideal for swarm robots.

Unfortunately the configuration options can be confusing. The manuals are not really written for beginners and as such seem a bit vague on many of the configuration options. In this walkthrough I will explain the basic hardware and configuration requirements needed to communicate between your Arduino and PC or laptop.

Basic Hardware requirements:
Obviously you will need two Xbee modules. There are various types available depending on the range you require. I am using two 60mW Xbee PRO modules. These have a line of site range of 1.6Km (1 mile) and an indoor range of 100m (300 ft). Perfect for most robotic applications.

If your trying to save power then the 60mW modules power output can be adjusted by the software. If you are using high power modules then I suggest you dial down the power when first configuring and testing since you will probably have transmitter and receiver sitting on your desk and I had some reliability issues when both were at full power in the same room. The cheaper low power modules will not have this problem.

As the Xbee modules do not use a standard header pin I recommend using Sparkfun's Xbee breakout board for your robot. You will need an interface for your PC. I am using Sparkfun's Xbee explorer module which is easy to use USB interface for the Xbee.














When connecting your Arduino to your Xbee for serial communications you must allow for the the fact that your Xbee runs on 3.3V and your Arduino runs on 5V. Some Xbees claim to be "5V tollerant" but for the sake of 3 resistors I prefer to add a little insurance rather than risk damaging my Xbee. Below is a simple interface that I recommend as a minimum requirement.

The 3.3V output from the Xbee's TX pin will be accepted by the Arduino's 5V logic without any problem. The series resistor simply protects the Xbee TX pin in case your program converts the RX input into a digital output. The 5V output of the Arduino's TX pin is divided by the 4K7 and 7K5 resistors to just over 3V.

I am using the X-CTU (Xbee Configuration, Trouble shooting Utility). Apparently this is only available for windows machines. I cannot advise Linux and Mac users on what software to use but the configuration settings should be the same regardless of the configuration software used.

The default baud rate for the Xbee modules is 9600.

With my Xbee module plugged into the Xbee explorer and connected to the PC you can see that my Xbee module is currently set to 57600 as I am uploading sketches to an Arduino Mega compatible board.

When you use your Xbee modules for the first time you will need to set this to the default 9600. The data, stop and parity bits should not need adjusting. Click on the [Test / Query] button to confirm you have the baud rate set right. If you cannot communicate then you may need to change the baud rate and try again. Once you have communications established then click on the "Modem Configuration" tab.

Click the [Read] button under "Modem Parameters and Firmware".

At this point you may want to consider making sure your firmware is up to date. If your Xbee modules do not both have the same firmware then you could run into problems. Clicking on the [Download new versions...] button will let you choose to download the latest versions from the net. You will then have all the versions available and can select the version you want. Normally the latest is the best. Select the version you want and hit the write button or alternatively check the "Always update firmware" box.

You will notice that the green options apear to be default settings, black are hardwired (e.g. serial number) and blue are settings that I have changed. Usually you will not need to change the channel, PAN and Destination address High. Just make sure they are the same on both Xbee Modules.

Networking & Security:
The address can be a little confusing. Destination Address High should be set to 0. In this case my Xbee connected to the laptop is set with the Source Address of 2222 and the Destination Address of 1111. The Xbee on the robot has the Source Address of 1111 and the Destination Address of 2222. This ensures that my two modules only talk to eachother.

From my understanding of the manual (please correct me if I am wrong) changing these values to "FFFF" will use the "Broadcast Address" allowing all robots with the same PAN ID to talk to each other. If you had 2 or more swarms of robots (e.g. two teams competing against each other) then you would use a different PAN ID for each swarm.

RF Interfacing:
This is pretty easy. Just set your power level. During configuration and testing I would probably leave this set to the highest level. As your robot and PC can read the signal strength received and adjust this settings at any time then robots that are trying to conserve power may want to adjust this according to the received signal strength. If you are making a swarm then you may want to play with the CCA setting but I don't recommend it.

Serial Interfacing:
Set your baud rate on both modules to the same setting. Remember once you have changed this setting you will need to go back to the PC setting and change that as well. If you just want simple data transmission between the two Xbee modules then the default 9600 will be fine. If you want to upload sketches then you will need to change this. For the older Arduino boards using the ATmega168/328 processor it will probably be 19200. The original Arduino Mega is 57600 and the new Uno and Mega PCBs use 115200. Check the "boards.txt" file in your Arduino IDE if your having problems here.

Packetization Timeout is a somewhat confusing setting and probably best left at the default setting of 3. Some tutorials suggest setting this higher for large program uploads. I have set mine to 10 as suggested by one tutorial but I didn't notice any difference. If anyone can explain this better then please do and I will update this tip.

At this point you should be able to write a simple sketch that uses Serial.println() to send data from your Arduino to the PC  through the Xbee modules. Make sure your baud rate for the Serial Monitor in the Arduino IDE is set the same as your Xbee modules.

Once you can get a simple data transmission between your Arduino and your PC through the Xbee modules then you are ready to move on to sketch uploads. Uploading a Sketch reqires resetting the Arduino at the right time.

Normally the DTR output from the USB interface is connected to the reset pin of the Arduino by a 100nF series capacitor. To do this wirelessly we will take advantage of the Xbee's digital I/O pins and a technique called "I/O line passing". In my example I use I/O pin 0.

Unfortunately the Xbee's 3.3V digital output won't reset the Arduino without some help. We need the capacitor to have a 5V to 0V drop to reset the MCU.  I have shown a CD4050BC hex non-inverting buffer being used.

As the Xbee can transmit several digital I/O pins the CD4050BC can translate 5 additional 3.3V digital outputs to 5V logic. The unused inputs of the buffer should be tied to ground.

In my example I used a jumper wire to attach the DTR output to the D0 input.

Some additional configuration is required for the I/O line passing to work. I/O line passing allows virtual wires to be created connecting two devices wirelessly. The pins are mapped in pairs so in our case what goes into D0 at PC side should come out at D0 connected to the Arduino.

I/O Settings:
You can see here that on my Xbee connected to the PC, DIO0 has been set to 3 which is as a digital input. The Xbee connected to the Arduino has this set to 5 which is digital output with a default setting of high.

The DIO change detect is a bitmask indicating which pins to monitor and which to ignore. Setting this to 1 indicates that only D0 is being used. I set this the same for both Xbee modules.

I/O Line Passing:
The first option here is IA which is the IO input address. this address ties the I/O pins of one Xbee module to another. In this case I have cheated and just set it to FFFF which is like the broadcast address in that it will allow the signals from any Xbee module to control it's I/O pins. If you have more than 2 Xbee modules then you may need to set this to a more apropriate setting.

The next setting is the D0 time out option. If the Xbee does not receive an update on the I/O pins status within this many milliseconds then the output will return to it's default state which in our case is high. For now my setup seems to work ok with this set to 0 for the Xbee connected to the Laptop and FF for the Xbee connected to the Arduino.

PC / Laptop serial port configuration:
You should check your port settings an make sure the port is set to the same baud rate as your Arduino requires for uploading code. I've used 57600 for my Spider controller. Check the boards.txt file in your arduino\hardward\arduino\ directory to determine the correct baudrate for your Arduino controller.

Go to your port settings and click on the [Advanced] button.

After this, try uploading a sketch to your Arduino. If it doesn't load then check your power settings. If you have all settings correct then you can not only upload sketches but also have your Arduino transmit debug/serial data back to your PC.

I have attached the manuals for both the Xbee modules and the X-CTU software (for Windows XP) as well as my configuration files. You can run the X-CTU software and load my profiles to compare them with your own if you are having problems.

I have successfully used this link in conjunction with Gobetwino to display my robots sensor data in an Excel spread sheet.

Good luck and enjoy.









Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

And found that ceiling also. You can set them higher if you like overrunning buffers and the often interesting results of that. They are all about range and/or getting through obstructions. They love batteries. Have you played with power reduction at all? I need to do that at some point. 

EDIT - Dang it - I am forum impaired. this was supposed to a reply to your reply about 900 Pros.

I am using xBee Pro 900 modules. On 2 of them I have the SFE regulated Explorer but it has a problem with Pro models requiring shorting of the tiny diode at DIN, so for the other units that need them I got the AdaFruit adapter which has a mouse over picture at http://www.ladyada.net/make/xbee/ explaining a few of the components. Got your 3 resistors plus a voltage regulator, a couple of caps and an IC to do the level shifting.

The Arduinos using them are a MEGA 2560, a MEGA 2580 and 1 to n (n = 2 prototypes; many more in the field) Pro Minis. Those are likely to get replaced by custom boards if (hopefully when) this goes production. I probably should have just used the breakout board on the Pro Minis, as they are 3.3v.

I also have the USB Explorer which I use to communicate with them using a home brewed protocol. It's not a swarm, but there are design reasons for a party line approach. I have been concerned about whether or not to try the upload because I have 3 code sets so I am usually only selectively updating one device. But it is an interesting thought - if you had a swarm, could you reprogram them all at once?

BTW, I also have a Fio which I was hoping to use for the simplest of the devices. Seemed like a great way to simplify since it has an on board xBee socket and built in LiPo charger.  It will not run a 900 Pro though.

I have 2 of the Xbee Pro 900-XSC and they have a baud rate limit of about 9600 because of the much lower frequency they use. This is not suitable for program uploads unless you modified the Arduino bootloader to suit.

As for uploading to a swarm simultaneously, I think the problem there is that uploading a sketch requires two way communications. You would have multiple bots responding at once. You would have to program each robot in the swarm individually using it's own address.

To use Xbee's to program a swarm simultaneously would require a specialised protocol.