RadioLib/examples/XBee/XBee_Transmit/XBee_Transmit.ino

70 wiersze
1.7 KiB
Arduino
Czysty Zwykły widok Historia

2018-07-19 14:22:19 +00:00
/*
2019-02-08 14:58:29 +00:00
RadioLib XBee API Transmit Example
2018-07-24 07:47:05 +00:00
This example transmits packets using XBee API mode.
In API mode, many XBee modules can form a mesh network.
IMPORTANT: Before uploading this example, make sure that the XBee module
is running API COORDINATOR firmware!
2019-06-02 13:03:40 +00:00
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
2018-07-24 07:47:05 +00:00
*/
2018-07-19 14:22:19 +00:00
// include the library
2019-02-08 14:58:29 +00:00
#include <RadioLib.h>
2018-07-19 14:22:19 +00:00
2019-06-02 13:03:40 +00:00
// XBee has the following connections:
// TX pin: 9
// RX pin: 8
// RESET pin: 3
2019-12-27 12:18:36 +00:00
XBee bee = new Module(9, 8, 3);
2019-06-02 13:03:40 +00:00
// or using RadioShield
// https://github.com/jgromes/RadioShield
//XBee bee = RadioShield.ModuleA;
2018-07-19 14:22:19 +00:00
void setup() {
Serial.begin(9600);
// initialize XBee module with baudrate 9600
Serial.print(F("[XBee] Initializing ... "));
2018-07-23 10:42:50 +00:00
int state = bee.begin(9600);
2018-07-24 07:47:05 +00:00
if (state == ERR_NONE) {
2018-07-19 14:22:19 +00:00
Serial.println(F("success!"));
} else {
2018-07-23 10:42:50 +00:00
Serial.print(F("failed, code "));
Serial.println(state);
2018-07-24 07:47:05 +00:00
while (true);
2018-07-19 14:22:19 +00:00
}
// set PAN ID to 0x0123456789ABCDEF
Serial.print(F("[XBee] Setting PAN ID ... "));
2018-07-24 07:47:05 +00:00
uint8_t panId[] = {0x01, 0x23, 0x45, 0x67,
2018-07-19 14:22:19 +00:00
0x89, 0xAB, 0xCD, 0xEF};
state = bee.setPanId(panId);
2018-07-24 07:47:05 +00:00
if (state == ERR_NONE) {
2018-07-19 14:22:19 +00:00
Serial.println(F("success!"));
} else {
2018-07-23 10:42:50 +00:00
Serial.print(F("failed, code "));
Serial.println(state);
2018-07-24 07:47:05 +00:00
while (true);
2018-07-19 14:22:19 +00:00
}
}
void loop() {
// transmit data to the destination module
2018-07-24 07:47:05 +00:00
uint8_t dest[] = {0x00, 0x13, 0xA2, 0x00,
2018-07-19 14:22:19 +00:00
0x40, 0xA5, 0x8A, 0x6B};
Serial.print(F("[XBee] Transmitting message ... "));
2018-07-23 10:42:50 +00:00
int state = bee.transmit(dest, "Hello World!");
2018-07-24 07:47:05 +00:00
if (state == ERR_NONE) {
2018-07-19 14:22:19 +00:00
Serial.println(F("success!"));
} else {
2018-07-23 10:42:50 +00:00
Serial.print(F("failed, code "));
Serial.println(state);
2018-07-19 14:22:19 +00:00
}
2018-07-24 07:47:05 +00:00
delay(1000);
2018-07-19 14:22:19 +00:00
}