XBee Communication

XBee Communication


XBees are a very simple way to enable wireless communication. Using wireless communication will expand the possibilities of a project, and is practically a necessity for a robot.

Two types of XBee communication that will be discussed are Arduino-Arduino communication and Arduino-Computer communication.

XBees cannot both send and receive data at the same time. If caution it taken, data should not be lost due to this fact.

Arduino-Arduino Communication

If the Arduino shield is being used, the jumpers should be set to USB mode when programming the Arduinos and then should be set to XBee mode when the programs are run.

Coding with XBees is simple because they can simply be coded using the familiar serial code.

To send from an XBee:

Serial.print("Send to other XBee");

To receive from an XBee:

int incomingByte;

if (Serial.available() > 0) { incomingByte = Serial.read(); Serial.print(incomingByte); }

Arduino-Computer Communication

The above code for sending and receiving data from an XBee is valid for the code on the Arduino.

If an Arduino with a shield is used to connect to the computer, the code put on that Arduino is a simple blank sketch:

void setup() {}

void loop() {}

The blank sketch bypasses the microcontroller and allows the data to flow through to the computer. For the XBee shield that is connected to the computer, the jumpers should be placed on USB mode since the data is going to be sent through the USB to the computer.

The data coming through can then be seen in the serial monitor. The data sent from the serial monitor will then be sent through the XBee to the other one on the Arduino.

If the serial monitor is not an attractive option, python code can also be used to handle the serial coming through. Creating a GUI may be a best option to handle the serial coming into the computer.

Jenn Case Wed, 02/06/2013 - 13:11