Go Down

Topic: xBee loopback with hardware flow control (Read 2103 times) previous topic - next topic


Howdy y'all,

Heres some code I found really handy.  This sketch turns your arduino w attached xBee into a loopback device for X-CTU's loopback test.  It uses newSoftSerial to make a second serial port on pins 2&3, and uses pin 4 for flow control, specifically  the CTS line (pin DIO7 on the xBee).

Code: [Select]
#include "NewSoftSerial.h"

#define CTS 4

NewSoftSerial xbeeSerial =  NewSoftSerial(2, 3);

char data[220];
byte ctsStatus;

void setup()
 pinMode(13, OUTPUT);
 Serial.println("Arduino Console");
 xbeeSerial.println("xBee Port");

void loop()
 int i = 0;
 data[0] = 0;
 while (xbeeSerial.available())
 {                                     //read the aether
   data[i] = (char) xbeeSerial.read();
   Serial.print(data[i], BYTE);
 ctsStatus = digitalRead(CTS);
 if (ctsStatus == 0)                    // inverse logic, we are clear on 0
   for (int j = 0; (i != j); j++)
   {                                       // spray it back
     Serial.print(data[j], BYTE);
     xbeeSerial.print(data[j], BYTE);

Go Up