Hi, I have 2 Xbee’s 1) Coordinator in API mode (connected to arduino) 2) Router AT mode.
Basically router AT will send a digital high low from DIO4. from a simple switch, once every 5 seconds
My arduino tries to read the data with the following function. (of course this is used under void loop)
void readSerial()
{
if (Serial.available()>20){
if(Serial.read()== 0x7E){
byte data1 = Serial.read();
byte data2 = Serial.read();
dataLength = (data1<<8)|data2 ;
Serial.println(dataLength); // data length
for (int i=0; i<=dataLength; i++){
dataList[i] = Serial.read();
Serial.print(dataList[i],HEX);
Serial.print(",");
}
}
This is the output, : 92,0,13,A2,0,40,CC,86,29,1A,D8,1,1,0,10,0,0,10,E9,
(which is normal, i checked up the serial and checksum, everything seems fine)
But however when i put “if (Serial.available()>10)”
This is the output :
92,0,13,A2,0,40,CC,86,FF,29,FF,FF,FF,FF,FF,FF,FF,1A,FF,
Or any number lesser than 20 for that matter. I don’t understand why putting a lesser number mixes up the frame. So far only numbers bigger than 20 work.
My understanding is, “if (Serial.available()>10)” means : if current frame has more than 10bytes, execute the follow commands… and the Router AT is definitely sending out frames with more than 10 bytes. But why is it that the printout seems so weird?