Reading XBee API packets from Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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