RadioLib/examples/SX123x/SX123x_Transmit_Blocking/SX123x_Transmit_Blocking.ino

79 wiersze
2.1 KiB
Arduino
Czysty Zwykły widok Historia

2018-07-13 13:36:01 +00:00
/*
RadioLib SX123x Blocking Transmit Example
2018-07-23 10:42:33 +00:00
This example transmits packets using SX1231 FSK radio module.
Other modules from SX123x family can also be used.
2019-02-06 18:39:44 +00:00
NOTE: SX123x modules offer the same features as RF69 and have the same
interface. Please see RF69 examples for examples on AES,
address filtering, interrupts and settings.
2019-06-02 13:03:10 +00:00
Using blocking transmit is not recommended, as it will lead
to inefficient use of processor time!
Instead, interrupt transmit is recommended.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
2018-07-23 10:42:33 +00:00
*/
2018-07-13 13:36:01 +00:00
// include the library
2019-02-08 14:58:29 +00:00
#include <RadioLib.h>
2018-07-13 13:36:01 +00:00
2019-06-02 13:03:10 +00:00
// SX1231 has the following connections:
2019-12-27 12:17:14 +00:00
// CS pin: 10
2019-06-02 13:03:10 +00:00
// DIO0 pin: 2
2019-12-27 12:17:14 +00:00
// RESET pin: 3
SX1231 radio = new Module(10, 2, 3);
2019-06-02 13:03:10 +00:00
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1231 radio = RadioShield.ModuleA;
2018-07-13 13:36:01 +00:00
void setup() {
Serial.begin(9600);
// initialize SX1231 with default settings
Serial.print(F("[SX1231] Initializing ... "));
int state = radio.begin();
2021-11-14 10:41:27 +00:00
if (state == RADIOLIB_ERR_NONE) {
2018-07-13 13:36:01 +00:00
Serial.println(F("success!"));
} else {
2018-07-23 10:42:33 +00:00
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
2018-07-13 13:36:01 +00:00
}
}
// counter to keep track of transmitted packets
int count = 0;
2018-07-13 13:36:01 +00:00
void loop() {
Serial.print(F("[SX1231] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to 256 characters long
String str = "Hello World! #" + String(count++);
int state = radio.transmit(str);
2018-07-13 13:36:01 +00:00
// you can also transmit byte array up to 256 bytes long
/*
2020-03-22 07:11:55 +00:00
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
2018-07-13 13:36:01 +00:00
*/
2018-07-23 10:42:33 +00:00
2021-11-14 10:41:27 +00:00
if (state == RADIOLIB_ERR_NONE) {
2018-07-13 13:36:01 +00:00
// the packet was successfully transmitted
2020-03-22 07:11:55 +00:00
Serial.println(F("success!"));
2018-07-23 10:42:33 +00:00
2021-11-14 10:41:27 +00:00
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
2018-07-13 13:36:01 +00:00
// the supplied packet was longer than 256 bytes
2020-03-22 07:11:55 +00:00
Serial.println(F("too long!"));
2018-07-23 10:42:33 +00:00
2018-07-13 13:36:01 +00:00
}
// wait for a second before transmitting again
delay(1000);
}