Try some basic code for an analog sensor reading in API Mode 2 for instance.
You should have 1 Analog Pin turned on as ADC Input.
Code:
// make sure everything we need is in the buffer
if (Serial.available() >= 23) {
startByte = Serial.read();
if (startByte == 0x7E) {
Serial.print(startByte, HEX);
for (int i=0; i < 22; i++) {
Serial.print(", ");
Serial.print(Serial.read(), HEX);
}
}
Serial.println();
}
You'll get something like this:
7E, 0, 12, 92, 0, 7D, 33, A2, 0, 40, AC, BA, 9, 74, 8D, 1, 1, 0, 0, 1, 1, 43, C1
Notice that in my case, my MSB of the 64bit Address has a 0x13 value, and in API MODE 2 (Character Escape), that value is escaped by 0x7D byte and x'ored with 0x20.
So i have an extra byte in reference to the xBee Datasheet, since i'm getting that escaped byte with 0x7D resulting in 0x7D 0x33.
Check this cheat sheet: http://www.tunnelsup.com/images/XBee-Quick-Reference-Guide.pdf
Normally in API Mode you will get 22 bytes, from start byte to Checksum byte. In my case i've got 23 bytes since there's a escape char there...
Play a little bit, and i'm sure you'll get it ok,. Just be aware of the amount of bytes you are expecting and outputing, whether you are printing the Checksum or not, or you have some escaped characters or not, and also if there are any Analog or Digital pins enabled.
That will affect the length of the API Packet for Data RX so watch out for that one, or you'll get ackward results.
Cheers //