Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Reading XBee API packets from Arduino
#include <AltSoftSerial.h>
AltSoftSerial Xbee; // DOUT -> 8, DIN -> 9
void setup() {
Serial.begin(38400);
Xbee.begin(9600);
}
void loop() {
if (Xbee.available() >= 14) { // Wait for whole packet
if (Xbee.read() == 0x7E) { // Start delimiter of frame
for (int i = 0; i < 4; i++) { Xbee.read(); } // Skip to low byte of src addr
int src = Xbee.read(); // source address
for (int i = 0; i < 6; i++) { Xbee.read(); } // Skip again
levels[src - 1] = random(300,500);
Xbee.read();
}
}
for (int i = 0; i < 16; i++) {
Serial.print(levels[i]);
if (i < 15) Serial.print(' ');
}
Serial.println();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment