Software Serial with Xbee shield to enable passthrough

Everything Arduino - Arduino is an exciting and fun open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.

Software Serial with Xbee shield to enable passthrough

Postby willp » July 3rd, 2008, 12:44 am

Using LadyAda's Software Serial library it is quite easy to free the Xbee shield from hogging the hardware serial on the Arduino. Now you can easly pass data from the pc through the Xbee shield both directions without having to remove the Arduino processor.

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
  }
}


Xbee_Soft_Serial.jpg
Simple wirewrap jumpers
Xbee_Soft_Serial.jpg (41.9 KiB) Viewed 4665 times
www.FunGizmos.com
willp
Site Admin
 
Posts: 19
Joined: February 4th, 2008, 1:21 am
Location: Woodland, WA

Re: Software Serial with Xbee shield to enable passthrough

Postby flatMC » October 12th, 2009, 2:20 am

Nice topic!
flatMC
 
Posts: 3
Joined: October 12th, 2009, 2:15 am


Return to Arduino

Who is online

Users browsing this forum: No registered users and 1 guest

cron