Upgrade RadioLib to 5.50

This commit is contained in:
lewishe 2022-12-09 16:12:04 +08:00
commit 6301fa4734
208 changed files with 15925 additions and 10099 deletions

View file

@ -57,7 +57,7 @@ void setup()
#else
int state = radio.begin(868.0);
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -72,7 +72,7 @@ void setup()
// start listening for LoRa packets
Serial.print(F("[SX1262] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -113,7 +113,7 @@ void loop()
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1262] Received packet!"));
@ -147,7 +147,7 @@ void loop()
}
#endif
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -24,7 +24,7 @@ SX1262 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUS
//SX1262 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
@ -62,14 +62,14 @@ void setup()
#endif
#ifdef HAS_DISPLAY
if (u8g2) {
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Initializing: FAIL!");
u8g2->sendBuffer();
}
}
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -108,7 +108,7 @@ void loop()
// reset flag
transmittedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));

View file

@ -62,7 +62,7 @@ void setup()
#else
int state = radio.begin(433.0);
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -77,7 +77,7 @@ void setup()
// start listening for LoRa packets
Serial.print(F("[SX1268] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -118,7 +118,7 @@ void loop()
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1268] Received packet!"));
@ -136,7 +136,7 @@ void loop()
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -29,7 +29,7 @@ SX1268 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUS
//SX1268 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
@ -67,14 +67,14 @@ void setup()
#endif
#ifdef HAS_DISPLAY
if (u8g2) {
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Initializing: FAIL!");
u8g2->sendBuffer();
}
}
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -113,7 +113,7 @@ void loop()
// reset flag
transmittedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));

View file

@ -60,7 +60,7 @@ void setup()
#else
int state = radio.begin(LoRa_frequency);
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -76,14 +76,14 @@ void setup()
state = radio.startReceive();
#ifdef HAS_DISPLAY
if (u8g2) {
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Initializing: FAIL!");
u8g2->sendBuffer();
}
}
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -125,7 +125,7 @@ void loop()
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1276] Received packet!"));
@ -160,7 +160,7 @@ void loop()
u8g2->sendBuffer();
}
#endif
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("[SX1276] CRC error!"));

View file

@ -37,14 +37,14 @@ void setup()
#endif
#ifdef HAS_DISPLAY
if (u8g2) {
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Initializing: FAIL!");
u8g2->sendBuffer();
}
}
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -71,7 +71,7 @@ void loop()
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F(" success!"));

View file

@ -61,14 +61,14 @@ void setup()
#ifdef HAS_DISPLAY
if (u8g2) {
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Initializing: FAIL!");
u8g2->sendBuffer();
}
}
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -82,7 +82,7 @@ void setup()
// start listening for LoRa packets
Serial.print(F("[SX1278] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -123,7 +123,7 @@ void loop()
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1278] Received packet!"));
@ -158,7 +158,7 @@ void loop()
u8g2->sendBuffer();
}
#endif
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("[SX1278] CRC error!"));

View file

@ -63,14 +63,14 @@ void setup()
int state = radio.begin(LoRa_frequency);
#endif
if (u8g2) {
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Initializing: FAIL!");
u8g2->sendBuffer();
}
}
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -85,7 +85,7 @@ void setup()
// start listening for LoRa packets
Serial.print(F("[SX1278] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -126,7 +126,7 @@ void loop()
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1278] Received packet!"));
@ -163,7 +163,7 @@ void loop()
}
#endif
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("[SX1278] CRC error!"));

View file

@ -37,14 +37,14 @@ void setup()
#endif
#ifdef HAS_DISPLAY
if (u8g2) {
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Initializing: FAIL!");
u8g2->sendBuffer();
}
}
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -71,7 +71,7 @@ void loop()
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F(" success!"));

View file

@ -23,7 +23,7 @@
SX1278 radio = new Module(RADIO_CS_PIN, RADIO_DI0_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
// save transmission state between loops
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
@ -62,14 +62,14 @@ void setup()
#endif
#ifdef HAS_DISPLAY
if (u8g2) {
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Initializing: FAIL!");
u8g2->sendBuffer();
}
}
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -111,7 +111,7 @@ void loop()
// reset flag
transmittedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));

View file

@ -60,14 +60,14 @@ void setup()
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.begin();
if (u8g2) {
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Initializing: FAIL!");
u8g2->sendBuffer();
}
}
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -93,7 +93,7 @@ void setup()
// start listening for LoRa packets
Serial.print(F("[SX1280] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -137,7 +137,7 @@ void loop()
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1280] Received packet!"));
@ -170,7 +170,7 @@ void loop()
}
#endif
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("[SX1280] CRC error!"));

View file

@ -24,7 +24,7 @@
SX1280 radio = new Module(RADIO_CS_PIN, RADIO_DIO1_PIN, RADIO_RST_PIN, RADIO_BUSY_PIN);
// save transmission state between loops
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
@ -60,14 +60,14 @@ void setup()
int state = radio.begin();
#ifdef HAS_DISPLAY
if (u8g2) {
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
u8g2->clearBuffer();
u8g2->drawStr(0, 12, "Initializing: FAIL!");
u8g2->sendBuffer();
}
}
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -120,7 +120,7 @@ void loop()
// reset flag
transmittedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));

View file

@ -107,7 +107,7 @@ void setup()
int state = radio.begin(LoRa_frequency);
#endif
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -181,7 +181,7 @@ void SenderLoop(void)
snprintf(buff[0], sizeof(buff[0]), "T-Beam Lora Sender");
// Send data every 3 seconds
if (millis() - loraLoopMillis > 3000) {
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
transmissionState = radio.startTransmit(String(loraLoopMillis).c_str());
// check if the previous transmission finished
if (receivedFlag) {
@ -190,7 +190,7 @@ void SenderLoop(void)
enableInterrupt = false;
// reset flag
receivedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
// NOTE: when using interrupt-driven transmit method,
@ -250,7 +250,7 @@ void ReceiveLoop(void)
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[RADIO] Received packet!"));
@ -269,7 +269,7 @@ void ReceiveLoop(void)
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
@ -304,7 +304,7 @@ void ButtonHandleEvent(AceButton *, uint8_t eventType, uint8_t buttonState)
if (funcSelectIndex == 2) {
Serial.print(F("[RADIO] Starting to listen ... "));
int state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));

View file

@ -1 +0,0 @@
{"type": "library", "name": "RadioLib", "version": "4.0.6", "spec": {"owner": "jgromes", "id": 5795, "name": "RadioLib", "requirements": null, "url": null}}

View file

@ -52,7 +52,7 @@ It is very easy to write code that machine can read. It is much harder to write
// build a temporary buffer (first block)
uint8_t* data = new uint8_t[len + 1];
if(!data) {
return(ERR_MEMORY_ALLOCATION_FAILED);
return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
}
// read the received data (second block)
@ -73,12 +73,12 @@ Sometimes, RadioLib might be used in critical applications where dynamic memory
```c++
// build a temporary buffer
#ifdef RADIOLIB_STATIC_ONLY
#if defined(RADIOLIB_STATIC_ONLY)
uint8_t data[RADIOLIB_STATIC_ARRAY_SIZE + 1];
#else
uint8_t* data = new uint8_t[length + 1];
if(!data) {
return(ERR_MEMORY_ALLOCATION_FAILED);
return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
}
#endif
@ -86,7 +86,7 @@ Sometimes, RadioLib might be used in critical applications where dynamic memory
readData(data, length);
// deallocate temporary buffer
#ifndef RADIOLIB_STATIC_ONLY
#if !defined(RADIOLIB_STATIC_ONLY)
delete[] data;
#endif
```
@ -98,7 +98,7 @@ During development, it can be useful to have access to the low level drivers, su
class Module {
void publicMethod();
#ifndef RADIOLIB_GODMODE
#if defined(RADIOLIB_GODMODE)
private:
#endif

View file

@ -2,20 +2,18 @@
### _One radio library to rule them all!_
## Universal wireless communication library for Arduino
## Universal wireless communication library for embedded devices
## See the [Wiki](https://github.com/jgromes/RadioLib/wiki) for further information. See the [GitHub Pages](https://jgromes.github.io/RadioLib) for detailed and up-to-date API reference.
RadioLib allows its users to integrate all sorts of different wireless communication modules, protocols and even digital modes into a single consistent system.
Want to add a Bluetooth interface to your LoRa network? Sure thing! Do you just want to go really old-school and play around with radio teletype, slow-scan TV, or even Hellschreiber using nothing but a cheap radio module? Why not!
RadioLib was originally created as a driver for [__RadioShield__](https://github.com/jgromes/RadioShield), but it can be used to control as many different wireless modules as you like - or at least as many as your Arduino can handle!
RadioLib was originally created as a driver for [__RadioShield__](https://github.com/jgromes/RadioShield), but it can be used to control as many different wireless modules as you like - or at least as many as your microcontroller can handle!
### Supported modules:
* __CC1101__ FSK radio module
* __ESP8266__ WiFi module
* __HC05__ Bluetooth module
* __JDY08__ BLE module
* __LLCC68__ LoRa module
* __nRF24L01__ 2.4 GHz module
* __RF69__ FSK/OOK radio module
* __RFM2x__ series FSK modules (RFM22, RM23)
@ -25,14 +23,9 @@ RadioLib was originally created as a driver for [__RadioShield__](https://github
* __SX127x__ series LoRa modules (SX1272, SX1273, SX1276, SX1277, SX1278, SX1279)
* __SX128x__ series LoRa/GFSK/BLE/FLRC modules (SX1280, SX1281, SX1282)
* __SX1231__ FSK/OOK radio module
* __XBee__ modules (S2B)
### Supported protocols and digital modes:
* __MQTT__ for modules:
ESP8266
* __HTTP__ for modules:
ESP8266
* __AX.25__ using 2-FSK or AFSK for modules:
* [__AX.25__](https://www.sigidwiki.com/wiki/PACKET) using 2-FSK or AFSK for modules:
SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, RFM2x and Si443x
* [__RTTY__](https://www.sigidwiki.com/wiki/RTTY) using 2-FSK or AFSK for modules:
SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x
@ -42,8 +35,12 @@ SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x
SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, RFM2x and Si443x
* [__Hellschreiber__](https://www.sigidwiki.com/wiki/Hellschreiber) using 2-FSK or AFSK for modules:
SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x
* [__APRS__](https://www.sigidwiki.com/wiki/APRS) using AFSK for modules:
SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x
* [__POCSAG__](https://www.sigidwiki.com/wiki/POCSAG) using 2-FSK for modules:
SX127x, RFM9x, RF69, SX1231, CC1101, nRF24L01, RFM2x and Si443x
### Supported platforms:
### Supported Arduino platforms:
* __Arduino__
* [__AVR__](https://github.com/arduino/ArduinoCore-avr) - Arduino Uno, Mega, Leonardo, Pro Mini, Nano etc.
* [__mbed__](https://github.com/arduino/ArduinoCore-mbed) - Arduino Nano 33 BLE and Arduino Portenta H7
@ -69,12 +66,25 @@ SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x
* [__STM32__ (official core)](https://github.com/stm32duino/Arduino_Core_STM32) - STM32 Nucleo, Discovery, Maple, BluePill, BlackPill etc.
* [__STM32__ (unofficial core)](https://github.com/rogerclarkmelbourne/Arduino_STM32) - STM32F1 and STM32F4-based boards
The list above is by no means exhaustive. Most of RadioLib code is independent of the used platform, so as long as your board is running some Arduino-compatible core, RadioLib should work. Compilation of all examples is tested for all platforms prior to releasing new version.
* __MCUdude__
* [__MegaCoreX__](https://github.com/MCUdude/MegaCoreX) - megaAVR-0 series (ATmega4809, ATmega3209 etc.)
* [__MegaCore__](https://github.com/MCUdude/MegaCore) - AVR (ATmega1281, ATmega640 etc.)
* __Raspberry Pi__
* [__RP2040__](https://github.com/arduino/ArduinoCore-mbed) - Raspberry Pi Pico and Arduino Nano RP2040 Connect
* [__Raspberry Pi__](https://github.com/me-no-dev/RasPiArduino) - Arduino framework for RaspberryPI
* __Heltec__
* [__CubeCell__](https://github.com/HelTecAutomation/CubeCell-Arduino) - ASR650X series (CubeCell-Board, CubeCell-Capsule, CubeCell-Module etc.)
* __PJRC__
* [__Teensy__](https://github.com/PaulStoffregen/cores) - Teensy 2.x, 3.x and 4.x boards
The list above is by no means exhaustive - RadioLib code is independent of the used platform! Compilation of all examples is tested for all platforms officially supported prior to releasing new version.
### In development:
* __SIM800C__ GSM module
* __AX5243__ FSK module
* __LoRaWAN__ protocol for SX127x, RFM9x and SX126x modules
* __APRS__ protocol for all the modules that can transmit AX.25
* ___and more!___
## Frequently Asked Questions
@ -86,4 +96,4 @@ First of all, take a look at the [examples](https://github.com/jgromes/RadioLib/
The fastest way to get help is by creating an [issue](https://github.com/jgromes/RadioLib/issues/new/choose) using the appropriate template. It is also highly recommended to try running the examples first - their functionality is tested from time to time and they should work. Finally, RadioLib is still under development, which means that sometimes, backwards-incompatible changes might be introduced. Though these are kept at minimum, sometimes it is unavoidable. You can check the [release changelog](https://github.com/jgromes/RadioLib/releases) to find out if there's been such a major change recently.
### RadioLib doesn't support my module! What should I do?
Start by creating new issue (if it doesn't exist yet). If you have some experience with Arduino and C/C++ in general, you can try to add the support yourself! Use the template files in `/extras/` folder to get started. This is by far the fastest way to implement new modules into RadioLib, since I can't be working on everything all the time. If you don't trust your programming skills enough to have a go at it yourself, don't worry. I will try to implement all requested modules, but it will take me a while.
Start by creating new issue (if it doesn't exist yet). If you have some experience with microcontrollers and C/C++ in general, you can try to add the support yourself! Use the template files in `/extras/` folder to get started. This is by far the fastest way to implement new modules into RadioLib, since I can't be working on everything all the time. If you don't trust your programming skills enough to have a go at it yourself, don't worry. I will try to implement all requested modules, but it will take me a while.

View file

@ -51,7 +51,18 @@ void setup() {
// (RF69, CC1101,, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize AFSK client
Serial.print(F("[AFSK] Initializing ... "));
state = audio.begin();
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));

View file

@ -95,7 +95,7 @@
#define NOTE_DS8 4978
#define REST 0
// notes of the moledy followed by the duration.
// notes of the melody followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!

View file

@ -46,10 +46,21 @@ void setup() {
int state = radio.beginFSK();
// when using one of the non-LoRa modules for AFSK
// (RF69, CC1101,, Si4432 etc.), use the basic begin() method
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize AFSK client
Serial.print(F("[AFSK] Initializing ... "));
state = audio.begin();
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -63,10 +74,12 @@ void loop() {
// same as Arduino tone() function
// 400 Hz tone
Serial.print(F("[AFSK] 400 Hz tone ... "));
audio.tone(400);
delay(1000);
// silence
Serial.println(F("done!"));
audio.noTone();
delay(1000);

View file

@ -0,0 +1,101 @@
/*
RadioLib AM-modulated AFSK Example
This example shows hot to send AM-modulated
audio FSK tones using SX1278's OOK modem.
Other modules that can be used for AFSK:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
SX1278 radio = new Module(10, 2, 9);
// create AFSK client instance using the FSK module
// this requires connection to the module direct
// input pin, here connected to Arduino pin 5
// SX127x/RFM9x: DIO2
// RF69: DIO2
// SX1231: DIO2
// CC1101: GDO2
AFSKClient audio(&radio, 5);
void setup() {
Serial.begin(9600);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
// when using one of the non-LoRa modules for AFSK
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize AFSK client
Serial.print(F("[AFSK] Initializing ... "));
state = audio.begin();
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// after that, set mode to OOK
Serial.print(F("[SX1278] Switching to OOK ... "));
state = radio.setOOK(true);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
}
void loop() {
// AFSKClient can be used to transmit tones,
// same as Arduino tone() function
// 400 Hz tone
Serial.print(F("[AFSK] 400 Hz tone ... "));
audio.tone(400);
delay(1000);
// silence
Serial.println(F("done!"));
audio.noTone();
delay(1000);
// AFSKClient can also be used to transmit HAM-friendly
// RTTY, Morse code, Hellschreiber, SSTV and AX.25.
// Details on how to use AFSK are in the example
// folders for each of the above modes.
// CAUTION: Unlike standard AFSK, the result when using OOK
// must be demodulated as AM!
}

View file

@ -0,0 +1,111 @@
/*
RadioLib APRS Mic-E Example
This example sends APRS position reports
encoded in the Mic-E format using SX1278's
FSK modem. The data is modulated as AFSK
at 1200 baud using Bell 202 tones.
DO NOT transmit in APRS bands unless
you have a ham radio license!
Other modules that can be used for APRS:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- nRF24
- Si443x/RFM2x
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
// create AFSK client instance using the FSK module
// pin 5 is connected to SX1278 DIO2
AFSKClient audio(&radio, 5);
// create AX.25 client instance using the AFSK instance
AX25Client ax25(&audio);
// create APRS client instance using the AX.25 client
APRSClient aprs(&ax25);
void setup() {
Serial.begin(9600);
// initialize SX1278
// NOTE: moved to ISM band on purpose
// DO NOT transmit in APRS bands without ham radio license!
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
// when using one of the non-LoRa modules for AX.25
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize AX.25 client
Serial.print(F("[AX.25] Initializing ... "));
// source station callsign: "N7LEM"
// source station SSID: 0
// preamble length: 8 bytes
state = ax25.begin("N7LEM");
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize APRS client
Serial.print(F("[APRS] Initializing ... "));
// symbol: '>' (car)
state = aprs.begin('>');
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
}
void loop() {
Serial.print(F("[APRS] Sending Mic-E position ... "));
int state = aprs.sendMicE(49.1945, 16.6000, 120, 10, RADIOLIB_APRS_MIC_E_TYPE_EN_ROUTE);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait one minute before transmitting again
delay(60000);
}

View file

@ -0,0 +1,123 @@
/*
RadioLib APRS Position Example
This example sends APRS position reports
using SX1278's FSK modem. The data is
modulated as AFSK at 1200 baud using Bell
202 tones.
DO NOT transmit in APRS bands unless
you have a ham radio license!
Other modules that can be used for APRS:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- nRF24
- Si443x/RFM2x
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
// create AFSK client instance using the FSK module
// pin 5 is connected to SX1278 DIO2
AFSKClient audio(&radio, 5);
// create AX.25 client instance using the AFSK instance
AX25Client ax25(&audio);
// create APRS client instance using the AX.25 client
APRSClient aprs(&ax25);
void setup() {
Serial.begin(9600);
// initialize SX1278
// NOTE: moved to ISM band on purpose
// DO NOT transmit in APRS bands without ham radio license!
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK(434.0);
// when using one of the non-LoRa modules for AX.25
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize AX.25 client
Serial.print(F("[AX.25] Initializing ... "));
// source station callsign: "N7LEM"
// source station SSID: 0
// preamble length: 8 bytes
state = ax25.begin("N7LEM");
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize APRS client
Serial.print(F("[APRS] Initializing ... "));
// symbol: '>' (car)
state = aprs.begin('>');
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
}
void loop() {
Serial.print(F("[APRS] Sending position ... "));
// send a location without message or timestamp
int state = aprs.sendPosition("N0CALL", 0, "4911.67N", "01635.96E");
delay(500);
// send a location with message and without timestamp
state |= aprs.sendPosition("N0CALL", 0, "4911.67N", "01635.96E", "I'm here!");
delay(500);
// send a location with message and timestamp
state |= aprs.sendPosition("N0CALL", 0, "4911.67N", "01635.96E", "I'm here!", "093045z");
delay(500);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait one minute before transmitting again
delay(60000);
}

View file

@ -58,7 +58,7 @@ void setup() {
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -72,7 +72,7 @@ void setup() {
// source station SSID: 0
// preamble length: 8 bytes
state = ax25.begin("N7LEM");
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -90,14 +90,14 @@ void loop() {
// control field: UI, P/F not used, unnumbered frame
// protocol identifier: no layer 3 protocol implemented
// information field: "Hello World!"
AX25Frame frameUI("NJ7P", 0, "N7LEM", 0, AX25_CONTROL_U_UNNUMBERED_INFORMATION |
AX25_CONTROL_POLL_FINAL_DISABLED | AX25_CONTROL_UNNUMBERED_FRAME,
AX25_PID_NO_LAYER_3, "Hello World (unnumbered)!");
AX25Frame frameUI("NJ7P", 0, "N7LEM", 0, RADIOLIB_AX25_CONTROL_U_UNNUMBERED_INFORMATION |
RADIOLIB_AX25_CONTROL_POLL_FINAL_DISABLED | RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME,
RADIOLIB_AX25_PID_NO_LAYER_3, "Hello World (unnumbered)!");
// send the frame
Serial.print(F("[AX.25] Sending UI frame ... "));
int state = ax25.sendFrame(&frameUI);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
@ -116,8 +116,8 @@ void loop() {
// source station callsign: "N7LEM"
// source station SSID: 0
// control field: RR, P/F not used, supervisory frame
AX25Frame frameRR("NJ7P", 0, "N7LEM", 0, AX25_CONTROL_S_RECEIVE_READY |
AX25_CONTROL_POLL_FINAL_DISABLED | AX25_CONTROL_SUPERVISORY_FRAME);
AX25Frame frameRR("NJ7P", 0, "N7LEM", 0, RADIOLIB_AX25_CONTROL_S_RECEIVE_READY |
RADIOLIB_AX25_CONTROL_POLL_FINAL_DISABLED | RADIOLIB_AX25_CONTROL_SUPERVISORY_FRAME);
// set receive sequence number (0 - 7)
frameRR.setRecvSequence(0);
@ -125,7 +125,7 @@ void loop() {
// send the frame
Serial.print(F("[AX.25] Sending RR frame ... "));
state = ax25.sendFrame(&frameRR);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
@ -146,8 +146,8 @@ void loop() {
// control field: P/F not used, information frame
// protocol identifier: no layer 3 protocol implemented
// information field: "Hello World (numbered)!"
AX25Frame frameI("NJ7P", 0, "N7LEM", 0, AX25_CONTROL_POLL_FINAL_DISABLED |
AX25_CONTROL_INFORMATION_FRAME, AX25_PID_NO_LAYER_3,
AX25Frame frameI("NJ7P", 0, "N7LEM", 0, RADIOLIB_AX25_CONTROL_POLL_FINAL_DISABLED |
RADIOLIB_AX25_CONTROL_INFORMATION_FRAME, RADIOLIB_AX25_PID_NO_LAYER_3,
"Hello World (numbered)!");
// set receive sequence number (0 - 7)
@ -159,7 +159,7 @@ void loop() {
// send the frame
Serial.print(F("[AX.25] Sending I frame ... "));
state = ax25.sendFrame(&frameI);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));

View file

@ -44,14 +44,13 @@ void setup() {
Serial.print(F("[SX1278] Initializing ... "));
// carrier frequency: 434.0 MHz
// bit rate: 1.2 kbps (1200 baud 2-FSK AX.25)
// frequency deviation: 0.5 kHz (1200 baud 2-FSK AX.25)
int state = radio.beginFSK(434.0, 1.2, 0.5);
int state = radio.beginFSK(434.0, 1.2);
// when using one of the non-LoRa modules for AX.25
// (RF69, CC1101,, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -65,7 +64,7 @@ void setup() {
// source station SSID: 0
// preamble length: 8 bytes
state = ax25.begin("N7LEM");
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -80,7 +79,7 @@ void loop() {
// destination station callsign: "NJ7P"
// destination station SSID: 0
int state = ax25.transmit("Hello World!", "NJ7P");
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));

View file

@ -53,7 +53,7 @@ void setup() {
// (RF69, CC1101,, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -67,13 +67,29 @@ void setup() {
// source station SSID: 0
// preamble length: 8 bytes
state = ax25.begin("N7LEM");
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// Sometimes, it may be required to adjust audio
// frequencies to match the expected 1200/2200 Hz tones.
// The following method will offset mark frequency by
// 100 Hz up and space frequency by 100 Hz down
/*
Serial.print(F("[AX.25] Setting correction ... "));
state = ax25.setCorrection(100, -100);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
*/
}
void loop() {
@ -82,7 +98,7 @@ void loop() {
// destination station callsign: "NJ7P"
// destination station SSID: 0
int state = ax25.transmit("Hello World!", "NJ7P");
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));

View file

@ -36,7 +36,7 @@ void setup() {
// initialize CC1101 with default settings
Serial.print(F("[CC1101] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -58,7 +58,7 @@ void loop() {
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -77,7 +77,11 @@ void loop() {
Serial.print(F("[CC1101] LQI:\t\t"));
Serial.println(radio.getLQI());
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -34,7 +34,7 @@ void setup() {
// initialize CC1101 with default settings
Serial.print(F("[CC1101] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -51,7 +51,7 @@ void setup() {
// 0xFF will be used.
Serial.print(F("[CC1101] Setting node address ... "));
state = radio.setNodeAddress(0x01, 1);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -65,7 +65,7 @@ void setup() {
/*
Serial.print(F("[CC1101] Disabling address filtering ... "));
state == radio.disableAddressFiltering();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -88,7 +88,7 @@ void loop() {
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -107,7 +107,7 @@ void loop() {
Serial.print(F("[CC1101] LQI:\t\t"));
Serial.println(radio.getLQI());
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -39,7 +39,7 @@ void setup() {
// initialize CC1101 with default settings
Serial.print(F("[CC1101] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -54,7 +54,7 @@ void setup() {
// start listening for packets
Serial.print(F("[CC1101] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -82,6 +82,9 @@ volatile bool enableInterrupt = true;
// is received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -112,7 +115,7 @@ void loop() {
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[CC1101] Received packet!"));
@ -131,7 +134,7 @@ void loop() {
Serial.print(F("[CC1101] LQI:\t\t"));
Serial.println(radio.getLQI());
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -33,7 +33,7 @@ CC1101 radio1 = new Module(10, 2, RADIOLIB_NC, 3);
// GDO0 pin: 4
// RST pin: unused
// GDO2 pin: 5 (optional)
CC1101 radio2 = new Module(9, 4, RADIOLIB_NC, 53);
CC1101 radio2 = new Module(9, 4, RADIOLIB_NC, 5);
// or using RadioShield
// https://github.com/jgromes/RadioShield
@ -45,7 +45,7 @@ void setup() {
// initialize CC1101 with default settings
Serial.print(F("[CC1101] Initializing ... "));
int state = radio1.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -62,7 +62,7 @@ void setup() {
// output power: 7 dBm
// preamble length: 32 bits
state = radio2.begin(434.0, 32.0, 60.0, 250.0, 7, 32);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -74,42 +74,42 @@ void setup() {
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
if (radio1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) {
if (radio1.setFrequency(433.5) == RADIOLIB_ERR_INVALID_FREQUENCY) {
Serial.println(F("[CC1101] Selected frequency is invalid for this module!"));
while (true);
}
// set bit rate to 100.0 kbps
state = radio1.setBitRate(100.0);
if (state == ERR_INVALID_BIT_RATE) {
if (state == RADIOLIB_ERR_INVALID_BIT_RATE) {
Serial.println(F("[CC1101] Selected bit rate is invalid for this module!"));
while (true);
} else if (state == ERR_INVALID_BIT_RATE_BW_RATIO) {
} else if (state == RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO) {
Serial.println(F("[CC1101] Selected bit rate to bandwidth ratio is invalid!"));
Serial.println(F("[CC1101] Increase receiver bandwidth to set this bit rate."));
while (true);
}
// set receiver bandwidth to 250.0 kHz
if (radio1.setRxBandwidth(250.0) == ERR_INVALID_RX_BANDWIDTH) {
if (radio1.setRxBandwidth(250.0) == RADIOLIB_ERR_INVALID_RX_BANDWIDTH) {
Serial.println(F("[CC1101] Selected receiver bandwidth is invalid for this module!"));
while (true);
}
// set allowed frequency deviation to 10.0 kHz
if (radio1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) {
if (radio1.setFrequencyDeviation(10.0) == RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION) {
Serial.println(F("[CC1101] Selected frequency deviation is invalid for this module!"));
while (true);
}
// set output power to 5 dBm
if (radio1.setOutputPower(5) == ERR_INVALID_OUTPUT_POWER) {
if (radio1.setOutputPower(5) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
Serial.println(F("[CC1101] Selected output power is invalid for this module!"));
while (true);
}
// 2 bytes can be set as sync word
if (radio1.setSyncWord(0x01, 0x23) == ERR_INVALID_SYNC_WORD) {
if (radio1.setSyncWord(0x01, 0x23) == RADIOLIB_ERR_INVALID_SYNC_WORD) {
Serial.println(F("[CC1101] Selected sync word is invalid for this module!"));
while (true);
}

View file

@ -21,7 +21,7 @@
// CS pin: 10
// GDO0 pin: 2
// RST pin: unused
// GDO2 pin: 3 (optional)
// GDO2 pin: 3
CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3);
// or using RadioShield
@ -34,7 +34,7 @@ void setup() {
// initialize CC1101 with default settings
Serial.print(F("[CC1101] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -55,11 +55,11 @@ void loop() {
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 64 bytes
Serial.println(F("too long!"));

View file

@ -34,7 +34,7 @@ void setup() {
// initialize CC1101 with default settings
Serial.print(F("[CC1101] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -51,7 +51,7 @@ void setup() {
// 0xFF will be used.
Serial.print(F("[CC1101] Setting node address ... "));
state = radio.setNodeAddress(0x01, 1);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -65,7 +65,7 @@ void setup() {
/*
Serial.print(F("[CC1101] Disabling address filtering ... "));
state == radio.disableAddressFiltering();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -87,11 +87,11 @@ void loop() {
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 255 bytes
Serial.println(F("too long!"));

View file

@ -22,7 +22,7 @@
// CS pin: 10
// GDO0 pin: 2
// RST pin: unused
// GDO2 pin: 3 (optional)
// GDO2 pin: 3
CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3);
// or using RadioShield
@ -30,7 +30,7 @@ CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3);
//CC1101 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
@ -38,7 +38,7 @@ void setup() {
// initialize CC1101 with default settings
Serial.print(F("[CC1101] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -48,7 +48,10 @@ void setup() {
// set the function that will be called
// when packet transmission is finished
radio.setGdo0Action(setFlag);
// NOTE: Unlike other modules (such as SX127x),
// different GDOx pins are used for
// transmit and receive interrupts!
radio.setGdo2Action(setFlag);
// start transmitting the first packet
Serial.print(F("[CC1101] Sending first packet ... "));
@ -75,6 +78,9 @@ volatile bool enableInterrupt = true;
// is transmitted by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -95,7 +101,7 @@ void loop() {
// reset flag
transmittedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
@ -109,6 +115,11 @@ void loop() {
}
// clean up after transmission is finished
// this will ensure transmitter is disabled,
// RF switch is powered down etc.
radio.finishTransmit();
// wait a second before transmitting again
delay(1000);

View file

@ -0,0 +1,142 @@
/*
RadioLib FSK4 Transmit Example
This example sends an example FSK-4 'Horus Binary' message
using SX1278's FSK modem.
This signal can be demodulated using a SSB demodulator (SDR or otherwise),
and horusdemodlib: https://github.com/projecthorus/horusdemodlib/wiki
Other modules that can be used for FSK4:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- SX126x
- nRF24
- Si443x/RFM2x
- SX128x
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
// create FSK4 client instance using the FSK module
FSK4Client fsk4(&radio);
// An encoded Horus Binary telemetry packet.
// Refer here for packet format information:
// https://github.com/projecthorus/horusdemodlib/wiki/2---Modem-Details#horus-binary-v1-mode-4-fsk
// After demodulation, deinterleaving, and descrambling, this results in a packet:
// 00000001172D0000000000000000D20463010AFF2780
// This decodes to the Habitat-compatible telemetry string:
// $$4FSKTEST,0,01:23:45,0.00000,0.00000,1234,99,1,10,5.00*ABCD
int horusPacketLen = 45;
byte horusPacket[] = {
0x45, 0x24, 0x24, 0x48, 0x2F, 0x12, 0x16, 0x08, 0x15, 0xC1,
0x49, 0xB2, 0x06, 0xFC, 0x92, 0xEB, 0x93, 0xD7, 0xEE, 0x5D,
0x35, 0xA0, 0x91, 0xDA, 0x8D, 0x5F, 0x85, 0x6B, 0x63, 0x03,
0x6B, 0x60, 0xEA, 0xFE, 0x55, 0x9D, 0xF1, 0xAB, 0xE5, 0x5E,
0xDB, 0x7C, 0xDB, 0x21, 0x5A, 0x19
};
void setup() {
Serial.begin(9600);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
// when using one of the non-LoRa modules for FSK4
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize FSK4 client
// NOTE: FSK4 frequency shift will be rounded
// to the nearest multiple of frequency step size.
// The exact value depends on the module:
// SX127x/RFM9x - 61 Hz
// RF69 - 61 Hz
// CC1101 - 397 Hz
// SX126x - 1 Hz
// nRF24 - 1000000 Hz
// Si443x/RFM2x - 156 Hz
// SX128x - 198 Hz
Serial.print(F("[FSK4] Initializing ... "));
// low ("space") frequency: 434.0 MHz
// frequency shift: 270 Hz
// baud rate: 100 baud
state = fsk4.begin(434.0, 270, 100);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// sometimes, it may be needed to set some manual corrections
// this can be done for tone frequencies,
// as well as tone lengths
/*
// set frequency shift offsets to -120, 60, 0 and 60 Hz and decrease tone length to 95%
int offsets[4] = { -120, -60, 0, 60 };
Serial.print(F("[FSK4] Setting corrections ... "));
state = fsk4.setCorrection(offsets, 0.95);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
*/
}
void loop() {
Serial.print(F("[FSK4] Sending FSK4 data packet ... "));
// send out idle condition for 1000 ms
fsk4.idle();
delay(1000);
// FSK4Client supports binary write methods
// send some bytes as a preamble
for(int i = 0; i < 8; i++) {
fsk4.write(0x1B);
}
// now send the encoded packet
fsk4.write(horusPacket, horusPacketLen);
Serial.println(F("done!"));
// wait for a second before transmitting again
delay(1000);
}

View file

@ -0,0 +1,135 @@
/*
RadioLib FSK4 Transmit AFSK Example
This example sends an example FSK-4 'Horus Binary' message
using SX1278's FSK modem. The data is modulated as AFSK.
This signal can be demodulated using an FM demodulator (SDR or otherwise),
and horusdemodlib: https://github.com/projecthorus/horusdemodlib/wiki
Other modules that can be used for FSK4:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- Si443x/RFM2x
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
// create AFSK client instance using the FSK module
// pin 5 is connected to SX1278 DIO2
AFSKClient audio(&radio, 5);
// create FSK4 client instance using the AFSK instance
FSK4Client fsk4(&audio);
// An encoded Horus Binary telemetry packet.
// Refer here for packet format information:
// https://github.com/projecthorus/horusdemodlib/wiki/2---Modem-Details#horus-binary-v1-mode-4-fsk
// After demodulation, deinterleaving, and descrambling, this results in a packet:
// 00000001172D0000000000000000D20463010AFF2780
// This decodes to the Habitat-compatible telemetry string:
// $$4FSKTEST,0,01:23:45,0.00000,0.00000,1234,99,1,10,5.00*ABCD
int horusPacketLen = 45;
byte horusPacket[] = {
0x45, 0x24, 0x24, 0x48, 0x2F, 0x12, 0x16, 0x08, 0x15, 0xC1,
0x49, 0xB2, 0x06, 0xFC, 0x92, 0xEB, 0x93, 0xD7, 0xEE, 0x5D,
0x35, 0xA0, 0x91, 0xDA, 0x8D, 0x5F, 0x85, 0x6B, 0x63, 0x03,
0x6B, 0x60, 0xEA, 0xFE, 0x55, 0x9D, 0xF1, 0xAB, 0xE5, 0x5E,
0xDB, 0x7C, 0xDB, 0x21, 0x5A, 0x19
};
void setup() {
Serial.begin(9600);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
// when using one of the non-LoRa modules for RTTY
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize FSK4 client
// NOTE: Unlike FSK FSK4, AFSK requires no rounding of
// the frequency shift.
Serial.print(F("[FSK4] Initializing ... "));
// low ("space") frequency: 434.0 MHz
// frequency shift: 270 Hz
// baud rate: 100 baud
state = fsk4.begin(400, 270, 100);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// sometimes, it may be needed to set some manual corrections
// this can be done for tone frequencies,
// as well as tone lengths
/*
// set audio tone offsets to -10, 20, 0 and 5 Hz and decrease tone length to 95%
int offsets[4] = { -10, 20, 0, 5 };
Serial.print(F("[FSK4] Setting corrections ... "));
state = fsk4.setCorrection(offsets, 0.95);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
*/
}
void loop() {
Serial.print(F("[FSK4] Sending FSK4 data packet ... "));
// send out idle condition for 500 ms
fsk4.idle();
delay(1000);
// FSK4Client supports binary write methods
// send some bytes as a preamble
for(int i = 0; i < 8; i++) {
fsk4.write(0x1B);
}
// now send the encoded packet
fsk4.write(horusPacket, horusPacketLen);
Serial.println(F("done!"));
// wait for a second before transmitting again
delay(1000);
}

View file

@ -1,43 +0,0 @@
/*
RadioLib HC05 Example
This example sends data using HC05 Bluetooth module.
HC05 works exactly like a Serial line, data are sent to the paired device.
The default pairing code for HC05 is 1234 or 1111.
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// HC05 has the following connections:
// TX pin: 9
// RX pin: 8
HC05 bluetooth = new Module(9, 8);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//HC05 bluetooth = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize HC05
// baudrate: 9600 baud
bluetooth.begin(9600);
}
void loop() {
// HC05 supports all methods of the Serial class
// read data incoming from Serial port and write them to Bluetooth
while (Serial.available() > 0) {
bluetooth.write(Serial.read());
}
// read data incoming from Bluetooth and write them to Serial port
while (bluetooth.available() > 0) {
Serial.write(bluetooth.read());
}
}

View file

@ -1,83 +0,0 @@
/*
RadioLib HTTP GET Example
This example sends HTTP GET request using ESP8266 WiFi module.
Please note that the response will be saved including header. HTTP header size
can easily exceed Arduino resources and cause the program to behave erratically.
IMPORTANT: Before uploading this example, make sure that the ESP8266 module is running
AT firmware (can be found in the /extras folder of the library)!
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// ESP8266 has the following connections:
// TX pin: 9
// RX pin: 8
ESP8266 wifi = new Module(9, 8);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//ESP8266 wifi = RadioShield.ModuleA;
// create HTTP client instance using the wifi module
// the default port used for HTTP is 80
HTTPClient http(&wifi, 80);
void setup() {
Serial.begin(9600);
// initialize ESP8266
Serial.print(F("[ESP8266] Initializing ... "));
// baudrate: 9600 baud
int state = wifi.begin(9600);
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// join access point
Serial.print(F("[ESP8266] Joining AP ... "));
// name: SSID
// password: password
state = wifi.join("SSID", "password");
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
}
void loop() {
// send HTTP GET request to www.httpbin.org/ip
// the response will contain origin IP address of the request
String response;
Serial.print(F("[ESP8266] Sending HTTP GET request ... "));
// URL: www.httpbin.org/ip
int http_code = http.get("www.httpbin.org/ip", response);
if (http_code > 0) {
Serial.print(F("HTTP code "));
Serial.println(http_code);
Serial.print(F("[ESP8266] Response is "));
Serial.print(response.length());
Serial.println(F(" bytes long."));
Serial.println(response);
} else {
Serial.print(F("failed, code "));
Serial.println(http_code);
}
// wait for a second before sending new request
delay(1000);
}

View file

@ -1,86 +0,0 @@
/*
RadioLib HTTP POST Example
This example sends HTTP POST request using ESP8266 WiFi module.
Please note that the response will be saved including header. HTTP header size
can easily exceed Arduino resources and cause the program to behave erratically.
IMPORTANT: Before uploading this example, make sure that the ESP8266 module is running
AT firmware (can be found in the /extras folder of the library)!
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// ESP8266 has the following connections:
// TX pin: 9
// RX pin: 8
ESP8266 wifi = new Module(9, 8);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//ESP8266 wifi = RadioShield.ModuleA;
// create HTTP client instance using the wifi module
// the default port used for HTTP is 80
HTTPClient http(&wifi, 80);
void setup() {
Serial.begin(9600);
// initialize ESP8266
Serial.print(F("[ESP8266] Initializing ... "));
// baudrate: 9600 baud
int state = wifi.begin(9600);
if(state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// join access point
Serial.print(F("[ESP8266] Joining AP ... "));
// name: SSID
// password: password
state = wifi.join("SSID", "password");
if(state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
}
void loop() {
// send HTTP POST request to www.httpbin.org/status/404
// the server doesn't process the posted data, it just returns
// response with the status code 404
String response;
Serial.print(F("[ESP8266] Sending HTTP POST request ... "));
// URL: www.httpbin.org/status/404
// content: str
// content type: text/plain
int http_code = http.post("www.httpbin.org/status/404", "str", response);
if(http_code > 0) {
Serial.print(F("HTTP code "));
Serial.println(http_code);
Serial.print(F("[ESP8266] Response is "));
Serial.print(response.length());
Serial.println(F(" bytes long."));
Serial.println(response);
} else {
Serial.print(F("failed, code "));
Serial.println(http_code);
}
// wait for a second before sending new request
delay(1000);
}

View file

@ -49,7 +49,7 @@ void setup() {
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -62,7 +62,7 @@ void setup() {
// base frequency: 434.0 MHz
// speed: 122.5 Baud ("Feld Hell")
state = hell.begin(434.0);
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));

View file

@ -52,7 +52,7 @@ void setup() {
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -65,7 +65,7 @@ void setup() {
// AFSK tone frequency: 400 Hz
// speed: 122.5 Baud ("Feld Hell")
state = hell.begin(400);
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -90,6 +90,12 @@ void loop() {
// string saved in flash
hell.print(F("Flash String"));
// in AFSK mode, it is possible to invert the text colors
// use white text on black background
hell.setInversion(true);
hell.print("Inverted String");
hell.setInversion(false);
// character
hell.print('c');

View file

@ -1,42 +0,0 @@
/*
RadioLib JDY08 Example
This example sends data using JDY08 Bluetooth module.
JDY08 works exactly like a Serial line, data are sent to the paired device.
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// JDY08 has the following connections:
// TX pin: 9
// RX pin: 8
JDY08 ble = new Module(9, 8);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//JDY08 ble = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize JDY08
// baudrate: 9600 baud
ble.begin(9600);
}
void loop() {
// JDY08 supports all methods of the Serial class
// read data incoming from Serial port and write them to Bluetooth
while (Serial.available() > 0) {
ble.write(Serial.read());
}
// read data incoming from Bluetooth and write them to Serial port
while (ble.available() > 0) {
Serial.write(ble.read());
}
}

View file

@ -1,91 +0,0 @@
/*
RadioLib MQTT Publish Example
This example publishes MQTT messages using ESP8266 WiFi module.
The messages are published to https://shiftr.io/try. You can use this namespace
for testing purposes, but remember that it is publicly accessible!
IMPORTANT: Before uploading this example, make sure that the ESP8266 module is running
AT firmware (can be found in the /extras folder of the library)!
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// ESP8266 has the following connections:
// TX pin: 9
// RX pin: 8
ESP8266 wifi = new Module(9, 8);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//ESP8266 wifi = RadioShield.ModuleA;
// create MQTT client instance using the wifi module
// the default port used for MQTT is 1883
MQTTClient mqtt(&wifi, 1883);
void setup() {
Serial.begin(9600);
// initialize ESP8266
Serial.print(F("[ESP8266] Initializing ... "));
// baudrate: 9600 baud
int state = wifi.begin(9600);
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// join access point
Serial.print(F("[ESP8266] Joining AP ... "));
// name: SSID
// password: password
state = wifi.join("SSID", "password");
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// connect to MQTT server
Serial.print(F("[ESP8266] Connecting to MQTT server ... "));
// server URL: broker.shiftr.io
// client ID: arduino
// username: try
// password: try
state = mqtt.connect("broker.shiftr.io", "arduino", "try", "try");
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
}
void loop() {
// publish MQTT message
Serial.print(F("[ESP8266] Publishing MQTT message ... "));
// topic name: hello
// application message: world
int state = mqtt.publish("hello", "world");
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before publishing again
delay(1000);
}

View file

@ -1,128 +0,0 @@
/*
RadioLib MQTT Subscribe Example
This example subscribes to MQTT topic using ESP8266 WiFi module.
The messages are pulled from https://shiftr.io/try. You can use this namespace
for testing purposes, but remember that it is publicly accessible!
IMPORTANT: Before uploading this example, make sure that the ESP8266 module is running
AT firmware (can be found in the /extras folder of the library)!
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// ESP8266 has the following connections:
// TX pin: 9
// RX pin: 8
ESP8266 wifi = new Module(9, 8);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//ESP8266 wifi = RadioShield.ModuleA;
// create MQTT client instance using the wifi module
// the default port used for MQTT is 1883
MQTTClient mqtt(&wifi, 1883);
void setup() {
Serial.begin(9600);
// initialize ESP8266
Serial.print(F("[ESP8266] Initializing ... "));
// baudrate: 9600 baud
int state = wifi.begin(9600);
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// join access point
Serial.print(F("[ESP8266] Joining AP ... "));
// name: SSID
// password: password
state = wifi.join("SSID", "password");
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// connect to MQTT server
Serial.print(F("[ESP8266] Connecting to MQTT server ... "));
// server URL: broker.shiftr.io
// client ID: arduino
// username: try
// password: try
state = mqtt.connect("broker.shiftr.io", "arduino", "try", "try");
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// subscribe to MQTT topic
// after calling this method, server will send PUBLISH packets
// to this client each time a new message was published at the topic
Serial.print(F("[ESP8266] Subscribing to MQTT topic ... "));
// topic name: hello
state = mqtt.subscribe("hello");
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
// unsubscribe from MQTT topic
// after calling this method, server will stop sending PUBLISH packets
Serial.print(F("[ESP8266] Unsubscribing from MQTT topic ... "));
// topic filter: hello
state = mqtt.unsubscribe("hello");
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
}
// create a function that will be called when a new PUBLISH packet
// arrives from the server
//
// IMPORTANT: This function MUST have two C-strings as arguments!
void onPublish(const char* topic, const char* message) {
Serial.println(F("[ESP8266] Received packet from MQTT server: "));
Serial.print(F("[ESP8266] Topic:\t"));
Serial.println(topic);
Serial.print(F("[ESP8266] Message:\t"));
Serial.println(message);
}
void loop() {
// check for new MQTT packets from server each time the loop() runs
// this will also send a PING packet, restarting the keep alive timer
int state = mqtt.check(onPublish);
Serial.print(F("[ESP8266] MQTT check "));
if (state == ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
// the rest of your loop() code goes here
// make sure that the maximum time the loop() runs is less than 1.5x keep alive,
// otherwise the server will close the network connection
}

View file

@ -0,0 +1,115 @@
/*
RadioLib SX127x Morse Receive AM Example
This example receives Morse code message using
SX1278's FSK modem. The signal is expected to be
modulated as OOK, to be demodulated in AM mode.
Other modules that can be used for Morse Code
with AFSK modulation:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- Si443x/RFM2x
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
// create AFSK client instance using the FSK module
// pin 5 is connected to SX1278 DIO2
AFSKClient audio(&radio, 5);
// create Morse client instance using the AFSK instance
MorseClient morse(&audio);
void setup() {
Serial.begin(9600);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// when using one of the non-LoRa modules for Morse code
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
// initialize Morse client
Serial.print(F("[Morse] Initializing ... "));
// AFSK tone frequency: 400 Hz
// speed: 20 words per minute
state = morse.begin(400);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// after that, set mode to OOK to emulate AM modulation
Serial.print(F("[SX1278] Switching to OOK ... "));
state = radio.setOOK(true);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// start direct mode reception
radio.receiveDirect();
}
// save symbol and length between loops
byte symbol = 0;
byte len = 0;
void loop() {
// try to read a new symbol
int state = morse.read(&symbol, &len);
// check if we have something to decode
if(state != RADIOLIB_MORSE_INTER_SYMBOL) {
// decode and print
Serial.print(MorseClient::decode(symbol, len));
// reset the symbol buffer
symbol = 0;
len = 0;
// check if we have a complete word
if(state == RADIOLIB_MORSE_WORD_COMPLETE) {
// inter-word space, interpret that as a new line
Serial.println();
}
}
}

View file

@ -0,0 +1,131 @@
/*
RadioLib Morse Transmit AM Example
This example sends Morse code message using
SX1278's FSK modem. The signal is modulated
as OOK, and may be demodulated in AM mode.
Other modules that can be used for Morse Code
with AM modulation:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- Si443x/RFM2x
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
// create AFSK client instance using the FSK module
// pin 5 is connected to SX1278 DIO2
AFSKClient audio(&radio, 5);
// create Morse client instance using the AFSK instance
MorseClient morse(&audio);
void setup() {
Serial.begin(9600);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
// when using one of the non-LoRa modules for Morse code
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize Morse client
Serial.print(F("[Morse] Initializing ... "));
// tone frequency: 400 Hz
// speed: 20 words per minute
state = morse.begin(400);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// after that, set mode to OOK to emulate AM modulation
Serial.print(F("[SX1278] Switching to OOK ... "));
state = radio.setOOK(true);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
}
void loop() {
Serial.print(F("[Morse] Sending Morse data ... "));
// MorseClient supports all methods of the Serial class
// NOTE: Characters that do not have ITU-R M.1677-1
// representation will not be sent! Lower case
// letters will be capitalized.
// send start signal first
morse.startSignal();
// Arduino String class
String aStr = "Arduino String";
morse.print(aStr);
// character array (C-String)
morse.print("C-String");
// string saved in flash
morse.print(F("Flash String"));
// character
morse.print('c');
// byte
// formatting DEC/HEX/OCT/BIN is supported for
// any integer type (byte/int/long)
morse.print(255, HEX);
// integer number
int i = 1000;
morse.print(i);
// floating point number
// NOTE: When using println(), the transmission will be
// terminated with end-of-work signal (...-.-).
float f = -3.1415;
morse.println(f, 3);
Serial.println(F("done!"));
// wait for a second before transmitting again
delay(1000);
}

View file

@ -2,8 +2,8 @@
RadioLib Morse Transmit AFSK Example
This example sends Morse code message using
SX1278's FSK modem. The data is modulated
as AFSK.
SX1278's FSK modem. The signal is modulated
as AFSK, and may be demodulated in FM mode.
Other modules that can be used for Morse Code
with AFSK modulation:
@ -36,7 +36,7 @@ SX1278 radio = new Module(10, 2, 9, 3);
// create AFSK client instance using the FSK module
// pin 5 is connected to SX1278 DIO2
AFSKClient audio(&radio, 5);
AFSKClient audio(&radio, 10);
// create Morse client instance using the AFSK instance
MorseClient morse(&audio);
@ -52,7 +52,7 @@ void setup() {
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -62,10 +62,21 @@ void setup() {
// initialize Morse client
Serial.print(F("[Morse] Initializing ... "));
// AFSK tone frequency: 400 MHz
// tone frequency: 400 Hz
// speed: 20 words per minute
state = morse.begin(400);
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// after that, set mode to OOK
Serial.print(F("[SX1278] Switching to OOK ... "));
state = radio.setOOK(true);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));

View file

@ -1,8 +1,9 @@
/*
RadioLib Morse Transmit Example
RadioLib Morse Transmit SSB Example
This example sends Morse code message using
SX1278's FSK modem.
SX1278's FSK modem. The signal is an unmodulated
carrier wave, and may be demodulated in SSB mode.
Other modules that can be used for Morse Code:
- SX127x/RFM9x
@ -49,7 +50,7 @@ void setup() {
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -59,10 +60,10 @@ void setup() {
// initialize Morse client
Serial.print(F("[Morse] Initializing ... "));
// base frequency: 434.0 MHz
// carrier wave frequency: 434.0 MHz
// speed: 20 words per minute
state = morse.begin(434.0);
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));

View file

@ -0,0 +1,121 @@
/*
RadioLib Pager (POCSAG) Receive Example
This example shows how to receive FSK packets without using
SX127x packet engine.
This example receives POCSAG messages using SX1278's
FSK modem in direct mode.
Other modules that can be used to receive POCSAG:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- Si443x/RFM2x
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// DIO2 pin: 5
const int pin = 5;
// create Pager client instance using the FSK module
PagerClient pager(&radio);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
// when using one of the non-LoRa modules
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// initialize Pager client
Serial.print(F("[Pager] Initializing ... "));
// base (center) frequency: 434.0 MHz
// speed: 1200 bps
state = pager.begin(434.0, 1200);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// start receiving POCSAG messages
Serial.print(F("[Pager] Starting to listen ... "));
// address of this "pager": 1234567
state = pager.startReceive(pin, 1234567);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
}
void loop() {
// the number of batches to wait for
// 2 batches will usually be enough to fit short and medium messages
if (pager.available() >= 2) {
Serial.print(F("[Pager] Received pager data, decoding ... "));
// you can read the data as an Arduino String
String str;
int state = pager.readData(str);
// you can also receive data as byte array
/*
byte byteArr[8];
size_t numBytes = 0;
int state = radio.receive(byteArr, &numBytes);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
// print the received data
Serial.print(F("[Pager] Data:\t"));
Serial.println(str);
} else {
// some error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}
}

View file

@ -0,0 +1,102 @@
/*
RadioLib Pager (POCSAG) Transmit Example
This example sends POCSAG messages using SX1278's
FSK modem.
Other modules that can be used to send POCSAG:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- SX126x
- nRF24
- Si443x/RFM2x
- SX128x
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
// create Pager client instance using the FSK module
PagerClient pager(&radio);
void setup() {
Serial.begin(9600);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
// when using one of the non-LoRa modules
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// initialize Pager client
Serial.print(F("[Pager] Initializing ... "));
// base (center) frequency: 434.0 MHz
// speed: 1200 bps
state = pager.begin(434.0, 1200);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
}
void loop() {
Serial.print(F("[Pager] Transmitting messages ... "));
// the simples form of "message" is just a tone on the destination pager
int state = pager.sendTone(1234567);
delay(500);
// next, transmit numeric (BCD) message to the destination pager
// NOTE: Only characters 0123456789*U-() and space
// can be sent in a BCD message!
state |= pager.transmit("0123456789*U -()", 1234567);
delay(500);
// finally, let's transmit an ASCII message now
state |= pager.transmit("Hello World!", 1234567, RADIOLIB_PAGER_ASCII);
delay(500);
// we can also send only a tone
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(3000);
}

View file

@ -35,7 +35,7 @@ void setup() {
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -57,7 +57,7 @@ void loop() {
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -71,11 +71,11 @@ void loop() {
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -31,7 +31,7 @@ void setup() {
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -67,7 +67,7 @@ void loop() {
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -75,11 +75,11 @@ void loop() {
Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str);
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -33,7 +33,7 @@ void setup() {
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -46,7 +46,7 @@ void setup() {
// address filtering (node address only)
Serial.print(F("[RF69] Setting node address ... "));
state = radio.setNodeAddress(0x02);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -59,7 +59,7 @@ void setup() {
// address filtering (node or broadcast address)
Serial.print(F("[RF69] Setting broadcast address ... "));
state = radio.setBroadcastAddress(0xFF);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -73,7 +73,7 @@ void setup() {
/*
Serial.print(F("[RF69] Disabling address filtering ... "));
state == radio.disableAddressFiltering();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -96,7 +96,7 @@ void loop() {
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -104,11 +104,11 @@ void loop() {
Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str);
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -31,7 +31,7 @@ void setup() {
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -46,7 +46,7 @@ void setup() {
// start listening for packets
Serial.print(F("[RF69] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -74,6 +74,9 @@ volatile bool enableInterrupt = true;
// is received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -104,7 +107,7 @@ void loop() {
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[RF69] Received packet!"));
@ -118,7 +121,7 @@ void loop() {
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -43,7 +43,7 @@ void setup() {
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
int state = radio1.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -60,7 +60,7 @@ void setup() {
// output power: 17 dBm
// preamble length: 32 bits
state = radio2.begin(868.0, 300.0, 60.0, 250.0, 17, 32);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -72,17 +72,17 @@ void setup() {
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
if (radio1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) {
if (radio1.setFrequency(433.5) == RADIOLIB_ERR_INVALID_FREQUENCY) {
Serial.println(F("[RF69] Selected frequency is invalid for this module!"));
while (true);
}
// set bit rate to 100.0 kbps
state = radio1.setBitRate(100.0);
if (state == ERR_INVALID_BIT_RATE) {
if (state == RADIOLIB_ERR_INVALID_BIT_RATE) {
Serial.println(F("[RF69] Selected bit rate is invalid for this module!"));
while (true);
} else if (state == ERR_INVALID_BIT_RATE_BW_RATIO) {
} else if (state == RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO) {
Serial.println(F("[RF69] Selected bit rate to bandwidth ratio is invalid!"));
Serial.println(F("[RF69] Increase receiver bandwidth to set this bit rate."));
while (true);
@ -90,23 +90,23 @@ void setup() {
// set receiver bandwidth to 250.0 kHz
state = radio1.setRxBandwidth(250.0);
if (state == ERR_INVALID_RX_BANDWIDTH) {
if (state == RADIOLIB_ERR_INVALID_RX_BANDWIDTH) {
Serial.println(F("[RF69] Selected receiver bandwidth is invalid for this module!"));
while (true);
} else if (state == ERR_INVALID_BIT_RATE_BW_RATIO) {
} else if (state == RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO) {
Serial.println(F("[RF69] Selected bit rate to bandwidth ratio is invalid!"));
Serial.println(F("[RF69] Decrease bit rate to set this receiver bandwidth."));
while (true);
}
// set allowed frequency deviation to 10.0 kHz
if (radio1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) {
if (radio1.setFrequencyDeviation(10.0) == RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION) {
Serial.println(F("[RF69] Selected frequency deviation is invalid for this module!"));
while (true);
}
// set output power to 2 dBm
if (radio1.setOutputPower(2) == ERR_INVALID_OUTPUT_POWER) {
if (radio1.setOutputPower(2) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
Serial.println(F("[RF69] Selected output power is invalid for this module!"));
while (true);
}
@ -115,7 +115,7 @@ void setup() {
// NOTE: sync word must not contain any zero bytes
// set sync word to 0x0123456789ABCDEF
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
if (radio1.setSyncWord(syncWord, 8) == ERR_INVALID_SYNC_WORD) {
if (radio1.setSyncWord(syncWord, 8) == RADIOLIB_ERR_INVALID_SYNC_WORD) {
Serial.println(F("[RF69] Selected sync word is invalid for this module!"));
while (true);
}

View file

@ -33,7 +33,7 @@ void setup() {
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -49,7 +49,7 @@ void setup() {
/*
Serial.print(F("[RF69] Setting high power module ... "));
state = radio.setOutputPower(20, true);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -71,11 +71,11 @@ void loop() {
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 64 bytes
Serial.println(F("too long!"));

View file

@ -31,7 +31,7 @@ void setup() {
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -66,11 +66,11 @@ void loop() {
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 64 bytes
Serial.println(F("too long!"));

View file

@ -33,7 +33,7 @@ void setup() {
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -46,7 +46,7 @@ void setup() {
// address filtering (node address only)
Serial.print(F("[RF69] Setting node address ... "));
state = radio.setNodeAddress(0x01);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -59,7 +59,7 @@ void setup() {
// address filtering (node or broadcast address)
Serial.print(F("[RF69] Setting broadcast address ... "));
state = radio.setBroadcastAddress(0xFF);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -73,7 +73,7 @@ void setup() {
/*
Serial.print(F("[RF69] Disabling address filtering ... "));
state = radio.disableAddressFiltering();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -106,11 +106,11 @@ void loop() {
int state = radio.transmit(byteArr, 8, 0xFF);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 64 bytes
Serial.println(F("too long!"));

View file

@ -29,7 +29,7 @@ RF69 radio = new Module(10, 2, 3);
//RF69 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
@ -37,7 +37,7 @@ void setup() {
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -57,7 +57,7 @@ void setup() {
/*
Serial.print(F("[RF69] Setting high power module ... "));
state = radio.setOutputPower(20, true);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -91,6 +91,9 @@ volatile bool enableInterrupt = true;
// is transmitted by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -111,7 +114,7 @@ void loop() {
// reset flag
transmittedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
@ -125,6 +128,11 @@ void loop() {
}
// clean up after transmission is finished
// this will ensure transmitter is disabled,
// RF switch is powered down etc.
radio.finishTransmit();
// wait a second before transmitting again
delay(1000);

View file

@ -49,7 +49,7 @@ void setup() {
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -75,7 +75,7 @@ void setup() {
// encoding: ASCII (7-bit)
// stop bits: 1
state = rtty.begin(434.0, 183, 45);
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -130,6 +130,9 @@ void loop() {
float f = -3.1415;
rtty.println(f, 3);
// turn the transmitter off
rtty.standby();
Serial.println(F("done!"));
// wait for a second before transmitting again

View file

@ -50,7 +50,7 @@ void setup() {
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -68,7 +68,7 @@ void setup() {
// encoding: ASCII (7-bit)
// stop bits: 1
state = rtty.begin(400, 170, 45);
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -123,6 +123,9 @@ void loop() {
float f = -3.1415;
rtty.println(f, 3);
// turn the transmitter off
rtty.standby();
Serial.println(F("done!"));
// wait for a second before transmitting again

View file

@ -91,7 +91,7 @@ void setup() {
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -107,7 +107,16 @@ void setup() {
Serial.print(F("[SSTV] Initializing ... "));
// 0 Hz tone frequency: 434.0 MHz
// SSTV mode: Wrasse (SC2-180)
// correction factor: 0.95
state = sstv.begin(434.0, Wrasse);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// set correction factor
// NOTE: Due to different speeds of various platforms
// supported by RadioLib (Arduino Uno, ESP32 etc),
// and because SSTV is analog protocol, incorrect
@ -116,8 +125,9 @@ void setup() {
// to adjust the length of timing pulses
// (lower number = shorter pulses).
// The value is usually around 0.95 (95%).
state = sstv.begin(434.0, Wrasse, 0.95);
if(state == ERR_NONE) {
Serial.print(F("[SSTV] Setting correction ... "));
state = sstv.setCorrection(0.95);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));

View file

@ -90,7 +90,7 @@ void setup() {
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -105,7 +105,16 @@ void setup() {
// initialize SSTV client
Serial.print(F("[SSTV] Initializing ... "));
// SSTV mode: Wrasse (SC2-180)
// correction factor: 0.95
state = sstv.begin(Wrasse);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// set correction factor
// NOTE: Due to different speeds of various platforms
// supported by RadioLib (Arduino Uno, ESP32 etc),
// and because SSTV is analog protocol, incorrect
@ -114,8 +123,9 @@ void setup() {
// to adjust the length of timing pulses
// (lower number = shorter pulses).
// The value is usually around 0.95 (95%).
state = sstv.begin(Wrasse, 0.95);
if(state == ERR_NONE) {
Serial.print(F("[SSTV] Setting correction ... "));
state = sstv.setCorrection(0.95);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));

View file

@ -33,7 +33,7 @@ void setup() {
// initialize SX1231 with default settings
Serial.print(F("[SX1231] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -55,7 +55,7 @@ void loop() {
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -63,11 +63,11 @@ void loop() {
Serial.print(F("[SX1231] Data:\t\t"));
Serial.println(str);
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -33,7 +33,7 @@ void setup() {
// initialize SX1231 with default settings
Serial.print(F("[SX1231] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -54,11 +54,11 @@ void loop() {
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(F("too long!"));

View file

@ -29,13 +29,16 @@ SX1262 radio = new Module(10, 2, 3, 9);
// https://github.com/jgromes/RadioShield
//SX1262 radio = RadioShield.ModuleA;
// or using CubeCell
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
void setup() {
Serial.begin(9600);
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -50,11 +53,11 @@ void loop() {
// start scanning current channel
int state = radio.scanChannel();
if (state == LORA_DETECTED) {
if (state == RADIOLIB_LORA_DETECTED) {
// LoRa preamble was detected
Serial.println(F("detected!"));
} else if (state == CHANNEL_FREE) {
} else if (state == RADIOLIB_CHANNEL_FREE) {
// no preamble was detected, channel is free
Serial.println(F("channel is free!"));

View file

@ -0,0 +1,129 @@
/*
RadioLib SX126x Channel Activity Detection Example
This example uses SX1262 to scan the current LoRa
channel and detect ongoing LoRa transmissions.
Unlike SX127x CAD, SX126x can detect any part
of LoRa transmission, not just the preamble.
Other modules from SX126x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1262 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1262 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1262 radio = RadioShield.ModuleA;
// or using CubeCell
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
void setup() {
Serial.begin(9600);
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set the function that will be called
// when LoRa packet or timeout is detected
radio.setDio1Action(setFlag);
// start scanning the channel
Serial.print(F("[SX1262] Starting scan for LoRa preamble ... "));
state = radio.startChannelScan();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
}
// flag to indicate that a packet was detected or CAD timed out
volatile bool scanFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// this function is called when a complete packet
// is received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// something happened, set the flag
scanFlag = true;
}
void loop() {
// check if the flag is set
if(scanFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
scanFlag = false;
// check CAD result
int state = radio.getChannelScanResult();
if (state == RADIOLIB_LORA_DETECTED) {
// LoRa packet was detected
Serial.println(F("[SX1262] Packet detected!"));
} else if (state == RADIOLIB_CHANNEL_FREE) {
// channel is free
Serial.println(F("[SX1262] Channel is free!"));
} else {
// some other error occurred
Serial.print(F("[SX1262] Failed, code "));
Serial.println(state);
}
// start scanning the channel again
Serial.print(F("[SX1262] Starting scan for LoRa preamble ... "));
state = radio.startChannelScan();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
// enable interrupt service routine
enableInterrupt = true;
}
}

View file

@ -30,13 +30,16 @@ SX1262 radio = new Module(10, 2, 3, 9);
// https://github.com/jgromes/RadioShield
//SX1262 radio = RadioShield.ModuleA;
// or using CubeCell
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
void setup() {
Serial.begin(9600);
// initialize SX1262 FSK modem with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.beginFSK();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -61,7 +64,7 @@ void setup() {
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.setSyncWord(syncWord, 8);
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("Unable to set configuration, code "));
Serial.println(state);
while (true);
@ -94,11 +97,11 @@ void loop() {
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1262] Packet transmitted successfully!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Serial.println(F("[SX1262] Packet too long!"));
} else if (state == ERR_TX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
Serial.println(F("[SX1262] Timed out while transmitting!"));
} else {
Serial.println(F("[SX1262] Failed to transmit packet, code "));
@ -112,11 +115,11 @@ void loop() {
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1262] Received packet!"));
Serial.print(F("[SX1262] Data:\t"));
Serial.println(str);
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
Serial.println(F("[SX1262] Timed out while waiting for packet!"));
} else {
Serial.println(F("[SX1262] Failed to receive packet, code "));
@ -137,7 +140,7 @@ void loop() {
state = radio.setNodeAddress(0x02);
// set broadcast address to 0xFF
state = radio.setBroadcastAddress(0xFF);
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1262] Unable to set address filter, code "));
Serial.println(state);
}
@ -147,7 +150,7 @@ void loop() {
// node and broadcast address
/*
state = radio.disableAddressFiltering();
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("Unable to remove address filter, code "));
}
*/

View file

@ -0,0 +1,162 @@
/*
RadioLib SX126x Ping-Pong Example
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// uncomment the following only on one
// of the nodes to initiate the pings
//#define INITIATING_NODE
// SX1262 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1262 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1262 radio = RadioShield.ModuleA;
// or using CubeCell
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
// save transmission states between loops
int transmissionState = RADIOLIB_ERR_NONE;
// flag to indicate transmission or reception state
bool transmitFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// flag to indicate that a packet was sent or received
volatile bool operationDone = false;
// this function is called when a complete packet
// is transmitted or received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we sent or received a packet, set the flag
operationDone = true;
}
void setup() {
Serial.begin(9600);
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set the function that will be called
// when new packet is received
radio.setDio1Action(setFlag);
#if defined(INITIATING_NODE)
// send the first packet on this node
Serial.print(F("[SX1262] Sending first packet ... "));
transmissionState = radio.startTransmit("Hello World!");
transmitFlag = true;
#else
// start listening for LoRa packets on this node
Serial.print(F("[SX1262] Starting to listen ... "));
state = radio.startReceive();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
#endif
}
void loop() {
// check if the previous operation finished
if(operationDone) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
operationDone = false;
if(transmitFlag) {
// the previous operation was transmission, listen for response
// print the result
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
// listen for response
radio.startReceive();
transmitFlag = false;
} else {
// the previous operation was reception
// print data and send another packet
String str;
int state = radio.readData(str);
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1262] Received packet!"));
// print data of the packet
Serial.print(F("[SX1262] Data:\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
Serial.print(F("[SX1262] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print SNR (Signal-to-Noise Ratio)
Serial.print(F("[SX1262] SNR:\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
}
// wait a second before transmitting again
delay(1000);
// send another one
Serial.print(F("[SX1262] Sending another packet ... "));
transmissionState = radio.startTransmit("Hello World!");
transmitFlag = true;
}
// we're ready to process more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View file

@ -34,13 +34,16 @@ SX1262 radio = new Module(10, 2, 3, 9);
// https://github.com/jgromes/RadioShield
//SX1262 radio = RadioShield.ModuleA;
// or using CubeCell
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
void setup() {
Serial.begin(9600);
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -65,7 +68,7 @@ void loop() {
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -85,11 +88,11 @@ void loop() {
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -35,13 +35,16 @@ SX1262 radio = new Module(10, 2, 3, 9);
// https://github.com/jgromes/RadioShield
//SX1262 radio = RadioShield.ModuleA;
// or using CubeCell
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
void setup() {
Serial.begin(9600);
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -56,7 +59,7 @@ void setup() {
// start listening for LoRa packets
Serial.print(F("[SX1262] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -85,6 +88,9 @@ volatile bool enableInterrupt = true;
// is received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -115,7 +121,7 @@ void loop() {
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1262] Received packet!"));
@ -133,7 +139,7 @@ void loop() {
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -45,13 +45,16 @@ SX1268 radio2 = new Module(8, 4, 5, 6);
// https://github.com/jgromes/RadioShield
//SX1261 radio3 = RadioShield.ModuleB;
// or using CubeCell
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
void setup() {
Serial.begin(9600);
// initialize SX1268 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio1.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -72,7 +75,7 @@ void setup() {
// output power: 2 dBm
// preamble length: 20 symbols
state = radio2.begin(915.0, 500.0, 6, 5, 0x34, 20);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -84,56 +87,56 @@ void setup() {
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
if (radio1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) {
if (radio1.setFrequency(433.5) == RADIOLIB_ERR_INVALID_FREQUENCY) {
Serial.println(F("Selected frequency is invalid for this module!"));
while (true);
}
// set bandwidth to 250 kHz
if (radio1.setBandwidth(250.0) == ERR_INVALID_BANDWIDTH) {
if (radio1.setBandwidth(250.0) == RADIOLIB_ERR_INVALID_BANDWIDTH) {
Serial.println(F("Selected bandwidth is invalid for this module!"));
while (true);
}
// set spreading factor to 10
if (radio1.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) {
if (radio1.setSpreadingFactor(10) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) {
Serial.println(F("Selected spreading factor is invalid for this module!"));
while (true);
}
// set coding rate to 6
if (radio1.setCodingRate(6) == ERR_INVALID_CODING_RATE) {
if (radio1.setCodingRate(6) == RADIOLIB_ERR_INVALID_CODING_RATE) {
Serial.println(F("Selected coding rate is invalid for this module!"));
while (true);
}
// set LoRa sync word to 0xAB
if (radio1.setSyncWord(0xAB) != ERR_NONE) {
if (radio1.setSyncWord(0xAB) != RADIOLIB_ERR_NONE) {
Serial.println(F("Unable to set sync word!"));
while (true);
}
// set output power to 10 dBm (accepted range is -17 - 22 dBm)
if (radio1.setOutputPower(10) == ERR_INVALID_OUTPUT_POWER) {
if (radio1.setOutputPower(10) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
Serial.println(F("Selected output power is invalid for this module!"));
while (true);
}
// set over current protection limit to 80 mA (accepted range is 45 - 240 mA)
// NOTE: set value to 0 to disable overcurrent protection
if (radio1.setCurrentLimit(80) == ERR_INVALID_CURRENT_LIMIT) {
if (radio1.setCurrentLimit(80) == RADIOLIB_ERR_INVALID_CURRENT_LIMIT) {
Serial.println(F("Selected current limit is invalid for this module!"));
while (true);
}
// set LoRa preamble length to 15 symbols (accepted range is 0 - 65535)
if (radio1.setPreambleLength(15) == ERR_INVALID_PREAMBLE_LENGTH) {
if (radio1.setPreambleLength(15) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) {
Serial.println(F("Selected preamble length is invalid for this module!"));
while (true);
}
// disable CRC
if (radio1.setCRC(false) == ERR_INVALID_CRC_CONFIGURATION) {
if (radio1.setCRC(false) == RADIOLIB_ERR_INVALID_CRC_CONFIGURATION) {
Serial.println(F("Selected CRC is invalid for this module!"));
while (true);
}
@ -141,7 +144,7 @@ void setup() {
// Some SX126x modules have TCXO (temperature compensated crystal
// oscillator). To configure TCXO reference voltage,
// the following method can be used.
if (radio1.setTCXO(2.4) == ERR_INVALID_TCXO_VOLTAGE) {
if (radio1.setTCXO(2.4) == RADIOLIB_ERR_INVALID_TCXO_VOLTAGE) {
Serial.println(F("Selected TCXO voltage is invalid for this module!"));
while (true);
}
@ -150,7 +153,7 @@ void setup() {
// this feature, the following method can be used.
// NOTE: As long as DIO2 is configured to control RF switch,
// it can't be used as interrupt pin!
if (radio1.setDio2AsRfSwitch() != ERR_NONE) {
if (radio1.setDio2AsRfSwitch() != RADIOLIB_ERR_NONE) {
Serial.println(F("Failed to set DIO2 as RF switch!"));
while (true);
}

View file

@ -30,13 +30,16 @@ SX1262 radio = new Module(10, 2, 3, 9);
// https://github.com/jgromes/RadioShield
//SX1262 radio = RadioShield.ModuleA;
// or using CubeCell
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
void setup() {
Serial.begin(9600);
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -71,7 +74,7 @@ void loop() {
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
@ -80,11 +83,11 @@ void loop() {
Serial.print(radio.getDataRate());
Serial.println(F(" bps"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(F("too long!"));
} else if (state == ERR_TX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
// timeout occured while transmitting packet
Serial.println(F("timeout!"));

View file

@ -31,8 +31,11 @@ SX1262 radio = new Module(10, 2, 3, 9);
// https://github.com/jgromes/RadioShield
//SX1262 radio = RadioShield.ModuleA;
// or using CubeCell
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
// save transmission state between loops
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
@ -40,7 +43,7 @@ void setup() {
// initialize SX1262 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -77,6 +80,9 @@ volatile bool enableInterrupt = true;
// is transmitted by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -97,7 +103,7 @@ void loop() {
// reset flag
transmittedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
@ -111,6 +117,11 @@ void loop() {
}
// clean up after transmission is finished
// this will ensure transmitter is disabled,
// RF switch is powered down etc.
radio.finishTransmit();
// wait a second before transmitting again
delay(1000);

View file

@ -36,7 +36,7 @@ void setup() {
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -51,11 +51,11 @@ void loop() {
// start scanning current channel
int state = radio.scanChannel();
if (state == PREAMBLE_DETECTED) {
if (state == RADIOLIB_PREAMBLE_DETECTED) {
// LoRa preamble was detected
Serial.println(F("detected preamble!"));
} else if (state == CHANNEL_FREE) {
} else if (state == RADIOLIB_CHANNEL_FREE) {
// no preamble was detected, channel is free
Serial.println(F("channel is free!"));

View file

@ -0,0 +1,147 @@
/*
RadioLib SX127x Channel Activity Detection with Interrupts Example
This example scans the current LoRa channel and detects
valid LoRa preambles. Preamble is the first part of
LoRa transmission, so this can be used to check
if the LoRa channel is free, or if you should start
receiving a message.
Other modules from SX127x/RFM9x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
void setup() {
// Serial port speed must be high enough for this example
Serial.begin(115200);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set the function that will be called
// when LoRa preamble is not detected within CAD timeout period
radio.setDio0Action(setFlagTimeout);
// set the function that will be called
// when LoRa preamble is detected
radio.setDio1Action(setFlagDetected);
// start scanning the channel
Serial.print(F("[SX1278] Starting scan for LoRa preamble ... "));
state = radio.startChannelScan();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
}
// flag to indicate that a preamble was not detected
volatile bool timeoutFlag = false;
// flag to indicate that a preamble was detected
volatile bool detectedFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// this function is called when no preamble
// is detected within timeout period
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlagTimeout(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we timed out, set the flag
timeoutFlag = true;
}
// this function is called when LoRa preamble
// is detected within timeout period
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlagDetected(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we got a preamble, set the flag
detectedFlag = true;
}
void loop() {
// check if we need to restart channel activity detection
if(detectedFlag || timeoutFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// check if we got a preamble
if(detectedFlag) {
// LoRa preamble was detected
Serial.println(F("[SX1278] Preamble detected!"));
} else {
// nothing was detected
Serial.println(F("[SX1278] Channel free!"));
}
// start scanning the channel
Serial.print(F("[SX1278] Starting scan for LoRa preamble ... "));
// start scanning current channel
int state = radio.startChannelScan();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
// reset flags
timeoutFlag = false;
detectedFlag = false;
// enable interrupts again
enableInterrupt = true;
}
}

View file

@ -0,0 +1,226 @@
/*
RadioLib SX127x Receive after Channel Activity Detection Example
This example scans the current LoRa channel and detects
valid LoRa preambles. Preamble is the first part of
LoRa transmission, so this can be used to check
if the LoRa channel is free, or if you should start
receiving a message. If a preamble is detected,
the module will switch to receive mode and receive the packet.
For most use-cases, it should be enough to just use the
interrupt-driven reception described in the example
"SX127x_Receive_Interrupt".
Other modules from SX127x/RFM9x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
void setup() {
// Serial port speed must be high enough for this example
Serial.begin(115200);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set the function that will be called
// when LoRa preamble is not detected within CAD timeout period
// or when a packet is received
radio.setDio0Action(setFlagTimeout);
// set the function that will be called
// when LoRa preamble is detected
radio.setDio1Action(setFlagDetected);
// start scanning the channel
Serial.print(F("[SX1278] Starting scan for LoRa preamble ... "));
state = radio.startChannelScan();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
}
// flag to indicate that a preamble was not detected
volatile bool timeoutFlag = false;
// flag to indicate that a preamble was detected
volatile bool detectedFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// flag to indicate if we are currently receiving
bool receiving = false;
// this function is called when no preamble
// is detected within timeout period
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlagTimeout(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we timed out, set the flag
timeoutFlag = true;
}
// this function is called when LoRa preamble
// is detected within timeout period
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlagDetected(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we got a preamble, set the flag
detectedFlag = true;
}
void loop() {
// check if we need to restart channel activity detection
if(detectedFlag || timeoutFlag) {
int state = RADIOLIB_ERR_NONE;
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// check ongoing reception
if(receiving) {
// DIO triggered while reception is ongoing
// that means we got a packet
// reset flags first
detectedFlag = false;
timeoutFlag = false;
// you can read received data as an Arduino String
String str;
state = radio.readData(str);
// you can also read received data as byte array
/*
byte byteArr[8];
state = radio.readData(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1278] Received packet!"));
// print data of the packet
Serial.print(F("[SX1278] Data:\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
Serial.print(F("[SX1278] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print SNR (Signal-to-Noise Ratio)
Serial.print(F("[SX1278] SNR:\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
// print frequency error
Serial.print(F("[SX1278] Frequency error:\t"));
Serial.print(radio.getFrequencyError());
Serial.println(F(" Hz"));
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("[SX1278] CRC error!"));
} else {
// some other error occurred
Serial.print(F("[SX1278] Failed, code "));
Serial.println(state);
}
// reception is done now
receiving = false;
}
// check if we got a preamble
if(detectedFlag) {
// LoRa preamble was detected
Serial.print(F("[SX1278] Preamble detected, starting reception ... "));
state = radio.startReceive(0, RADIOLIB_SX127X_RXSINGLE);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
}
// set the flag for ongoing reception
receiving = true;
} else if(!receiving) {
// nothing was detected
// do not print anything, it just spams the console
}
// if we're not receiving, start scanning again
if(!receiving) {
int state = radio.startChannelScan();
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("[SX1278] Starting new scan failed, code "));
Serial.println(state);
}
}
// reset flags
timeoutFlag = false;
detectedFlag = false;
// enable interrupts again
enableInterrupt = true;
}
}

View file

@ -28,7 +28,7 @@ SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 fsk = RadioShield.ModuleA;
//SX1278 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
@ -36,7 +36,7 @@ void setup() {
// initialize SX1278 FSK modem with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -61,7 +61,7 @@ void setup() {
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.setSyncWord(syncWord, 8);
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("Unable to set configuration, code "));
Serial.println(state);
while (true);
@ -74,7 +74,7 @@ void setup() {
// setDataShapingOOK() to set the correct shaping!
state = radio.setOOK(true);
state = radio.setDataShapingOOK(1);
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("Unable to change modulation, code "));
Serial.println(state);
while (true);
@ -95,11 +95,11 @@ void loop() {
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Packet transmitted successfully!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Serial.println(F("[SX1278] Packet too long!"));
} else if (state == ERR_TX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
Serial.println(F("[SX1278] Timed out while transmitting!"));
} else {
Serial.println(F("[SX1278] Failed to transmit packet, code "));
@ -113,11 +113,11 @@ void loop() {
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Received packet!"));
Serial.print(F("[SX1278] Data:\t"));
Serial.println(str);
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
Serial.println(F("[SX1278] Timed out while waiting for packet!"));
} else {
Serial.println(F("[SX1278] Failed to receive packet, code "));
@ -138,7 +138,7 @@ void loop() {
state = radio.setNodeAddress(0x02);
// set broadcast address to 0xFF
state = radio.setBroadcastAddress(0xFF);
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Unable to set address filter, code "));
Serial.println(state);
}
@ -148,7 +148,7 @@ void loop() {
// node and broadcast address
/*
state = radio.disableAddressFiltering();
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("Unable to remove address filter, code "));
}
*/
@ -159,7 +159,7 @@ void loop() {
// activate direct mode transmitter
state = radio.transmitDirect();
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Unable to start direct transmission mode, code "));
Serial.println(state);
}
@ -170,20 +170,21 @@ void loop() {
// it is recommended to set data shaping to 0
// (no shaping) when transmitting audio
state = radio.setDataShaping(0.0);
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Unable to set data shaping, code "));
Serial.println(state);
}
// tone() function is not available on ESP32 and Arduino Due
#if !defined(ESP32) && !defined(_VARIANT_ARDUINO_DUE_X_)
// transmit FM tone at 1000 Hz for 1 second
// transmit FM tone at 1000 Hz for 1 second, then 500 Hz for 1 second
// (DIO2 is connected to Arduino pin 4)
// Note: tone() function is not available on Arduino Due and CubeCell
// on these platforms, the following will do nothing
#if !defined(RADIOLIB_TONE_UNSUPPORTED)
tone(4, 1000);
delay(1000);
// transmit FM note at 500 Hz for 1 second
tone(4, 500);
delay(1000);
noTone(4);
#endif
// NOTE: after calling transmitDirect(), SX127x will start
@ -194,7 +195,7 @@ void loop() {
// direct mode transmissions can also be received
// as bit stream on DIO1 (data) and DIO2 (clock)
state = radio.receiveDirect();
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Unable to start direct reception mode, code "));
Serial.println(state);
}

View file

@ -0,0 +1,159 @@
/*
RadioLib SX127x Ping-Pong Example
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// uncomment the following only on one
// of the nodes to initiate the pings
//#define INITIATING_NODE
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// NRST pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
// save transmission states between loops
int transmissionState = RADIOLIB_ERR_NONE;
// flag to indicate transmission or reception state
bool transmitFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// flag to indicate that a packet was sent or received
volatile bool operationDone = false;
// this function is called when a complete packet
// is transmitted or received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we sent or received packet, set the flag
operationDone = true;
}
void setup() {
Serial.begin(9600);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set the function that will be called
// when new packet is received
radio.setDio0Action(setFlag);
#if defined(INITIATING_NODE)
// send the first packet on this node
Serial.print(F("[SX1278] Sending first packet ... "));
transmissionState = radio.startTransmit("Hello World!");
transmitFlag = true;
#else
// start listening for LoRa packets on this node
Serial.print(F("[SX1278] Starting to listen ... "));
state = radio.startReceive();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
#endif
}
void loop() {
// check if the previous operation finished
if(operationDone) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
operationDone = false;
if(transmitFlag) {
// the previous operation was transmission, listen for response
// print the result
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
// listen for response
radio.startReceive();
transmitFlag = false;
} else {
// the previous operation was reception
// print data and send another packet
String str;
int state = radio.readData(str);
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1278] Received packet!"));
// print data of the packet
Serial.print(F("[SX1278] Data:\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
Serial.print(F("[SX1278] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print SNR (Signal-to-Noise Ratio)
Serial.print(F("[SX1278] SNR:\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
}
// wait a second before transmitting again
delay(1000);
// send another one
Serial.print(F("[SX1278] Sending another packet ... "));
transmissionState = radio.startTransmit("Hello World!");
transmitFlag = true;
}
// we're ready to process more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View file

@ -40,7 +40,7 @@ void setup() {
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -65,7 +65,7 @@ void loop() {
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -91,11 +91,11 @@ void loop() {
Serial.print(radio.getFrequencyError());
Serial.println(F(" Hz"));
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -0,0 +1,80 @@
/*
RadioLib SX127x Direct Receive Example
This example shows how to receive FSK packets without using
SX127x packet engine.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// DIO2 pin: 5
const int pin = 5;
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1278 with FSK modem at 9600 bps
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.beginFSK(434.0, 9.6, 20.0);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set the direct mode sync word
// the default RadioLib FSK sync word is 0x12AD
// we can add in some preamble bits, to lower the chance
// of false detection
radio.setDirectSyncWord(0x555512AD, 32);
// set function that will be called each time a bit is received
radio.setDirectAction(readBit);
// start direct mode reception
radio.receiveDirect();
}
// this function is called when a new bit is received
void readBit(void) {
// read the data bit
radio.readBit(pin);
}
void loop() {
// we expect the packet to contain the string "Hello World!",
// a length byte and 2 CRC bytes, that's 15 bytes in total
if(radio.available() >= 15) {
Serial.println("[SX1278] Received packet in direct mode!");
while(radio.available()) {
// read a byte
byte b = radio.read();
// print it
Serial.print(b, HEX);
Serial.print('\t');
Serial.write(b);
Serial.println();
}
}
}

View file

@ -0,0 +1,180 @@
/*
RadioLib SX127x Transmit with Frequency Hopping Example
This example transmits packets using SX1278 LoRa radio module.
Each packet contains up to 256 bytes of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
Other modules from SX127x/RFM9x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
SX127x supports FHSS or Frequency Hopping Spread Spectrum.
Once a hopping period is set and a transmission is started, the radio
will begin triggering interrupts every hop period where the radio frequency
is changed to the next channel.
*/
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
// flag to indicate that a packet was received
volatile bool receivedFlag = false;
// flag to indicate frequency must be changed
volatile bool fhssChangeFlag = false;
// the channel frequencies can be generated randomly or hard coded
// NOTE: The frequency list MUST be the same on both sides!
float channels[] = { 433.0, 433.4, 433.2, 433.6, 434.0, 433.8 };
int numberOfChannels = sizeof(channels) / sizeof(float);
// counter to keep track of how many frequency hops were performed
int hopsCompleted = 0;
// this function is called when a complete packet
// is received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setRxFlag(void) {
receivedFlag = true;
}
// this function is called when FhssChangeChannel interrupt occurs
// (at the beginning of each transmission)
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFHSSFlag(void) {
fhssChangeFlag = true;
}
void setup() {
Serial.begin(9600);
// begin radio on home channel
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.begin(channels[0]);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set hop period in symbols
// this will also enable FHSS
state = radio.setFHSSHoppingPeriod(9);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set the function to call when reception is finished
radio.setDio0Action(setRxFlag);
// set the function to call when we need to change frequency
radio.setDio1Action(setFHSSFlag);
// start listening for LoRa packets
Serial.print(F("[SX1278] Starting to listen ... "));
state = radio.startReceive();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
}
void loop() {
// check if the reception flag is set
if (receivedFlag == true) {
// you can read received data as an Arduino String
String str;
int state = radio.readData(str);
// you can also read received data as byte array
/*
byte byteArr[8];
int state = radio.readData(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1278] Received packet!"));
// print data of the packet
Serial.print(F("[SX1278] Data:\t\t"));
Serial.println(str);
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("[SX1278] CRC error!"));
} else {
// some other error occurred
Serial.print(F("[SX1278] Failed, code "));
Serial.println(state);
}
// print the number of hops it took
Serial.print(F("[SX1278] Hops completed: "));
Serial.println(hopsCompleted);
// reset the counter
hopsCompleted = 0;
// put the module back to listen mode
radio.startReceive();
// we're ready to receive more packets, clear the flag
receivedFlag = false;
}
// check if we need to do another frequency hop
if (fhssChangeFlag == true) {
// we do, change it now
int state = radio.setFrequency(channels[radio.getFHSSChannel() % numberOfChannels]);
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("[SX1278] Failed to change frequency, code "));
Serial.println(state);
}
// increment the counter
hopsCompleted++;
// clear the FHSS interrupt
radio.clearFHSSInt();
// we're ready to do another hop, clear the flag
fhssChangeFlag = false;
}
}

View file

@ -41,7 +41,7 @@ void setup() {
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -56,7 +56,7 @@ void setup() {
// start listening for LoRa packets
Serial.print(F("[SX1278] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -85,6 +85,9 @@ volatile bool enableInterrupt = true;
// is received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -115,7 +118,7 @@ void loop() {
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1278] Received packet!"));
@ -138,7 +141,7 @@ void loop() {
Serial.print(radio.getFrequencyError());
Serial.println(F(" Hz"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("[SX1278] CRC error!"));

View file

@ -47,7 +47,7 @@ void setup() {
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio1.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -73,7 +73,7 @@ void setup() {
// preamble length: 20 symbols
// amplifier gain: 1 (maximum gain)
state = radio2.begin(915.0, 500.0, 6, 5, 0x14, 2, 20, 1);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -85,32 +85,32 @@ void setup() {
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
if (radio1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) {
if (radio1.setFrequency(433.5) == RADIOLIB_ERR_INVALID_FREQUENCY) {
Serial.println(F("Selected frequency is invalid for this module!"));
while (true);
}
// set bandwidth to 250 kHz
if (radio1.setBandwidth(250.0) == ERR_INVALID_BANDWIDTH) {
if (radio1.setBandwidth(250.0) == RADIOLIB_ERR_INVALID_BANDWIDTH) {
Serial.println(F("Selected bandwidth is invalid for this module!"));
while (true);
}
// set spreading factor to 10
if (radio1.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) {
if (radio1.setSpreadingFactor(10) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) {
Serial.println(F("Selected spreading factor is invalid for this module!"));
while (true);
}
// set coding rate to 6
if (radio1.setCodingRate(6) == ERR_INVALID_CODING_RATE) {
if (radio1.setCodingRate(6) == RADIOLIB_ERR_INVALID_CODING_RATE) {
Serial.println(F("Selected coding rate is invalid for this module!"));
while (true);
}
// set LoRa sync word to 0x14
// NOTE: value 0x34 is reserved for LoRaWAN networks and should not be used
if (radio1.setSyncWord(0x14) != ERR_NONE) {
if (radio1.setSyncWord(0x14) != RADIOLIB_ERR_NONE) {
Serial.println(F("Unable to set sync word!"));
while (true);
}
@ -118,20 +118,20 @@ void setup() {
// set output power to 10 dBm (accepted range is -3 - 17 dBm)
// NOTE: 20 dBm value allows high power operation, but transmission
// duty cycle MUST NOT exceed 1%
if (radio1.setOutputPower(10) == ERR_INVALID_OUTPUT_POWER) {
if (radio1.setOutputPower(10) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
Serial.println(F("Selected output power is invalid for this module!"));
while (true);
}
// set over current protection limit to 80 mA (accepted range is 45 - 240 mA)
// NOTE: set value to 0 to disable overcurrent protection
if (radio1.setCurrentLimit(80) == ERR_INVALID_CURRENT_LIMIT) {
if (radio1.setCurrentLimit(80) == RADIOLIB_ERR_INVALID_CURRENT_LIMIT) {
Serial.println(F("Selected current limit is invalid for this module!"));
while (true);
}
// set LoRa preamble length to 15 symbols (accepted range is 6 - 65535)
if (radio1.setPreambleLength(15) == ERR_INVALID_PREAMBLE_LENGTH) {
if (radio1.setPreambleLength(15) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) {
Serial.println(F("Selected preamble length is invalid for this module!"));
while (true);
}
@ -139,7 +139,7 @@ void setup() {
// set amplifier gain to 1 (accepted range is 1 - 6, where 1 is maximum gain)
// NOTE: set value to 0 to enable automatic gain control
// leave at 0 unless you know what you're doing
if (radio1.setGain(1) == ERR_INVALID_GAIN) {
if (radio1.setGain(1) == RADIOLIB_ERR_INVALID_GAIN) {
Serial.println(F("Selected gain is invalid for this module!"));
while (true);
}

View file

@ -36,7 +36,7 @@ void setup() {
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -71,7 +71,7 @@ void loop() {
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F(" success!"));
@ -80,11 +80,11 @@ void loop() {
Serial.print(radio.getDataRate());
Serial.println(F(" bps"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(F("too long!"));
} else if (state == ERR_TX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
// timeout occurred while transmitting packet
Serial.println(F("timeout!"));

View file

@ -0,0 +1,182 @@
/*
RadioLib SX127x Transmit with Frequency Hopping Example
This example transmits packets using SX1278 LoRa radio module.
Each packet contains up to 256 bytes of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
Other modules from SX127x/RFM9x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
SX127x supports FHSS or Frequency Hopping Spread Spectrum.
Once a hopping period is set and a transmission is started, the radio
will begin triggering interrupts every hop period where the radio frequency
is changed to the next channel.
*/
#include <RadioLib.h>
// SX1278 has the following connections:
// NSS pin: 10
// DIO0 pin: 2
// RESET pin: 9
// DIO1 pin: 3
SX1278 radio = new Module(10, 2, 9, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1278 radio = RadioShield.ModuleA;
// flag to indicate that a packet was received
volatile bool transmittedFlag = false;
// flag to indicate frequency must be changed
volatile bool fhssChangeFlag = false;
// the channel frequencies can be generated randomly or hard coded
// NOTE: The frequency list MUST be the same on both sides!
float channels[] = { 433.0, 433.4, 433.2, 433.6, 434.0, 433.8 };
int numberOfChannels = sizeof(channels) / sizeof(float);
// counter to keep track of how many frequency hops were performed
int hopsCompleted = 0;
// counter that increments with each sent packet
int packetCounter = 0;
// save transmission state between loops
int transmissionState = RADIOLIB_ERR_NONE;
// this is the packet that will be sent
String longPacket = "Let's create a really long packet to trigger \
lots of hop interrupts. A packet can be up to 256 bytes long. \
This packet is 222 bytes so using sf = 9, bw = 125, timeOnAir is \
1488ms. 1488ms / (9*4.10ms) = 40 hops. Counter: ";
// this function is called when a complete packet
// is transmitted by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setTxFlag(void) {
transmittedFlag = true;
}
// this function is called when FhssChangeChannel interrupt occurs
// (at the beginning of each transmission)
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFHSSFlag(void) {
fhssChangeFlag = true;
}
void setup() {
Serial.begin(9600);
// begin radio on home channel
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.begin(channels[0]);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set hop period in symbols
// this will also enable FHSS
state = radio.setFHSSHoppingPeriod(9);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set the function to call when transmission is finished
radio.setDio0Action(setTxFlag);
// set the function to call when we need to change frequency
radio.setDio1Action(setFHSSFlag);
// start transmitting the first packet
Serial.print(F("[SX1278] Sending first packet ... "));
String packet = longPacket + packetCounter;
transmissionState = radio.startTransmit(packet);
}
void loop() {
// check if the transmission flag is set
if (transmittedFlag == true) {
// reset flag
transmittedFlag = false;
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
// The channel is automatically reset to 0 upon completion
Serial.print(F("[SX1278] Radio is on channel: "));
Serial.println(radio.getFHSSChannel());
// print the number of hops it took
Serial.print(F("[SX1278] Hops completed: "));
Serial.println(hopsCompleted);
// reset the counter
hopsCompleted = 0;
// return to home channel before the next transaction
radio.setFrequency(channels[radio.getFHSSChannel() % numberOfChannels]);
// wait a second before transmitting again
delay(1000);
// increment the packet counter
packetCounter++;
// send another packet
Serial.print(F("[SX1278] Sending another packet ... "));
String packet = longPacket + packetCounter;
transmissionState = radio.startTransmit(packet);
}
// check if we need to do another frequency hop
if (fhssChangeFlag == true) {
// we do, change it now
int state = radio.setFrequency(channels[radio.getFHSSChannel() % numberOfChannels]);
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("[SX1278] Failed to change frequency, code "));
Serial.println(state);
}
// increment the counter
hopsCompleted++;
// clear the FHSS interrupt
radio.clearFHSSInt();
// we're ready to do another hop, clear the flag
fhssChangeFlag = false;
}
}

View file

@ -32,7 +32,7 @@ SX1278 radio = new Module(10, 2, 9, 3);
//SX1278 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
@ -40,7 +40,7 @@ void setup() {
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -77,6 +77,9 @@ volatile bool enableInterrupt = true;
// is transmitted by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -97,7 +100,7 @@ void loop() {
// reset flag
transmittedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
@ -111,6 +114,11 @@ void loop() {
}
// clean up after transmission is finished
// this will ensure transmitter is disabled,
// RF switch is powered down etc.
radio.finishTransmit();
// wait a second before transmitting again
delay(1000);

View file

@ -38,7 +38,7 @@ void setup() {
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.beginBLE();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -59,13 +59,13 @@ void setup() {
state = radio.setOutputPower(5);
state = radio.setDataShaping(1.0);
state = radio.setAccessAddress(0x12345678);
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("Unable to set configuration, code "));
Serial.println(state);
while (true);
}
#warning "This sketch is just an API guide! Read the note at line 6."
#warning "This sketch is just an API guide! Read the note at line 8."
}
void loop() {
@ -79,11 +79,11 @@ void loop() {
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Packet transmitted successfully!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Serial.println(F("[SX1280] Packet too long!"));
} else if (state == ERR_TX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
Serial.println(F("[SX1280] Timed out while transmitting!"));
} else {
Serial.print(F("[SX1280] Failed to transmit packet, code "));
@ -97,11 +97,11 @@ void loop() {
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Received packet!"));
Serial.print(F("[SX1280] Data:\t"));
Serial.println(str);
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
Serial.println(F("[SX1280] Timed out while waiting for packet!"));
} else {
Serial.print(F("[SX1280] Failed to receive packet, code "));

View file

@ -33,7 +33,7 @@ void setup() {
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -48,11 +48,11 @@ void loop() {
// start scanning current channel
int state = radio.scanChannel();
if (state == LORA_DETECTED) {
if (state == RADIOLIB_LORA_DETECTED) {
// LoRa preamble was detected
Serial.println(F("detected!"));
} else if (state == CHANNEL_FREE) {
} else if (state == RADIOLIB_CHANNEL_FREE) {
// no preamble was detected, channel is free
Serial.println(F("channel is free!"));

View file

@ -36,7 +36,7 @@ void setup() {
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.beginFLRC();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -58,7 +58,7 @@ void setup() {
state = radio.setDataShaping(1.0);
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67};
state = radio.setSyncWord(syncWord, 4);
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("Unable to set configuration, code "));
Serial.println(state);
while (true);
@ -78,11 +78,11 @@ void loop() {
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Packet transmitted successfully!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Serial.println(F("[SX1280] Packet too long!"));
} else if (state == ERR_TX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
Serial.println(F("[SX1280] Timed out while transmitting!"));
} else {
Serial.println(F("[SX1280] Failed to transmit packet, code "));
@ -96,11 +96,11 @@ void loop() {
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Received packet!"));
Serial.print(F("[SX1280] Data:\t"));
Serial.println(str);
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
Serial.println(F("[SX1280] Timed out while waiting for packet!"));
} else {
Serial.print(F("[SX1280] Failed to receive packet, code "));

View file

@ -36,7 +36,7 @@ void setup() {
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.beginGFSK();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -58,7 +58,7 @@ void setup() {
state = radio.setDataShaping(RADIOLIB_SHAPING_1_0);
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89};
state = radio.setSyncWord(syncWord, 5);
if (state != ERR_NONE) {
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("Unable to set configuration, code "));
Serial.println(state);
while (true);
@ -78,11 +78,11 @@ void loop() {
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Packet transmitted successfully!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Serial.println(F("[SX1280] Packet too long!"));
} else if (state == ERR_TX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
Serial.println(F("[SX1280] Timed out while transmitting!"));
} else {
Serial.println(F("[SX1280] Failed to transmit packet, code "));
@ -96,11 +96,11 @@ void loop() {
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Received packet!"));
Serial.print(F("[SX1280] Data:\t"));
Serial.println(str);
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
Serial.println(F("[SX1280] Timed out while waiting for packet!"));
} else {
Serial.print(F("[SX1280] Failed to receive packet, code "));

View file

@ -35,7 +35,7 @@ void setup() {
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -57,14 +57,14 @@ void loop() {
int state = radio.range(false, 0x12345678);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// ranging finished successfully
Serial.println(F("success!"));
Serial.print(F("[SX1280] Distance:\t\t\t"));
Serial.print(radio.getRangingResult());
Serial.println(F(" meters"));
} else if (state == ERR_RANGING_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RANGING_TIMEOUT) {
// timed out waiting for ranging packet
Serial.println(F("timed out!"));

View file

@ -40,7 +40,7 @@ void setup() {
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -65,7 +65,7 @@ void loop() {
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -85,11 +85,17 @@ void loop() {
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
} else if (state == ERR_RX_TIMEOUT) {
// print the Frequency Error
// of the last received packet
Serial.print(F("[SX1280] Frequency Error:\t"));
Serial.print(radio.getFrequencyError());
Serial.println(F(" Hz"));
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -41,7 +41,7 @@ void setup() {
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -56,7 +56,7 @@ void setup() {
// start listening for LoRa packets
Serial.print(F("[SX1280] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -85,6 +85,9 @@ volatile bool enableInterrupt = true;
// is received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -115,7 +118,7 @@ void loop() {
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1280] Received packet!"));
@ -133,7 +136,13 @@ void loop() {
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
} else if (state == ERR_CRC_MISMATCH) {
// print the Frequency Error
// of the last received packet
Serial.print(F("[SX1280] Frequency Error:\t"));
Serial.print(radio.getFrequencyError());
Serial.println(F(" Hz"));
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -48,7 +48,7 @@ void setup() {
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio1.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -68,7 +68,7 @@ void setup() {
// output power: 2 dBm
// preamble length: 20 symbols
state = radio2.begin(2450.0, 1625.0, 7, 5, 2, 20);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -80,43 +80,43 @@ void setup() {
// and check if the configuration was changed successfully
// set carrier frequency to 2410.5 MHz
if (radio1.setFrequency(2410.5) == ERR_INVALID_FREQUENCY) {
if (radio1.setFrequency(2410.5) == RADIOLIB_ERR_INVALID_FREQUENCY) {
Serial.println(F("Selected frequency is invalid for this module!"));
while (true);
}
// set bandwidth to 203.125 kHz
if (radio1.setBandwidth(203.125) == ERR_INVALID_BANDWIDTH) {
if (radio1.setBandwidth(203.125) == RADIOLIB_ERR_INVALID_BANDWIDTH) {
Serial.println(F("Selected bandwidth is invalid for this module!"));
while (true);
}
// set spreading factor to 10
if (radio1.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) {
if (radio1.setSpreadingFactor(10) == RADIOLIB_ERR_INVALID_SPREADING_FACTOR) {
Serial.println(F("Selected spreading factor is invalid for this module!"));
while (true);
}
// set coding rate to 6
if (radio1.setCodingRate(6) == ERR_INVALID_CODING_RATE) {
if (radio1.setCodingRate(6) == RADIOLIB_ERR_INVALID_CODING_RATE) {
Serial.println(F("Selected coding rate is invalid for this module!"));
while (true);
}
// set output power to -2 dBm
if (radio1.setOutputPower(-2) == ERR_INVALID_OUTPUT_POWER) {
if (radio1.setOutputPower(-2) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
Serial.println(F("Selected output power is invalid for this module!"));
while (true);
}
// set LoRa preamble length to 16 symbols (accepted range is 2 - 65535)
if (radio1.setPreambleLength(16) == ERR_INVALID_PREAMBLE_LENGTH) {
if (radio1.setPreambleLength(16) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) {
Serial.println(F("Selected preamble length is invalid for this module!"));
while (true);
}
// disable CRC
if (radio1.setCRC(false) == ERR_INVALID_CRC_CONFIGURATION) {
if (radio1.setCRC(false) == RADIOLIB_ERR_INVALID_CRC_CONFIGURATION) {
Serial.println(F("Selected CRC is invalid for this module!"));
while (true);
}

View file

@ -43,7 +43,7 @@ void setup() {
// preamble length: 12 symbols
// CRC: enabled
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -78,11 +78,11 @@ void loop() {
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(F("too long!"));

View file

@ -32,7 +32,7 @@ SX1280 radio = new Module(10, 2, 3, 9);
//SX1280 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
@ -40,7 +40,7 @@ void setup() {
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -77,6 +77,9 @@ volatile bool enableInterrupt = true;
// is transmitted by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -97,7 +100,7 @@ void loop() {
// reset flag
transmittedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
@ -107,6 +110,11 @@ void loop() {
}
// clean up after transmission is finished
// this will ensure transmitter is disabled,
// RF switch is powered down etc.
radio.finishTransmit();
// wait a second before transmitting again
delay(1000);

View file

@ -37,7 +37,7 @@ void setup() {
// initialize Si4432 with default settings
Serial.print(F("[Si4432] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -59,7 +59,7 @@ void loop() {
int state = radio.receive(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
@ -67,11 +67,11 @@ void loop() {
Serial.print(F("[Si4432] Data:\t\t"));
Serial.println(str);
} else if (state == ERR_RX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -33,7 +33,7 @@ void setup() {
// initialize Si4432 with default settings
Serial.print(F("[Si4432] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -48,7 +48,7 @@ void setup() {
// start listening for packets
Serial.print(F("[Si4432] Starting to listen ... "));
state = radio.startReceive();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -76,6 +76,9 @@ volatile bool enableInterrupt = true;
// is received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -106,7 +109,7 @@ void loop() {
int state = radio.readData(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[Si4432] Received packet!"));
@ -114,7 +117,7 @@ void loop() {
Serial.print(F("[Si4432] Data:\t\t\t"));
Serial.println(str);
} else if (state == ERR_CRC_MISMATCH) {
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));

View file

@ -43,7 +43,7 @@ void setup() {
// initialize Si4432 with default settings
Serial.print(F("[Si4432] Initializing ... "));
int state = radio1.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -60,7 +60,7 @@ void setup() {
// output power: 17 dBm
// preamble length: 32 bits
state = radio2.begin(868.0, 200.0, 60.0, 335.5, 17, 32);
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -72,17 +72,17 @@ void setup() {
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
if (radio1.setFrequency(433.5) == ERR_INVALID_FREQUENCY) {
if (radio1.setFrequency(433.5) == RADIOLIB_ERR_INVALID_FREQUENCY) {
Serial.println(F("[Si4432] Selected frequency is invalid for this module!"));
while (true);
}
// set bit rate to 100.0 kbps
state = radio1.setBitRate(100.0);
if (state == ERR_INVALID_BIT_RATE) {
if (state == RADIOLIB_ERR_INVALID_BIT_RATE) {
Serial.println(F("[Si4432] Selected bit rate is invalid for this module!"));
while (true);
} else if (state == ERR_INVALID_BIT_RATE_BW_RATIO) {
} else if (state == RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO) {
Serial.println(F("[Si4432] Selected bit rate to bandwidth ratio is invalid!"));
Serial.println(F("[Si4432] Increase receiver bandwidth to set this bit rate."));
while (true);
@ -90,19 +90,19 @@ void setup() {
// set receiver bandwidth to 284.8 kHz
state = radio1.setRxBandwidth(284.8);
if (state == ERR_INVALID_RX_BANDWIDTH) {
if (state == RADIOLIB_ERR_INVALID_RX_BANDWIDTH) {
Serial.println(F("[Si4432] Selected receiver bandwidth is invalid for this module!"));
while (true);
}
// set frequency deviation to 10.0 kHz
if (radio1.setFrequencyDeviation(10.0) == ERR_INVALID_FREQUENCY_DEVIATION) {
if (radio1.setFrequencyDeviation(10.0) == RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION) {
Serial.println(F("[Si4432] Selected frequency deviation is invalid for this module!"));
while (true);
}
// set output power to 2 dBm
if (radio1.setOutputPower(2) == ERR_INVALID_OUTPUT_POWER) {
if (radio1.setOutputPower(2) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
Serial.println(F("[Si4432] Selected output power is invalid for this module!"));
while (true);
}
@ -110,7 +110,7 @@ void setup() {
// up to 4 bytes can be set as sync word
// set sync word to 0x01234567
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67};
if (radio1.setSyncWord(syncWord, 4) == ERR_INVALID_SYNC_WORD) {
if (radio1.setSyncWord(syncWord, 4) == RADIOLIB_ERR_INVALID_SYNC_WORD) {
Serial.println(F("[Si4432] Selected sync word is invalid for this module!"));
while (true);
}

View file

@ -35,7 +35,7 @@ void setup() {
// initialize Si4432 with default settings
Serial.print(F("[Si4432] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -60,15 +60,15 @@ void loop() {
int state = radio.transmit(byteArr, 8);
*/
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F(" success!"));
} else if (state == ERR_PACKET_TOO_LONG) {
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(F(" too long!"));
} else if (state == ERR_TX_TIMEOUT) {
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
// timeout occured while transmitting packet
Serial.println(F(" timeout!"));

View file

@ -30,7 +30,7 @@ Si4432 radio = new Module(10, 2, 9);
//Si4432 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = ERR_NONE;
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
@ -38,7 +38,7 @@ void setup() {
// initialize Si4432 with default settings
Serial.print(F("[Si4432] Initializing ... "));
int state = radio.begin();
if (state == ERR_NONE) {
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -75,6 +75,9 @@ volatile bool enableInterrupt = true;
// is transmitted by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
@ -95,7 +98,7 @@ void loop() {
// reset flag
transmittedFlag = false;
if (transmissionState == ERR_NONE) {
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
@ -105,6 +108,11 @@ void loop() {
}
// clean up after transmission is finished
// this will ensure transmitter is disabled,
// RF switch is powered down etc.
radio.finishTransmit();
// wait a second before transmitting again
delay(1000);

Some files were not shown because too many files have changed in this diff Show more