Pages: [1]   Go Down
Author Topic: xBee loopback with hardware flow control  (Read 1116 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).

#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);
    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);


Pages: [1]   Go Up
Jump to: