This is kind of a follow on to a previous thread, but with different hardware and a bit more detail...
This time I'm using an XBee Series 2 Co-ordinator connected to my laptop via a XBee Explorer USB and the corresponding router is connected to a Real Bare Bones Board in turn connected to my laptop via USB.
RO/ Packetisation Timeout is set to 0
The sketch I'm running should echo back the number sent for 1-3 and 'misc' for everything else.
With the code below, I'm finding that when I send a digit the first one doesn't have an effect, and thereafter each digit sent triggers the appropriate response to the previous digit. Here's the output from the X-CTU terminal on the coordinator (red from the router, blue is what sending to the router)
#include <SoftwareSerial.h> //includes the software serial library
#include <TinyGPS.h>Â // includes the TinyGPS library
SoftwareSerial XbeeSerial(9, 10);
// a byte to receive data:
char inByte = 0;
int Xbeepower = 6;
void setup()
{
 Serial.begin(115200);Â
 XbeeSerial.begin(9600);
 pinMode(Xbeepower, OUTPUT);
 digitalWrite(Xbeepower, HIGH);
} //end setup
void loop()
{
 // get any incoming data from xbee:
 if (XbeeSerial.available() > 1) {
  // read a byte
  inByte = XbeeSerial.read();
 }
 if (inByte == '0') {
  Serial.println("0");
  XbeeSerial.println("0");
 }
 else if (inByte == '1') {
  Serial.println("1");
  XbeeSerial.println("1");
 }Â
 else if (inByte == '2') {
  Serial.println("2");
  XbeeSerial.println("2");
 }Â
 // do nothing if anything else was received
 else {
  Serial.println("misc");
  XbeeSerial.println("misc");
 }
 delay(2000);
} //end loop
So, sending each digit twice kind of works as a workaround, but it would be good to understand what's causing this and, ideally, just send each digit once. (I'm hoping to build up to sending arrays.)
Am I sending the digits in the wrong format or something like that?
I moved everything into the
if (XbeeSerial.available() > 1) {
statement and I think it's now doing what you think it's doing - just one response for every key pressed (the original code repeats the output until another key press)
Terminal output looks like this (I hit enter a few times at the start)
#include <SoftwareSerial.h> //includes the software serial library
#include <TinyGPS.h>Â // includes the TinyGPS library
SoftwareSerial XbeeSerial(9, 10);
// a byte to receive data:
char inByte = 0;
int Xbeepower = 6;
void setup()
{
 Serial.begin(115200);Â
 XbeeSerial.begin(9600);
 pinMode(Xbeepower, OUTPUT);
 digitalWrite(Xbeepower, HIGH);
} //end setup
void loop()
{
 // get any incoming data from xbee:
 if (XbeeSerial.available() > 1) {
  // read a byte
  inByte = XbeeSerial.read();
Â
 if (inByte == '0') {
  Serial.println("0");
  XbeeSerial.println("0");
 }
 else if (inByte == '1') {
  Serial.println("1");
  XbeeSerial.println("1");
 }Â
 else if (inByte == '2') {
  Serial.println("2");
  XbeeSerial.println("2");
 }Â
 // do nothing if anything else was received
 else {
  Serial.println("misc");
  XbeeSerial.println("misc");
 }
}
 delay(200);
} //end loop