You can get the serial library here: http://www.ladyada.net/make/eshield/download.html
Arduino sample code below:
- Code: Select all
#include <AFSoftSerial.h>
// To easily use the Xbee shield as a PC <-> Xbee passthrough we can tie the Xbee serial ports
// to unused arduino i/o pins and use a software serial library to interface with the Xbee shield.
// This leaves the hardware serial port fre to be used by the arduino usb connection to the PC.
// We can now send/receive commands from the computer, process on the host arduino if needed and then relay
// to the remote Xbee. Any data sent back from the remote Xbee can be received on the host Xbee, data again
// processed if needed and info can be sent via usb to the pc.
// Shield still needs to be removed before programming arduino.
//remove the two serial select jumpers on the Xbee shield and wire the two middle pins to unused i/o
//pins on the arduino. In this case we are using 2 & 3
//LadyAda's Serial library can be found here: http://www.ladyada.net/make/eshield/download.html
AFSoftSerial XbeeSerial = AFSoftSerial(3, 2);
void setup() {
Serial.begin(9600); //connection to host computer
Serial.println("Xbee Software Serial Test!");
XbeeSerial.begin(9600); //connection to Xbee shield
}
void loop()
{
//simple relay test. Of course we could be processing data here as needed before sending out in either direction.
if (XbeeSerial.available()) {
Serial.print((char)XbeeSerial.read()); //grab avail data from Xbee and send to host pc
}
if (Serial.available()) {
XbeeSerial.print((char)Serial.read()); //Now take any incoming data from pc and relay to Xbee
}
}
