Go Down

Topic: xBee loopback with hardware flow control (Read 1 time) previous topic - next topic

lex talionis

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);
 pinMode(CTS,INPUT);
 Serial.begin(9600);
 Serial.println("Arduino Console");
 xbeeSerial.begin(9600);
 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);
   i++;
 }
 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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy