Hi,
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)
0.misc
.misc
.10
.0
.0
.21
.1
.32
.2
.2
.2
.4misc
.misc
.0misc
.misc
.misc
.10
.0
.111
.1
.221
.2
.32
.3misc
.misc#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?
Thanks