XBee - Updated AT examples
This commit is contained in:
parent
b227d0cd19
commit
df54510986
2 changed files with 14 additions and 69 deletions
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* KiteLib XBee AT Receive Example
|
||||
*
|
||||
* This example receives packets using XBee AT mode.
|
||||
* In AT mode, two XBee modules act like a Serial line. Both modules must have
|
||||
* the same PAN ID, and the destination addresses have to be set properly.
|
||||
*
|
||||
* IMPORTANT: Before uplolading this example, make sure that the XBee module is running
|
||||
* AT ROUTER firmware!
|
||||
*/
|
||||
|
||||
// include the library
|
||||
#include <KiteLib.h>
|
||||
|
||||
// XBee module is in slot A on the shield
|
||||
XBee bee = Kite.ModuleA;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
// initialize XBee module with baudrate 9600
|
||||
Serial.print(F("[XBee] Initializing ... "));
|
||||
byte state = bee.begin(9600);
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code 0x"));
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
}
|
||||
|
||||
// set PAN ID to 0123456789ABCDEF
|
||||
Serial.print(F("[XBee] Setting PAN ID ... "));
|
||||
state = bee.setPanId("0123456789ABCDEF");
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code 0x"));
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
}
|
||||
|
||||
// set destination address to the address of the second module
|
||||
Serial.print(F("[XBee] Setting destination address ... "));
|
||||
state = bee.setDestinationAddress("0013A200", "40A58A52");
|
||||
if(state == ERR_NONE) {
|
||||
Serial.println(F("success!"));
|
||||
} else {
|
||||
Serial.print(F("failed, code 0x"));
|
||||
Serial.println(state, HEX);
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read data incoming from XBee and write them to Serial
|
||||
// XBee supports all methods of the Serial class
|
||||
while(bee.available() > 0) {
|
||||
Serial.write(bee.read());
|
||||
}
|
||||
}
|
|
@ -1,19 +1,20 @@
|
|||
/*
|
||||
* KiteLib XBee AT Transmit Example
|
||||
* KiteLib XBee Transparent Operation Example
|
||||
*
|
||||
* This example transmits packets using XBee AT mode.
|
||||
* In AT mode, two XBee modules act like a Serial line. Both modules must have
|
||||
* the same PAN ID, and the destination addresses have to be set properly.
|
||||
* This example transmits packets using XBee Transparent mode.
|
||||
* In Transparent mode, two XBee modules act like a Serial line.
|
||||
* Both modules must have the same PAN ID, and the destination
|
||||
* addresses have to be set properly.
|
||||
*
|
||||
* IMPORTANT: Before uplolading this example, make sure that the XBee module is running
|
||||
* AT COORDINATOR firmware!
|
||||
* IMPORTANT: Before uploading this example, make sure that the XBee modules
|
||||
* are running AT COORDINATOR and AT ROUTER firmware!
|
||||
*/
|
||||
|
||||
// include the library
|
||||
#include <KiteLib.h>
|
||||
|
||||
// XBee module is in slot A on the shield
|
||||
XBee bee = Kite.ModuleA;
|
||||
XBeeSerial bee = Kite.ModuleA;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
@ -53,9 +54,14 @@ void setup() {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
// XBeeSerial supports all methods of the Serial class
|
||||
// read data incoming from Serial port and write them to XBee
|
||||
// XBee supports all methods of the Serial class
|
||||
while(Serial.available() > 0) {
|
||||
bee.write(Serial.read());
|
||||
}
|
||||
|
||||
// read data incoming from XBee and write them to Serial port
|
||||
while(bee.available() > 0) {
|
||||
Serial.write(bee.read());
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue