Prepare migrate to RadioLib

lora-esp32-dev
US1GHQ 2021-11-24 22:49:18 +02:00
parent a9e9f8d7f0
commit 61a6b46a04
162 changed files with 36712 additions and 0 deletions

16
lib/RadioLib/.gitignore vendored 100644
View File

@ -0,0 +1,16 @@
# Arduino Library Development file
.development
# Atom
*.tags
*.tags1
# Jetbrain IDEs
.idea
# Debug decoder
extras/decoder/log.txt
extras/decoder/out.txt
# PlatformIO
.pio*

View File

@ -0,0 +1,3 @@
# Code of Conduct
Don't be an a*shole.

View File

@ -0,0 +1,110 @@
# Contributing to RadioLib
First of all, thank you very much for taking the time to contribute! All feedback and ideas are greatly appreciated.
To keep this library organized, please follow these rules.
## Issues
The following rules guide submission of new issues. These rules are in place mainly so that the issue author can get help as quickly as possible.
1. **Questions are welcome, spam is not.**
Any issues without description will be considered spam and as such will be **CLOSED** and **LOCKED** immediately!
2. **This repository has issue templates.**
To report bugs or suggest new features, use the provided issue templates. Use the default issue only if the templates do not fit your issue type.
3. **Be as clear as possible when creating issues.**
Issues with generic titles (e.g. "not working", "lora", etc.) will be **CLOSED** until the title is fixed, since the title is supposed to categorize the issue. The same applies for issues with very little information and extensive grammatical or formatting errors that make it difficult to find out what is the actual issue.
4. **Issues deserve some attention too.**
Issues that are left for 2 weeks without response by the original author when asked for further information will be closed due to inactivity. This is to keep track of important issues, the author is encouraged to reopen the issue at a later date.
## Code style guidelines
I like pretty code! Or at least, I like *consistent* code style. When creating pull requests, please follow these style guidelines, they're in place to keep high code readability.
1. **Bracket style**
This library uses the following style of bracket indentation (1TBS, or "javascript" style):
```c++
if (foo) {
bar();
} else {
baz();
}
```
2. **Tabs**
Use 2 space characters for tabs.
3. **Single-line comments**
Comments can be very useful - and they can become the bane of readability. Every single-line comment should start at new line, have one space between comment delimiter `//` and the start of the comment itself. The comment should also start with a lower-case letter.
```c++
// this function does something
foo("bar");
// here it does something else
foo(12345);
```
4. **Split code into blocks**
It is very easy to write code that machine can read. It is much harder to write one that humans can read. That's why it's a great idea to split code into blocks - even if the block is just a single line!
```c++
// build a temporary buffer (first block)
uint8_t* data = new uint8_t[len + 1];
if(!data) {
return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
}
// read the received data (second block)
state = readData(data, len);
// add null terminator (third block)
data[len] = 0;
```
5. **Doxygen**
If you're adding a new method, make sure to add appropriate Doxygen comments, so that the documentation is always complete.
6. **Keywords**
This is an Arduino library, so it needs to comply with the Arduino library specification. To add a new keyword to the Arduino IDE syntax highlighting, add it to the keywords.txt file. **Use true tabs in keywords.txt! No spaces there!**
7. **Dynamic memory**
Sometimes, RadioLib might be used in critical applications where dynamic memory allocation using `new` or `malloc` might cause issues. For such cases, RadioLib provides the option to compile using only static arrays. This means that every dynamically allocated array must have a sufficiently large static counterpart. Naturally, all dynamically allocated memory must be properly de-allocated using `delete` or `free`.
```c++
// build a temporary buffer
#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(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED);
}
#endif
// read the received data
readData(data, length);
// deallocate temporary buffer
#if !defined(RADIOLIB_STATIC_ONLY)
delete[] data;
#endif
```
8. **God Mode**
During development, it can be useful to have access to the low level drivers, such as the SPI commands. These are incredibly powerful, since they will basically let user do anything he wants with the module, outside of the normal level of sanity checks. As such, they are normally protected using C++ access modifiers `private` or `protected`. God mode disables this protection, and so any newly implemented `class` must contain the appropriate macro check:
```c++
class Module {
void publicMethod();
#if defined(RADIOLIB_GODMODE)
private:
#endif
void privateMethod();
};
```
9. **No Arduino Strings**
Arduino `String` class should never be used internally in the library. The only allowed occurence of Arduino `String` is in public API methods, and only at the top-most layer.

2565
lib/RadioLib/Doxyfile 100644

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,91 @@
# RadioLib ![Build Status](https://github.com/jgromes/RadioLib/workflows/CI/badge.svg)
### _One radio library to rule them all!_
## 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 microcontroller can handle!
### Supported modules:
* __CC1101__ FSK radio module
* __LLCC68__ LoRa module
* __nRF24L01__ 2.4 GHz module
* __RF69__ FSK/OOK radio module
* __RFM2x__ series FSK modules (RFM22, RM23)
* __RFM9x__ series LoRa modules (RFM95, RM96, RFM97, RFM98)
* __Si443x__ series FSK modules (Si4430, Si4431, Si4432)
* __SX126x__ series LoRa modules (SX1261, SX1262, SX1268)
* __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
### Supported protocols and digital modes:
* __AX.25__ 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
* [__Morse Code__](https://www.sigidwiki.com/wiki/Morse_Code_(CW)) using 2-FSK or AFSK for modules:
SX127x, RFM9x, SX126x, RF69, SX1231, CC1101, nRF24L01, RFM2x, Si443x and SX128x
* [__SSTV__](https://www.sigidwiki.com/wiki/SSTV) using 2-FSK or AFSK for modules:
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
### 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
* [__megaAVR__](https://github.com/arduino/ArduinoCore-megaavr) - Arduino Uno WiFi Rev.2 and Nano Every
* [__SAM__](https://github.com/arduino/ArduinoCore-sam) - Arduino Due
* [__SAMD__](https://github.com/arduino/ArduinoCore-samd) - Arduino Zero, MKR boards, M0 Pro etc.
* __Adafruit__
* [__SAMD__](https://github.com/adafruit/ArduinoCore-samd) - Adafruit Feather M0 and M4 boards (Feather, Metro, Gemma, Trinket etc.)
* [__nRF52__](https://github.com/adafruit/Adafruit_nRF52_Arduino) - Adafruit Feather nRF528x, Bluefruit and CLUE
* __Espressif__
* [__ESP32__](https://github.com/espressif/arduino-esp32) - ESP32-based boards
* [__ESP8266__](https://github.com/esp8266/Arduino) - ESP8266-based boards
* __Intel__
* [__Curie__](https://github.com/arduino/ArduinoCore-arc32) - Arduino 101
* __SparkFun__
* [__Apollo3__](https://github.com/sparkfun/Arduino_Apollo3) - Sparkfun Artemis Redboard
* __ST Microelectronics__
* [__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
* __MCUdude__
* [__MegaCoreX__](https://github.com/MCUdude/MegaCoreX) - megaAVR-0 series (ATmega4809, ATmega3209 etc.)
* __Raspberry Pi__
* [__RP2040__](https://github.com/arduino/ArduinoCore-mbed) - Raspberry Pi Pico and Arduino Nano RP2040 Connect
* __Heltec__
* [__CubeCell__](https://github.com/HelTecAutomation/CubeCell-Arduino) - ASR650X series (CubeCell-Board, CubeCell-Capsule, CubeCell-Module etc.)
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:
* __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
### Where should I start?
First of all, take a look at the [examples](https://github.com/jgromes/RadioLib/tree/master/examples) and the [Wiki](https://github.com/jgromes/RadioLib/wiki) - especially the [Basics](https://github.com/jgromes/RadioLib/wiki/Basics) page. There's a lot of useful information over there. If something isn't working as expected, try searching the [issues](https://github.com/jgromes/RadioLib/issues/).
### Help, my module isn't working!
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 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

@ -0,0 +1,5 @@
# Security Policy
## Reporting a Vulnerability
RadioLib is provided as-is without any warranty, and is not intended to be used in security-critical applications. However, if you discover a vulnerability within the library code, please report it to gromes.jan@gmail.com.

View File

@ -0,0 +1,105 @@
/*
RadioLib AFSK Imperial March Example
This example shows how to EXECUTE ORDER 66
Other modules that can be used for AFSK:
- 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>
// include the melody
#include "melody.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);
// 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
// Si443x/RFM2x: GPIO
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);
}
}
void loop() {
Serial.print(F("[AFSK] Executing Order 66 ... "));
// calculate whole note duration
int wholenote = (60000 * 4) / 120;
// iterate over the melody
for(unsigned int note = 0; note < sizeof(melody) / sizeof(melody[0]); note += 2) {
// calculate the duration of each note
int noteDuration = 0;
int divider = melody[note + 1];
if(divider > 0) {
// regular note, just proceed
noteDuration = wholenote / divider;
} else if(divider < 0) {
// dotted notes are represented with negative durations!!
noteDuration = wholenote / abs(divider);
noteDuration *= 1.5; // increases the duration in half for dotted notes
}
// we only play the note for 90% of the duration, leaving 10% as a pause
audio.tone(melody[note]);
delay(noteDuration*0.9);
audio.noTone();
delay(noteDuration*0.1);
}
Serial.println(F("done!"));
// wait for a second
delay(1000);
}

View File

@ -0,0 +1,128 @@
/*
Note definitions, melody and melody-related functions
adapted from https://github.com/robsoncouto/arduino-songs
by Robson Couto, 2019
*/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#define REST 0
// notes of the moledy 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!!
int melody[] = {
// Darth Vader theme (Imperial March) - Star wars
// Score available at https://musescore.com/user/202909/scores/1141521
// The tenor saxophone part was used
NOTE_A4,-4, NOTE_A4,-4, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_F4,8, REST,8,
NOTE_A4,-4, NOTE_A4,-4, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_A4,16, NOTE_F4,8, REST,8,
NOTE_A4,4, NOTE_A4,4, NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16,
NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,//4
NOTE_E5,4, NOTE_E5,4, NOTE_E5,4, NOTE_F5,-8, NOTE_C5,16,
NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,
NOTE_A5,4, NOTE_A4,-8, NOTE_A4,16, NOTE_A5,4, NOTE_GS5,-8, NOTE_G5,16, //7
NOTE_DS5,16, NOTE_D5,16, NOTE_DS5,8, REST,8, NOTE_A4,8, NOTE_DS5,4, NOTE_D5,-8, NOTE_CS5,16,
NOTE_C5,16, NOTE_B4,16, NOTE_C5,16, REST,8, NOTE_F4,8, NOTE_GS4,4, NOTE_F4,-8, NOTE_A4,-16,//9
NOTE_C5,4, NOTE_A4,-8, NOTE_C5,16, NOTE_E5,2,
NOTE_A5,4, NOTE_A4,-8, NOTE_A4,16, NOTE_A5,4, NOTE_GS5,-8, NOTE_G5,16, //7
NOTE_DS5,16, NOTE_D5,16, NOTE_DS5,8, REST,8, NOTE_A4,8, NOTE_DS5,4, NOTE_D5,-8, NOTE_CS5,16,
NOTE_C5,16, NOTE_B4,16, NOTE_C5,16, REST,8, NOTE_F4,8, NOTE_GS4,4, NOTE_F4,-8, NOTE_A4,-16,//9
NOTE_A4,4, NOTE_F4,-8, NOTE_C5,16, NOTE_A4,2,
};

View File

@ -0,0 +1,90 @@
/*
RadioLib AFSK Example
This example shows hot to send audio FSK tones
using SX1278's FSK modem.
Other modules that can be used for AFSK:
- 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);
// 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
// Si443x/RFM2x: GPIO
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);
}
}
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.
}

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,174 @@
/*
RadioLib AX.25 Frame Example
This example shows how to send various
AX.25 frames using SX1278's FSK modem.
Other modules that can be used for AX.25:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- SX126x
- nRF24
- Si443x/RFM2x
Using raw AX.25 frames requires some
knowledge of the protocol, refer to
AX25_Transmit for basic operation.
Frames shown in this example are not
exhaustive; all possible AX.25 frames
should be supported.
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 AX.25 client instance using the FSK module
AX25Client ax25(&radio);
void setup() {
Serial.begin(9600);
// initialize SX1278
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);
// 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);
}
}
void loop() {
// create AX.25 Unnumbered Information frame
// destination station callsign: "NJ7P"
// destination station SSID: 0
// source station callsign: "N7LEM"
// source station SSID: 0
// 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, 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 == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else {
// some error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
delay(1000);
// create AX.25 Receive Ready frame
// destination station callsign: "NJ7P"
// destination station SSID: 0
// source station callsign: "N7LEM"
// source station SSID: 0
// control field: RR, P/F not used, 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);
// send the frame
Serial.print(F("[AX.25] Sending RR frame ... "));
state = ax25.sendFrame(&frameRR);
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else {
// some error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
delay(1000);
// create AX.25 Information frame
// destination station callsign: "NJ7P"
// destination station SSID: 0
// source station callsign: "N7LEM"
// source station SSID: 0
// 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, 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)
frameI.setRecvSequence(0);
// set send sequence number (0 - 7)
frameI.setSendSequence(0);
// send the frame
Serial.print(F("[AX.25] Sending I frame ... "));
state = ax25.sendFrame(&frameI);
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else {
// some error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
delay(1000);
}

View File

@ -0,0 +1,94 @@
/*
RadioLib AX.25 Transmit Example
This example sends AX.25 messages using
SX1278's FSK modem.
Other modules that can be used for AX.25:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- SX126x
- 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 AX.25 client instance using the FSK module
AX25Client ax25(&radio);
void setup() {
Serial.begin(9600);
// initialize SX1278
Serial.print(F("[SX1278] Initializing ... "));
// carrier frequency: 434.0 MHz
// bit rate: 1.2 kbps (1200 baud 2-FSK AX.25)
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 == 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);
}
}
void loop() {
// send AX.25 unnumbered information frame
Serial.print(F("[AX.25] Sending UI frame ... "));
// destination station callsign: "NJ7P"
// destination station SSID: 0
int state = ax25.transmit("Hello World!", "NJ7P");
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else {
// some error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
delay(1000);
}

View File

@ -0,0 +1,113 @@
/*
RadioLib AX.25 Transmit AFSK Example
This example sends AX.25 messages using
SX1278's FSK modem. The data is modulated
as AFSK at 1200 baud using Bell 202 tones.
Other modules that can be used for AX.25
with AFSK modulation:
- 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);
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 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);
}
// 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() {
// send AX.25 unnumbered information frame
Serial.print(F("[AX.25] Sending UI frame ... "));
// destination station callsign: "NJ7P"
// destination station SSID: 0
int state = ax25.transmit("Hello World!", "NJ7P");
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else {
// some error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
delay(1000);
}

View File

@ -0,0 +1,94 @@
/*
RadioLib CC1101 Receive Example
This example receives packets using CC1101 FSK radio module.
To successfully receive data, the following settings have to be the same
on both transmitter and receiver:
- carrier frequency
- bit rate
- frequency deviation
- sync word
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// CC1101 has the following connections:
// CS pin: 10
// GDO0 pin: 2
// RST pin: unused
// GDO2 pin: 3 (optional)
CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize CC1101 with default settings
Serial.print(F("[CC1101] 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);
}
}
void loop() {
Serial.print(F("[CC1101] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[CC1101] Data:\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[CC1101] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print LQI (Link Quality Indicator)
// of the last received packet, lower is better
Serial.print(F("[CC1101] LQI:\t\t"));
Serial.println(radio.getLQI());
} 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!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View File

@ -0,0 +1,120 @@
/*
RadioLib CC1101 Receive with Address Example
This example receives packets using CC1101 FSK radio
module. Packets can have 1-byte address of the
destination node. After setting node address, this node
will automatically filter out any packets that do not
contain either node address or broadcast addresses.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// CC1101 has the following connections:
// CS pin: 10
// GDO0 pin: 2
// RST pin: unused
// GDO2 pin: 3 (optional)
CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize CC1101 with default settings
Serial.print(F("[CC1101] 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 node address
// NOTE: Calling this method will automatically enable
// address filtering. CC1101 also allows to set
// number of broadcast address (0/1/2).
// The following sets one broadcast address 0x00.
// When setting two broadcast addresses, 0x00 and
// 0xFF will be used.
Serial.print(F("[CC1101] Setting node address ... "));
state = radio.setNodeAddress(0x01, 1);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// address filtering can also be disabled
// NOTE: Calling this method will also erase previously
// set node address
/*
Serial.print(F("[CC1101] Disabling address filtering ... "));
state == radio.disableAddressFiltering();
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("[CC1101] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[CC1101] Data:\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[CC1101] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print LQI (Link Quality Indicator)
// of the last received packet, lower is better
Serial.print(F("[CC1101] LQI:\t\t"));
Serial.println(radio.getLQI());
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View File

@ -0,0 +1,153 @@
/*
RadioLib CC1101 Receive with Interrupts Example
This example listens for FSK transmissions and tries to
receive them. Once a packet is received, an interrupt is
triggered.
To successfully receive data, the following settings have to be the same
on both transmitter and receiver:
- carrier frequency
- bit rate
- frequency deviation
- sync word
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// CC1101 has the following connections:
// CS pin: 10
// GDO0 pin: 2
// RST pin: unused
// GDO2 pin: 3 (optional)
CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize CC1101 with default settings
Serial.print(F("[CC1101] 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.setGdo0Action(setFlag);
// start listening for packets
Serial.print(F("[CC1101] 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);
}
// if needed, 'listen' mode can be disabled by calling
// any of the following methods:
//
// radio.standby()
// radio.sleep()
// radio.transmit();
// radio.receive();
// radio.readData();
}
// flag to indicate that a packet was received
volatile bool receivedFlag = 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we got a packet, set the flag
receivedFlag = true;
}
void loop() {
// check if the flag is set
if(receivedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
receivedFlag = false;
// 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("[CC1101] Received packet!"));
// print data of the packet
Serial.print(F("[CC1101] Data:\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[CC1101] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print LQI (Link Quality Indicator)
// of the last received packet, lower is better
Serial.print(F("[CC1101] LQI:\t\t"));
Serial.println(radio.getLQI());
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// put module back to listen mode
radio.startReceive();
// we're ready to receive more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,121 @@
/*
RadioLib CC1101 Settings Example
This example shows how to change all the properties of RF69 radio.
RadioLib currently supports the following settings:
- pins (SPI slave select, digital IO 0, digital IO 1)
- carrier frequency
- bit rate
- receiver bandwidth
- allowed frequency deviation
- output power during transmission
- sync word
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// CC1101 has the following connections:
// CS pin: 10
// GDO0 pin: 2
// RST pin: unused
// GDO2 pin: 3 (optional)
CC1101 radio1 = new Module(10, 2, RADIOLIB_NC, 3);
// second CC1101 has different connections:
// CS pin: 9
// GDO0 pin: 4
// RST pin: unused
// GDO2 pin: 5 (optional)
CC1101 radio2 = new Module(9, 4, RADIOLIB_NC, 53);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 radio3 = RadioShield.ModuleB;
void setup() {
Serial.begin(9600);
// initialize CC1101 with default settings
Serial.print(F("[CC1101] Initializing ... "));
int state = radio1.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// initialize CC1101 with non-default settings
Serial.print(F("[CC1101] Initializing ... "));
// carrier frequency: 434.0 MHz
// bit rate: 32.0 kbps
// frequency deviation: 60.0 kHz
// Rx bandwidth: 250.0 kHz
// output power: 7 dBm
// preamble length: 32 bits
state = radio2.begin(434.0, 32.0, 60.0, 250.0, 7, 32);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// you can also change the settings at runtime
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
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 == RADIOLIB_ERR_INVALID_BIT_RATE) {
Serial.println(F("[CC1101] Selected bit rate is invalid for this module!"));
while (true);
} 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) == 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) == 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) == 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) == RADIOLIB_ERR_INVALID_SYNC_WORD) {
Serial.println(F("[CC1101] Selected sync word is invalid for this module!"));
while (true);
}
}
void loop() {
// nothing here
}

View File

@ -0,0 +1,75 @@
/*
RadioLib CC1101 Transmit Example
This example transmits packets using CC1101 FSK radio module.
Each packet contains up to 64 bytes of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// CC1101 has the following connections:
// CS pin: 10
// GDO0 pin: 2
// RST pin: unused
// GDO2 pin: 3 (optional)
CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize CC1101 with default settings
Serial.print(F("[CC1101] 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);
}
}
void loop() {
Serial.print(F("[CC1101] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to 63 characters long
int state = radio.transmit("Hello World!");
// you can also transmit byte array up to 63 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 64 bytes
Serial.println(F("too long!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,107 @@
/*
RadioLib CC1101 Transmit to Address Example
This example transmits packets using CC1101 FSK radio
module. Packets can have 1-byte address of the
destination node. After setting node address, this node
will automatically filter out any packets that do not
contain either node address or broadcast addresses.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// CC1101 has the following connections:
// CS pin: 10
// GDO0 pin: 2
// RST pin: unused
// GDO2 pin: 3 (optional)
CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize CC1101 with default settings
Serial.print(F("[CC1101] 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 node address
// NOTE: Calling this method will automatically enable
// address filtering. CC1101 also allows to set
// number of broadcast address (0/1/2).
// The following sets one broadcast address 0x00.
// When setting two broadcast addresses, 0x00 and
// 0xFF will be used.
Serial.print(F("[CC1101] Setting node address ... "));
state = radio.setNodeAddress(0x01, 1);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// address filtering can also be disabled
// NOTE: Calling this method will also erase previously
// set node address
/*
Serial.print(F("[CC1101] Disabling address filtering ... "));
state == radio.disableAddressFiltering();
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("[CC1101] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to 63 characters long
int state = radio.transmit("Hello World!");
// you can also transmit byte array up to 63 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 255 bytes
Serial.println(F("too long!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,133 @@
/*
RadioLib CC1101 Transmit with Interrupts Example
This example transmits packets using CC1101 FSK radio module.
Once a packet is transmitted, an interrupt is triggered.
Each packet contains up to 64 bytes of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#cc1101
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// CC1101 has the following connections:
// CS pin: 10
// GDO0 pin: 2
// RST pin: unused
// GDO2 pin: 3 (optional)
CC1101 radio = new Module(10, 2, RADIOLIB_NC, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//CC1101 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
// initialize CC1101 with default settings
Serial.print(F("[CC1101] 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 packet transmission is finished
radio.setGdo0Action(setFlag);
// start transmitting the first packet
Serial.print(F("[CC1101] Sending first packet ... "));
// you can transmit C-string or Arduino string up to
// 64 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x56,
0x78, 0xAB, 0xCD, 0xEF};
state = radio.startTransmit(byteArr, 8);
*/
}
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we sent a packet, set the flag
transmittedFlag = true;
}
void loop() {
// check if the previous transmission finished
if(transmittedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
transmittedFlag = false;
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
// NOTE: when using interrupt-driven transmit method,
// it is not possible to automatically measure
// transmission data rate using getDataRate()
} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
// wait a second before transmitting again
delay(1000);
// send another one
Serial.print(F("[CC1101] Sending another packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.startTransmit(byteArr, 8);
*/
// we're ready to send more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,125 @@
/*
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);
}
}
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,118 @@
/*
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);
}
}
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

@ -0,0 +1,116 @@
/*
RadioLib Hellschreiber Transmit Example
This example sends Hellschreiber message using
SX1278's FSK modem.
Other modules that can be used for Hellschreiber:
- 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 Hellschreiber client instance using the FSK module
HellClient hell(&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 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 Hellschreiber client
Serial.print(F("[Hell] Initializing ... "));
// base frequency: 434.0 MHz
// speed: 122.5 Baud ("Feld Hell")
state = hell.begin(434.0);
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("[Hell] Sending Hellschreiber data ... "));
// HellClient supports all methods of the Serial class
// NOTE: Lower case letter will be capitalized.
// Arduino String class
String aStr = "Arduino String";
hell.print(aStr);
// character array (C-String)
hell.print("C-String");
// string saved in flash
hell.print(F("Flash String"));
// character
hell.print('c');
// byte
// formatting DEC/HEX/OCT/BIN is supported for
// any integer type (byte/int/long)
hell.print(255, HEX);
// integer number
int i = 1000;
hell.print(i);
// floating point number
// NOTE: println() has no effect on the transmission,
// and is only kept for compatibility reasons.
float f = -3.1415;
hell.println(f, 3);
// custom glyph - must be a 7 byte array of rows 7 pixels long
uint8_t customGlyph[] = { 0b0000000, 0b0010100, 0b0010100, 0b0000000, 0b0100010, 0b0011100, 0b0000000 };
hell.printGlyph(customGlyph);
Serial.println(F("done!"));
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,119 @@
/*
RadioLib Hellschreiber Transmit AFSK Example
This example sends Hellschreiber message using
SX1278's FSK modem. The data is modulated
as AFSK.
Other modules that can be used for Hellschreiber
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 Hellschreiber client instance using the AFSK instance
HellClient hell(&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 Hellschreiber client
Serial.print(F("[Hell] Initializing ... "));
// AFSK tone frequency: 400 Hz
// speed: 122.5 Baud ("Feld Hell")
state = hell.begin(400);
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("[Hell] Sending Hellschreiber data ... "));
// HellClient supports all methods of the Serial class
// NOTE: Lower case letter will be capitalized.
// Arduino String class
String aStr = "Arduino String";
hell.print(aStr);
// character array (C-String)
hell.print("C-String");
// string saved in flash
hell.print(F("Flash String"));
// character
hell.print('c');
// byte
// formatting DEC/HEX/OCT/BIN is supported for
// any integer type (byte/int/long)
hell.print(255, HEX);
// integer number
int i = 1000;
hell.print(i);
// floating point number
// NOTE: println() has no effect on the transmission,
// and is only kept for compatibility reasons.
float f = -3.1415;
hell.println(f, 3);
// custom glyph - must be a 7 byte array of rows 7 pixels long
uint8_t customGlyph[] = { 0b0000000, 0b0010100, 0b0010100, 0b0000000, 0b0100010, 0b0011100, 0b0000000 };
hell.printGlyph(customGlyph);
Serial.println(F("done!"));
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,117 @@
/*
RadioLib Morse Transmit Example
This example sends Morse code message using
SX1278's FSK modem.
Other modules that can be used for Morse Code:
- 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 Morse client instance using the FSK module
MorseClient morse(&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 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 ... "));
// base frequency: 434.0 MHz
// speed: 20 words per minute
state = morse.begin(434.0);
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

@ -0,0 +1,120 @@
/*
RadioLib Morse Transmit AFSK Example
This example sends Morse code message using
SX1278's FSK modem. The data is modulated
as AFSK.
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();
// 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 ... "));
// AFSK tone frequency: 400 MHz
// 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);
}
}
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

@ -0,0 +1,88 @@
/*
RadioLib RF69 Receive Example
This example receives packets using RF69 FSK radio module.
To successfully receive data, the following settings have to be the same
on both transmitter and receiver:
- carrier frequency
- bit rate
- frequency deviation
- sync word
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
RF69 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize RF69 with default settings
Serial.print(F("[RF69] 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);
}
}
void loop() {
Serial.print(F("[RF69] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[RF69] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
} 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!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View File

@ -0,0 +1,92 @@
/*
RadioLib RF69 Receive with AES Example
This example receives packets using RF69 FSK radio module.
Packets are decrypted using hardware AES.
NOTE: When using address filtering, the address byte is NOT encrypted!
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
RF69 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize RF69 with default settings
Serial.print(F("[RF69] 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 AES key that will be used to decrypt the packet
// NOTE: the key must be exactly 16 bytes long!
uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
radio.setAESKey(key);
// enable AES encryption
radio.enableAES();
// AES encryption can also be disabled
/*
radio.disableAES();
*/
}
void loop() {
Serial.print(F("[RF69] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str);
} 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!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View File

@ -0,0 +1,121 @@
/*
RadioLib RF69 Receive with Address Example
This example receives packets using RF69 FSK radio module.
Packets can have 1-byte address of the destination node.
After setting node (or broadcast) address, this node will
automatically filter out any packets that do not contain
either node address or broadcast address.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
RF69 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize RF69 with default settings
Serial.print(F("[RF69] 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 node address
// NOTE: calling this method will automatically enable
// address filtering (node address only)
Serial.print(F("[RF69] Setting node address ... "));
state = radio.setNodeAddress(0x02);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set broadcast address
// NOTE: calling this method will automatically enable
// address filtering (node or broadcast address)
Serial.print(F("[RF69] Setting broadcast address ... "));
state = radio.setBroadcastAddress(0xFF);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// address filtering can also be disabled
// NOTE: calling this method will also erase previously set
// node and broadcast address
/*
Serial.print(F("[RF69] Disabling address filtering ... "));
state == radio.disableAddressFiltering();
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("[RF69] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str);
} 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!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View File

@ -0,0 +1,140 @@
/*
RadioLib RF69 Receive with Interrupts Example
This example listens for FSK transmissions and tries to
receive them. Once a packet is received, an interrupt is
triggered.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
RF69 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize RF69 with default settings
Serial.print(F("[RF69] 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);
// start listening for packets
Serial.print(F("[RF69] 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);
}
// if needed, 'listen' mode can be disabled by calling
// any of the following methods:
//
// radio.standby()
// radio.sleep()
// radio.transmit();
// radio.receive();
// radio.readData();
}
// flag to indicate that a packet was received
volatile bool receivedFlag = 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we got a packet, set the flag
receivedFlag = true;
}
void loop() {
// check if the flag is set
if(receivedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
receivedFlag = false;
// 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("[RF69] Received packet!"));
// print data of the packet
Serial.print(F("[RF69] Data:\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[RF69] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// put module back to listen mode
radio.startReceive();
// we're ready to receive more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,139 @@
/*
RadioLib RF69 Settings Example
This example shows how to change all the properties of RF69 radio.
RadioLib currently supports the following settings:
- pins (SPI slave select, digital IO 0, digital IO 1)
- carrier frequency
- bit rate
- receiver bandwidth
- allowed frequency deviation
- output power during transmission
- sync word
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
RF69 radio1 = new Module(10, 2, 3);
// second CC1101 has different connections:
// CS pin: 9
// DIO0 pin: 4
// RESET pin: 5
RF69 radio2 = new Module(9, 4, 5);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 radio3 = RadioShield.ModuleB;
void setup() {
Serial.begin(9600);
// initialize RF69 with default settings
Serial.print(F("[RF69] Initializing ... "));
int state = radio1.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// initialize RF69 with non-default settings
Serial.print(F("[RF69] Initializing ... "));
// carrier frequency: 868.0 MHz
// bit rate: 300.0 kbps
// frequency deviation: 60.0 kHz
// Rx bandwidth: 250.0 kHz
// output power: 17 dBm
// preamble length: 32 bits
state = radio2.begin(868.0, 300.0, 60.0, 250.0, 17, 32);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// you can also change the settings at runtime
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
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 == RADIOLIB_ERR_INVALID_BIT_RATE) {
Serial.println(F("[RF69] Selected bit rate is invalid for this module!"));
while (true);
} 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);
}
// set receiver bandwidth to 250.0 kHz
state = radio1.setRxBandwidth(250.0);
if (state == RADIOLIB_ERR_INVALID_RX_BANDWIDTH) {
Serial.println(F("[RF69] Selected receiver bandwidth is invalid for this module!"));
while (true);
} 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) == 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) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
Serial.println(F("[RF69] Selected output power is invalid for this module!"));
while (true);
}
// up to 8 bytes can be set as sync word
// 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) == RADIOLIB_ERR_INVALID_SYNC_WORD) {
Serial.println(F("[RF69] Selected sync word is invalid for this module!"));
while (true);
}
Serial.println(F("[RF69] All settings changed successfully!"));
// RF69 can also measure temperature (roughly)
// to get correct temperature measurements, the sensor must be calibrated
// at ambient temperature
radio1.setAmbientTemperature(25); // replace 25 with your ambient temperature
}
void loop() {
// measure temperature
Serial.print(F("[RF69] Measured temperature: "));
Serial.print(radio1.getTemperature());
Serial.println(F(" deg C"));
// wait 100 ms before the next measurement
delay(100);
}

View File

@ -0,0 +1,91 @@
/*
RadioLib RF69 Transmit Example
This example transmits packets using RF69 FSK radio module.
Each packet contains up to 64 bytes of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
RF69 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize RF69 with default settings
Serial.print(F("[RF69] 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);
}
// NOTE: some RF69 modules use high power output,
// those are usually marked RF69H(C/CW).
// To configure RadioLib for these modules,
// you must call setOutputPower() with
// second argument set to true.
/*
Serial.print(F("[RF69] Setting high power module ... "));
state = radio.setOutputPower(20, 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("[RF69] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to 64 characters long
int state = radio.transmit("Hello World!");
// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 64 bytes
Serial.println(F("too long!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,86 @@
/*
RadioLib RF69 Transmit with AES Example
This example transmits packets using RF69 FSK radio module.
Packets are encrypted using hardware AES.
NOTE: When using address filtering, the address byte is NOT encrypted!
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
RF69 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize RF69 with default settings
Serial.print(F("[RF69] 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 AES key to encrypt the packet
// NOTE: the key must be exactly 16 bytes long!
uint8_t key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
radio.setAESKey(key);
// enable AES encryption
radio.enableAES();
// AES encryption can also be disabled
/*
radio.disableAES();
*/
}
void loop() {
Serial.print(F("[RF69] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to 64 characters long
int state = radio.transmit("Hello World!");
// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 64 bytes
Serial.println(F("too long!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,126 @@
/*
RadioLib RF69 Transmit to Address Example
This example transmits packets using RF69 FSK radio module.
Packets can have 1-byte address of the destination node.
After setting node (or broadcast) address, this node will
automatically filter out any packets that do not contain
either node address or broadcast address.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
RF69 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize RF69 with default settings
Serial.print(F("[RF69] 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 node address
// NOTE: calling this method will automatically enable
// address filtering (node address only)
Serial.print(F("[RF69] Setting node address ... "));
state = radio.setNodeAddress(0x01);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// set broadcast address
// NOTE: calling this method will automatically enable
// address filtering (node or broadcast address)
Serial.print(F("[RF69] Setting broadcast address ... "));
state = radio.setBroadcastAddress(0xFF);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// address filtering can also be disabled
// NOTE: calling this method will also erase previously set
// node and broadcast address
/*
Serial.print(F("[RF69] Disabling address filtering ... "));
state = radio.disableAddressFiltering();
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("[RF69] Transmitting packet ... "));
// transmit C-string or Arduino string to node with address 0x02
int state = radio.transmit("Hello World!", 0x02);
// transmit byte array to node with address 0x02
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8, 0x02);
*/
// transmit C-string or Arduino string in broadcast mode
/*
int state = radio.transmit("Hello World!", 0xFF);
*/
// transmit byte array in broadcast mode
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8, 0xFF);
*/
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 64 bytes
Serial.println(F("too long!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,149 @@
/*
RadioLib RF69 Transmit with Interrupts Example
This example transmits FSK packets with one second delays
between them. Each packet contains up to 64 bytes
of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// RF69 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
RF69 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//RF69 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
// initialize RF69 with default settings
Serial.print(F("[RF69] 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 packet transmission is finished
radio.setDio0Action(setFlag);
// NOTE: some RF69 modules use high power output,
// those are usually marked RF69H(C/CW).
// To configure RadioLib for these modules,
// you must call setOutputPower() with
// second argument set to true.
/*
Serial.print(F("[RF69] Setting high power module ... "));
state = radio.setOutputPower(20, true);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
*/
// start transmitting the first packet
Serial.print(F("[RF69] Sending first packet ... "));
// you can transmit C-string or Arduino string up to
// 64 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.startTransmit(byteArr, 8);
*/
}
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we sent a packet, set the flag
transmittedFlag = true;
}
void loop() {
// check if the previous transmission finished
if(transmittedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
transmittedFlag = false;
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
// NOTE: when using interrupt-driven transmit method,
// it is not possible to automatically measure
// transmission data rate using getDataRate()
} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
// wait a second before transmitting again
delay(1000);
// send another one
Serial.print(F("[RF69] Sending another packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.startTransmit(byteArr, 8);
*/
// we're ready to send more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,140 @@
/*
RadioLib RTTY Transmit Example
This example sends RTTY message using SX1278's
FSK modem.
Other modules that can be used for RTTY:
- 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 RTTY client instance using the FSK module
RTTYClient rtty(&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 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 RTTY client
// NOTE: RTTY 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("[RTTY] Initializing ... "));
// low ("space") frequency: 434.0 MHz
// frequency shift: 183 Hz
// baud rate: 45 baud
// encoding: ASCII (7-bit)
// stop bits: 1
state = rtty.begin(434.0, 183, 45);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
/*
// RadioLib also provides ITA2 ("Baudot") support
rtty.begin(434, 183, 45, ITA2);
// All transmissions in loop() (strings and numbers)
// will now be encoded using ITA2 code
// ASCII characters that do not have ITA2 equivalent
// will be sent as NUL (including lower case letters!)
*/
}
void loop() {
Serial.print(F("[RTTY] Sending RTTY data ... "));
// send out idle condition for 500 ms
rtty.idle();
delay(500);
// RTTYClient supports all methods of the Serial class
// Arduino String class
String aStr = "Arduino String";
rtty.println(aStr);
// character array (C-String)
rtty.println("C-String");
// string saved in flash
rtty.println(F("Flash String"));
// character
rtty.println('c');
// byte
// formatting DEC/HEX/OCT/BIN is supported for
// any integer type (byte/int/long)
rtty.println(255, HEX);
// integer number
int i = 1000;
rtty.println(i);
// floating point number
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
delay(1000);
}

View File

@ -0,0 +1,133 @@
/*
RadioLib RTTY Transmit AFSK Example
This example sends RTTY message using SX1278's
FSK modem. The data is modulated as AFSK.
Other modules that can be used for RTTY:
- 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 RTTY client instance using the AFSK instance
RTTYClient rtty(&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 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 RTTY client
// NOTE: Unlike FSK RTTY, AFSK requires no rounding of
// the frequency shift.
Serial.print(F("[RTTY] Initializing ... "));
// space frequency: 400 Hz
// frequency shift: 170 Hz
// baud rate: 45 baud
// encoding: ASCII (7-bit)
// stop bits: 1
state = rtty.begin(400, 170, 45);
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
/*
// RadioLib also provides ITA2 ("Baudot") support
rtty.begin(400, 170, 45, ITA2);
// All transmissions in loop() (strings and numbers)
// will now be encoded using ITA2 code
// ASCII characters that do not have ITA2 equivalent
// will be sent as NUL (including lower case letters!)
*/
}
void loop() {
Serial.print(F("[RTTY] Sending RTTY data ... "));
// send out idle condition for 500 ms
rtty.idle();
delay(500);
// RTTYClient supports all methods of the Serial class
// Arduino String class
String aStr = "Arduino String";
rtty.println(aStr);
// character array (C-String)
rtty.println("C-String");
// string saved in flash
rtty.println(F("Flash String"));
// character
rtty.println('c');
// byte
// formatting DEC/HEX/OCT/BIN is supported for
// any integer type (byte/int/long)
rtty.println(255, HEX);
// integer number
int i = 1000;
rtty.println(i);
// floating point number
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
delay(1000);
}

View File

@ -0,0 +1,156 @@
/*
RadioLib SSTV Transmit Example
The following example sends SSTV picture using
SX1278's FSK modem.
Other modules that can be used for SSTV:
- SX127x/RFM9x
- RF69
- SX1231
- SX126x
NOTE: SSTV is an analog modulation, and
requires precise frequency control.
Some of the above modules can only
set their frequency in rough steps,
so the result can be distorted.
Using high-precision radio with TCXO
(like SX126x) is recommended.
NOTE: Some platforms (such as Arduino Uno)
might not be fast enough to correctly
send pictures via high-speed modes
like Scottie2 or Martin2. For those,
lower speed modes such as Wrasse,
Scottie1 or Martin1 are recommended.
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 SSTV client instance using the FSK module
SSTVClient sstv(&radio);
// test "image" - actually just a single 320px line
// will be sent over and over again, to create vertical color stripes at the receiver
uint32_t line[320] = {
// black
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
// blue
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
// green
0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00,
0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00,
// cyan
0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF,
0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF,
// red
0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000,
0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000,
// magenta
0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF,
0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF,
// yellow
0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00,
0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00,
// white
0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF,
0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF
};
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 SSTV
// (RF69, SX1231 etc.), use the basic begin() method
// int state = radio.begin();
// initialize SSTV client
Serial.print(F("[SSTV] Initializing ... "));
// 0 Hz tone frequency: 434.0 MHz
// SSTV mode: Wrasse (SC2-180)
// correction factor: 0.95
// NOTE: Due to different speeds of various platforms
// supported by RadioLib (Arduino Uno, ESP32 etc),
// and because SSTV is analog protocol, incorrect
// timing of pulses can lead to distortions.
// To compensate, correction factor can be used
// 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 == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// to help tune the receiver, SSTVClient can send
// continuous beep at the frequency corresponding to
// 1900 Hz in upper sideband (aka USB) modulation
// (SSTV header "leader tone")
/*
sstv.idle();
while(true);
*/
}
void loop() {
// send picture with 8 color stripes
Serial.print(F("[SSTV] Sending test picture ... "));
// send synchronization header first
sstv.sendHeader();
// send all picture lines
for(uint16_t i = 0; i < sstv.getPictureHeight(); i++) {
sstv.sendLine(line);
}
// turn off transmitter
radio.standby();
Serial.println(F("done!"));
delay(30000);
}

View File

@ -0,0 +1,152 @@
/*
RadioLib SSTV Transmit AFSK Example
The following example sends SSTV picture using
SX1278's FSK modem. The data is modulated
as AFSK.
Other modules that can be used for SSTV:
with AFSK modulation:
- SX127x/RFM9x
- RF69
- SX1231
- CC1101
- Si443x/RFM2x
NOTE: Some platforms (such as Arduino Uno)
might not be fast enough to correctly
send pictures via high-speed modes
like Scottie2 or Martin2. For those,
lower speed modes such as Wrasse,
Scottie1 or Martin1 are recommended.
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 SSTV client instance using the AFSK instance
SSTVClient sstv(&audio);
// test "image" - actually just a single 320px line
// will be sent over and over again, to create vertical color stripes at the receiver
uint32_t line[320] = {
// black
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000, 0x000000,
// blue
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF, 0x0000FF,
// green
0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00,
0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00, 0x00FF00,
// cyan
0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF,
0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF, 0x00FFFF,
// red
0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000,
0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000, 0xFF0000,
// magenta
0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF,
0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF, 0xFF00FF,
// yellow
0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00,
0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00, 0xFFFF00,
// white
0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF,
0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF
};
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 SSTV
// (RF69, SX1231 etc.), use the basic begin() method
// int state = radio.begin();
// initialize SSTV client
Serial.print(F("[SSTV] Initializing ... "));
// SSTV mode: Wrasse (SC2-180)
// correction factor: 0.95
// NOTE: Due to different speeds of various platforms
// supported by RadioLib (Arduino Uno, ESP32 etc),
// and because SSTV is analog protocol, incorrect
// timing of pulses can lead to distortions.
// To compensate, correction factor can be used
// 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 == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while(true);
}
// to help tune the receiver, SSTVClient can send
// continuous 1900 Hz beep
/*
sstv.idle();
while(true);
*/
}
void loop() {
// send picture with 8 color stripes
Serial.print(F("[SSTV] Sending test picture ... "));
// send synchronization header first
sstv.sendHeader();
// send all picture lines
for(uint16_t i = 0; i < sstv.getPictureHeight(); i++) {
sstv.sendLine(line);
}
// turn off transmitter
radio.standby();
Serial.println(F("done!"));
delay(30000);
}

View File

@ -0,0 +1,80 @@
/*
RadioLib SX1231 Receive Example
This example receives packets using SX1231 FSK radio module.
NOTE: SX1231 offers the same features as RF69 and has the same
interface. Please see RF69 examples for examples on AES,
address filtering, interrupts and settings.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1231 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
SX1231 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1231 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1231 with default settings
Serial.print(F("[SX1231] 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);
}
}
void loop() {
Serial.print(F("[SX1231] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[SX1231] Data:\t\t"));
Serial.println(str);
} 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!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View File

@ -0,0 +1,69 @@
/*
RadioLib SX1231 Transmit Example
This example transmits packets using SX1231 FSK radio module.
NOTE: SX1231 offers the same features as RF69 and has the same
interface. Please see RF69 examples for examples on AES,
address filtering, interrupts and settings.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#rf69sx1231
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1231 has the following connections:
// CS pin: 10
// DIO0 pin: 2
// RESET pin: 3
SX1231 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1231 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1231 with default settings
Serial.print(F("[SX1231] 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);
}
}
void loop() {
Serial.print(F("[SX1231] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to 256 characters long
int state = radio.transmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(F("too long!"));
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,70 @@
/*
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;
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);
}
}
void loop() {
Serial.print(F("[SX1262] Scanning channel for LoRa transmission ... "));
// start scanning current channel
int state = radio.scanChannel();
if (state == RADIOLIB_LORA_DETECTED) {
// LoRa preamble was detected
Serial.println(F("detected!"));
} else if (state == RADIOLIB_CHANNEL_FREE) {
// no preamble was detected, channel is free
Serial.println(F("channel is free!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait 100 ms before new scan
delay(100);
}

View File

@ -0,0 +1,123 @@
/*
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;
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!
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

@ -0,0 +1,154 @@
/*
RadioLib SX126x FSK Modem Example
This example shows how to use FSK modem in SX126x chips.
NOTE: The sketch below is just a guide on how to use
FSK modem, so this code should not be run directly!
Instead, modify the other examples to use FSK
modem and use the appropriate configuration
methods.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx126x---fsk-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;
void setup() {
Serial.begin(9600);
// initialize SX1262 FSK modem with default settings
Serial.print(F("[SX1262] 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);
}
// if needed, you can switch between LoRa and FSK modes
//
// radio.begin() start LoRa mode (and disable FSK)
// radio.beginFSK() start FSK mode (and disable LoRa)
// the following settings can also
// be modified at run-time
state = radio.setFrequency(433.5);
state = radio.setBitRate(100.0);
state = radio.setFrequencyDeviation(10.0);
state = radio.setRxBandwidth(250.0);
state = radio.setOutputPower(10.0);
state = radio.setCurrentLimit(100.0);
state = radio.setDataShaping(RADIOLIB_SHAPING_1_0);
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.setSyncWord(syncWord, 8);
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("Unable to set configuration, code "));
Serial.println(state);
while (true);
}
// FSK modem on SX126x can handle the sync word setting in bits, not just
// whole bytes. The value used is left-justified.
// This makes same result as radio.setSyncWord(syncWord, 8):
state = radio.setSyncBits(syncWord, 64);
// This will use 0x012 as sync word (12 bits only):
state = radio.setSyncBits(syncWord, 12);
// FSK modem allows advanced CRC configuration
// Default is CCIT CRC16 (2 bytes, initial 0x1D0F, polynomial 0x1021, inverted)
// Set CRC to IBM CRC (2 bytes, initial 0xFFFF, polynomial 0x8005, non-inverted)
state = radio.setCRC(2, 0xFFFF, 0x8005, false);
// set CRC length to 0 to disable CRC
#warning "This sketch is just an API guide! Read the note at line 6."
}
void loop() {
// FSK modem can use the same transmit/receive methods
// as the LoRa modem, even their interrupt-driven versions
// transmit FSK packet
int state = radio.transmit("Hello World!");
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1262] Packet transmitted successfully!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Serial.println(F("[SX1262] Packet too long!"));
} 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 "));
Serial.println(state);
}
// receive FSK packet
String str;
state = radio.receive(str);
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1262] Received packet!"));
Serial.print(F("[SX1262] Data:\t"));
Serial.println(str);
} 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 "));
Serial.println(state);
}
// FSK modem has built-in address filtering system
// it can be enabled by setting node address, broadcast
// address, or both
//
// to transmit packet to a particular address,
// use the following methods:
//
// radio.transmit("Hello World!", address);
// radio.startTransmit("Hello World!", address);
// set node address to 0x02
state = radio.setNodeAddress(0x02);
// set broadcast address to 0xFF
state = radio.setBroadcastAddress(0xFF);
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1262] Unable to set address filter, code "));
Serial.println(state);
}
// address filtering can also be disabled
// NOTE: calling this method will also erase previously set
// node and broadcast address
/*
state = radio.disableAddressFiltering();
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("Unable to remove address filter, code "));
}
*/
}

View File

@ -0,0 +1,159 @@
/*
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;
// 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 aor received 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

@ -0,0 +1,102 @@
/*
RadioLib SX126x Receive Example
This example listens for LoRa transmissions using SX126x Lora modules.
To successfully receive data, the following settings have to be the same
on both transmitter and receiver:
- carrier frequency
- bandwidth
- spreading factor
- coding rate
- sync word
- preamble length
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;
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);
}
}
void loop() {
Serial.print(F("[SX1262] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
// NOTE: receive() is a blocking method!
// See example ReceiveInterrupt for details
// on non-blocking reception method.
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[SX1262] Data:\t\t"));
Serial.println(str);
// print the RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[SX1262] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print the SNR (Signal-to-Noise Ratio)
// of the last received packet
Serial.print(F("[SX1262] SNR:\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
} 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!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View File

@ -0,0 +1,155 @@
/*
RadioLib SX126x Receive with Interrupts Example
This example listens for LoRa transmissions and tries to
receive them. Once a packet is received, an interrupt is
triggered. To successfully receive data, the following
settings have to be the same on both transmitter
and receiver:
- carrier frequency
- bandwidth
- spreading factor
- coding rate
- sync word
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;
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);
// start listening for LoRa packets
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);
}
// if needed, 'listen' mode can be disabled by calling
// any of the following methods:
//
// radio.standby()
// radio.sleep()
// radio.transmit();
// radio.receive();
// radio.readData();
// radio.scanChannel();
}
// flag to indicate that a packet was received
volatile bool receivedFlag = 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we got a packet, set the flag
receivedFlag = true;
}
void loop() {
// check if the flag is set
if(receivedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
receivedFlag = false;
// 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("[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"));
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// put module back to listen mode
radio.startReceive();
// we're ready to receive more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,163 @@
/*
RadioLib SX126x Settings Example
This example shows how to change all the properties of LoRa transmission.
RadioLib currently supports the following settings:
- pins (SPI slave select, DIO1, DIO2, BUSY pin)
- carrier frequency
- bandwidth
- spreading factor
- coding rate
- sync word
- output power during transmission
- CRC
- preamble length
- TCXO voltage
- DIO2 RF switch control
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 radio1 = new Module(10, 2, 3, 9);
// SX12628 has different connections:
// NSS pin: 8
// DIO1 pin: 4
// NRST pin: 5
// BUSY pin: 6
SX1268 radio2 = new Module(8, 4, 5, 6);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1261 radio3 = RadioShield.ModuleB;
void setup() {
Serial.begin(9600);
// initialize SX1268 with default settings
Serial.print(F("[SX1262] Initializing ... "));
int state = radio1.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// initialize the second LoRa instance with
// non-default settings
// this LoRa link will have high data rate,
// but lower range
Serial.print(F("[SX1268] Initializing ... "));
// carrier frequency: 915.0 MHz
// bandwidth: 500.0 kHz
// spreading factor: 6
// coding rate: 5
// sync word: 0x34 (public network/LoRaWAN)
// output power: 2 dBm
// preamble length: 20 symbols
state = radio2.begin(915.0, 500.0, 6, 5, 0x34, 20);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// you can also change the settings at runtime
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
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) == 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) == 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) == 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) != 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) == 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) == 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) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) {
Serial.println(F("Selected preamble length is invalid for this module!"));
while (true);
}
// disable CRC
if (radio1.setCRC(false) == RADIOLIB_ERR_INVALID_CRC_CONFIGURATION) {
Serial.println(F("Selected CRC is invalid for this module!"));
while (true);
}
// 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) == RADIOLIB_ERR_INVALID_TCXO_VOLTAGE) {
Serial.println(F("Selected TCXO voltage is invalid for this module!"));
while (true);
}
// Some SX126x modules use DIO2 as RF switch. To enable
// 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() != RADIOLIB_ERR_NONE) {
Serial.println(F("Failed to set DIO2 as RF switch!"));
while (true);
}
Serial.println(F("All settings succesfully changed!"));
}
void loop() {
// nothing here
}

View File

@ -0,0 +1,100 @@
/*
RadioLib SX126x Transmit Example
This example transmits packets using SX1262 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 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;
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);
}
// some modules have an external RF switch
// controlled via two pins (RX enable, TX enable)
// to enable automatic control of the switch,
// call the following method
// RX enable: 4
// TX enable: 5
/*
radio.setRfSwitchPins(4, 5);
*/
}
void loop() {
Serial.print(F("[SX1262] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
// NOTE: transmit() is a blocking method!
// See example SX126x_Transmit_Interrupt for details
// on non-blocking transmission method.
int state = radio.transmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
// print measured data rate
Serial.print(F("[SX1262] Datarate:\t"));
Serial.print(radio.getDataRate());
Serial.println(F(" bps"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(F("too long!"));
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
// timeout occured while transmitting packet
Serial.println(F("timeout!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,135 @@
/*
RadioLib SX126x Transmit with Interrupts Example
This example transmits LoRa packets with one second delays
between them. 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 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;
// save transmission state between loops
int transmissionState = RADIOLIB_ERR_NONE;
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 packet transmission is finished
radio.setDio1Action(setFlag);
// start transmitting the first packet
Serial.print(F("[SX1262] Sending first packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.startTransmit(byteArr, 8);
*/
}
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we sent a packet, set the flag
transmittedFlag = true;
}
void loop() {
// check if the previous transmission finished
if(transmittedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
transmittedFlag = false;
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
// NOTE: when using interrupt-driven transmit method,
// it is not possible to automatically measure
// transmission data rate using getDataRate()
} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
// wait a second before transmitting again
delay(1000);
// send another one
Serial.print(F("[SX1262] Sending another packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.startTransmit(byteArr, 8);
*/
// we're ready to send more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,66 @@
/*
RadioLib SX127x 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.
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.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);
}
}
void loop() {
Serial.print(F("[SX1278] Scanning channel for LoRa preamble ... "));
// start scanning current channel
int state = radio.scanChannel();
if (state == RADIOLIB_PREAMBLE_DETECTED) {
// LoRa preamble was detected
Serial.println(F("detected preamble!"));
} else if (state == RADIOLIB_CHANNEL_FREE) {
// no preamble was detected, channel is free
Serial.println(F("channel is free!"));
}
// wait 100 ms before new scan
delay(100);
}

View File

@ -0,0 +1,136 @@
/*
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;
// save state between loops
int scanState = RADIOLIB_ERR_NONE;
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 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!
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!
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 got a preamble
if(detectedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
detectedFlag = false;
// LoRa preamble was detected
Serial.print(F("[SX1278] Preamble detected!"));
}
// check if we need to restart channel activity detection
if(detectedFlag || timeoutFlag) {
// 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);
}
}
}

View File

@ -0,0 +1,206 @@
/*
RadioLib SX127x FSK Modem Example
This example shows how to use FSK modem in SX127x chips.
NOTE: The sketch below is just a guide on how to use
FSK modem, so this code should not be run directly!
Instead, modify the other examples to use FSK
modem and use the appropriate configuration
methods.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx127xrfm9x---fsk-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 fsk = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1278 FSK modem 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);
}
// if needed, you can switch between LoRa and FSK modes
//
// radio.begin() start LoRa mode (and disable FSK)
// radio.beginFSK() start FSK mode (and disable LoRa)
// the following settings can also
// be modified at run-time
state = radio.setFrequency(433.5);
state = radio.setBitRate(100.0);
state = radio.setFrequencyDeviation(10.0);
state = radio.setRxBandwidth(250.0);
state = radio.setOutputPower(10.0);
state = radio.setCurrentLimit(100);
state = radio.setDataShaping(RADIOLIB_SHAPING_0_5);
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.setSyncWord(syncWord, 8);
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("Unable to set configuration, code "));
Serial.println(state);
while (true);
}
// FSK modulation can be changed to OOK
// NOTE: When using OOK, the maximum bit rate is only 32.768 kbps!
// Also, data shaping changes from Gaussian filter to
// simple filter with cutoff frequency. Make sure to call
// setDataShapingOOK() to set the correct shaping!
state = radio.setOOK(true);
state = radio.setDataShapingOOK(1);
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("Unable to change modulation, code "));
Serial.println(state);
while (true);
}
#warning "This sketch is just an API guide! Read the note at line 6."
}
void loop() {
// FSK modem can use the same transmit/receive methods
// as the LoRa modem, even their interrupt-driven versions
// NOTE: FSK modem maximum packet length is 63 bytes!
// transmit FSK packet
int state = radio.transmit("Hello World!");
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Packet transmitted successfully!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Serial.println(F("[SX1278] Packet too long!"));
} 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 "));
Serial.println(state);
}
// receive FSK packet
String str;
state = radio.receive(str);
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Received packet!"));
Serial.print(F("[SX1278] Data:\t"));
Serial.println(str);
} 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 "));
Serial.println(state);
}
// FSK modem has built-in address filtering system
// it can be enabled by setting node address, broadcast
// address, or both
//
// to transmit packet to a particular address,
// use the following methods:
//
// radio.transmit("Hello World!", address);
// radio.startTransmit("Hello World!", address);
// set node address to 0x02
state = radio.setNodeAddress(0x02);
// set broadcast address to 0xFF
state = radio.setBroadcastAddress(0xFF);
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Unable to set address filter, code "));
Serial.println(state);
}
// address filtering can also be disabled
// NOTE: calling this method will also erase previously set
// node and broadcast address
/*
state = radio.disableAddressFiltering();
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("Unable to remove address filter, code "));
}
*/
// FSK modem supports direct data transmission
// in this mode, SX127x directly transmits any data
// sent to DIO1 (data) and DIO2 (clock)
// activate direct mode transmitter
state = radio.transmitDirect();
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Unable to start direct transmission mode, code "));
Serial.println(state);
}
// using the direct mode, it is possible to transmit
// FM notes with Arduino tone() function
// it is recommended to set data shaping to 0
// (no shaping) when transmitting audio
state = radio.setDataShaping(0.0);
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Unable to set data shaping, code "));
Serial.println(state);
}
// 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 ESP32, Arduino Due and CubeCell
// on these platforms, the following will do nothing
#if !defined(RADIOLIB_TONE_UNSUPPORTED)
tone(4, 1000);
delay(1000);
tone(4, 500);
delay(1000);
noTone(4);
#endif
// NOTE: after calling transmitDirect(), SX127x will start
// transmitting immediately! This signal can jam other
// devices at the same frequency, it is up to the user
// to disable it with standby() method!
// direct mode transmissions can also be received
// as bit stream on DIO1 (data) and DIO2 (clock)
state = radio.receiveDirect();
if (state != RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1278] Unable to start direct reception mode, code "));
Serial.println(state);
}
// NOTE: you will not be able to send or receive packets
// while direct mode is active! to deactivate it, call method
// radio.packetMode()
}

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 aor 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

@ -0,0 +1,108 @@
/*
RadioLib SX127x Receive Example
This example listens for LoRa transmissions using SX127x Lora modules.
To successfully receive data, the following settings have to be the same
on both transmitter and receiver:
- carrier frequency
- bandwidth
- spreading factor
- coding rate
- sync word
- preamble length
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.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);
}
}
void loop() {
Serial.print(F("[SX1278] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
// NOTE: receive() is a blocking method!
// See example ReceiveInterrupt for details
// on non-blocking reception method.
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[SX1278] Data:\t\t\t"));
Serial.println(str);
// print the RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[SX1278] RSSI:\t\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print the SNR (Signal-to-Noise Ratio)
// of the last received packet
Serial.print(F("[SX1278] SNR:\t\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
// print frequency error
// of the last received packet
Serial.print(F("[SX1278] 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 == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

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,160 @@
/*
RadioLib SX127x Receive with Interrupts Example
This example listens for LoRa transmissions and tries to
receive them. Once a packet is received, an interrupt is
triggered. To successfully receive data, the following
settings have to be the same on both transmitter
and receiver:
- carrier frequency
- bandwidth
- spreading factor
- coding rate
- sync word
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.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);
// 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);
}
// if needed, 'listen' mode can be disabled by calling
// any of the following methods:
//
// radio.standby()
// radio.sleep()
// radio.transmit();
// radio.receive();
// radio.readData();
// radio.scanChannel();
}
// flag to indicate that a packet was received
volatile bool receivedFlag = 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we got a packet, set the flag
receivedFlag = true;
}
void loop() {
// check if the flag is set
if(receivedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
receivedFlag = false;
// 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);
// 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);
}
// put module back to listen mode
radio.startReceive();
// we're ready to receive more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,152 @@
/*
RadioLib SX127x Settings Example
This example shows how to change all the properties of LoRa transmission.
RadioLib currently supports the following settings:
- pins (SPI slave select, digital IO 0, digital IO 1)
- carrier frequency
- bandwidth
- spreading factor
- coding rate
- sync word
- output power during transmission
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 radio1 = new Module(10, 2, 9, 3);
// SX1272 has different connections:
// NSS pin: 9
// DIO0 pin: 4
// RESET pin: 5
// DIO1 pin: 6
SX1272 radio2 = new Module(9, 4, 5, 6);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1276 radio3 = RadioShield.ModuleB;
void setup() {
Serial.begin(9600);
// initialize SX1278 with default settings
Serial.print(F("[SX1278] Initializing ... "));
int state = radio1.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// initialize the second LoRa instance with
// non-default settings
// this LoRa link will have high data rate,
// but lower range
// NOTE: when using spreading factor 6, the total packet
// length has to be known in advance!
// you have to pass the number of expected bytes
// to the receive() method
Serial.print(F("[SX1272] Initializing ... "));
// carrier frequency: 915.0 MHz
// bandwidth: 500.0 kHz
// spreading factor: 6
// coding rate: 5
// sync word: 0x14
// output power: 2 dBm
// preamble length: 20 symbols
// amplifier gain: 1 (maximum gain)
state = radio2.begin(915.0, 500.0, 6, 5, 0x14, 2, 20, 1);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// you can also change the settings at runtime
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
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) == 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) == 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) == 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) != RADIOLIB_ERR_NONE) {
Serial.println(F("Unable to set sync word!"));
while (true);
}
// 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) == 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) == 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) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) {
Serial.println(F("Selected preamble length is invalid for this module!"));
while (true);
}
// 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) == RADIOLIB_ERR_INVALID_GAIN) {
Serial.println(F("Selected gain is invalid for this module!"));
while (true);
}
Serial.println(F("All settings successfully changed!"));
}
void loop() {
// nothing here
}

View File

@ -0,0 +1,100 @@
/*
RadioLib SX127x Transmit 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/
*/
// 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(5, 2, 9, 3);
// 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.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// some modules have an external RF switch
// controlled via two pins (RX enable, TX enable)
// to enable automatic control of the switch,
// call the following method
// RX enable: 4
// TX enable: 5
/*
radio.setRfSwitchPins(4, 5);
*/
}
void loop() {
Serial.print(F("[SX1278] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
// NOTE: transmit() is a blocking method!
// See example SX127x_Transmit_Interrupt for details
// on non-blocking transmission method.
int state = radio.transmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F(" success!"));
// print measured data rate
Serial.print(F("[SX1278] Datarate:\t"));
Serial.print(radio.getDataRate());
Serial.println(F(" bps"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(F("too long!"));
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
// timeout occurred while transmitting packet
Serial.println(F("timeout!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,140 @@
/*
RadioLib SX127x Transmit with Interrupts Example
This example transmits LoRa packets with one second delays
between them. 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/
*/
// 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;
// save transmission state between loops
int transmissionState = RADIOLIB_ERR_NONE;
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 packet transmission is finished
radio.setDio0Action(setFlag);
// start transmitting the first packet
Serial.print(F("[SX1278] Sending first packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.startTransmit(byteArr, 8);
*/
}
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we sent a packet, set the flag
transmittedFlag = true;
}
void loop() {
// check if the previous transmission finished
if(transmittedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
transmittedFlag = false;
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
// NOTE: when using interrupt-driven transmit method,
// it is not possible to automatically measure
// transmission data rate using getDataRate()
} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
// NOTE: in FSK mode, SX127x will not automatically
// turn transmitter off after sending a packet
// set mode to standby to ensure we don't jam others
//radio.standby()
// wait a second before transmitting again
delay(1000);
// send another one
Serial.print(F("[SX1278] Sending another packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.startTransmit(byteArr, 8);
*/
// we're ready to send more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,110 @@
/*
RadioLib SX128x BLE Modem Example
This example shows how to use BLE modem in SX128x chips.
RadioLib does not provide BLE protocol support (yet),
only compatibility with the physical layer.
NOTE: The sketch below is just a guide on how to use
BLE modem, so this code should not be run directly!
Instead, modify the other examples to use BLE
modem and use the appropriate configuration
methods.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---ble-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1280 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1280 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1280 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.beginBLE();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// if needed, you can switch between any of the modems
//
// radio.begin() start LoRa modem (and disable BLE)
// radio.beginBLE() start BLE modem (and disable LoRa)
// the following settings can also
// be modified at run-time
state = radio.setFrequency(2410.5);
state = radio.setBitRate(250);
state = radio.setFrequencyDeviation(100.0);
state = radio.setOutputPower(5);
state = radio.setDataShaping(1.0);
state = radio.setAccessAddress(0x12345678);
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."
}
void loop() {
// BLE modem can use the same transmit/receive methods
// as the LoRa modem, even their interrupt-driven versions
// transmit BLE packet
int state = radio.transmit("Hello World!");
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Packet transmitted successfully!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Serial.println(F("[SX1280] Packet too long!"));
} 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 "));
Serial.println(state);
}
// receive BLE packet
String str;
state = radio.receive(str);
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Received packet!"));
Serial.print(F("[SX1280] Data:\t"));
Serial.println(str);
} 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 "));
Serial.println(state);
}
}

View File

@ -0,0 +1,68 @@
/*
RadioLib SX128x Channel Activity Detection Example
This example uses SX1280 to scan the current LoRa
channel and detect ongoing LoRa transmissions.
Other modules from SX128x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1280 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1280 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1280 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1280 with default settings
Serial.print(F("[SX1280] 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);
}
}
void loop() {
Serial.print(F("[SX1280] Scanning channel for LoRa transmission ... "));
// start scanning current channel
int state = radio.scanChannel();
if (state == RADIOLIB_LORA_DETECTED) {
// LoRa preamble was detected
Serial.println(F("detected!"));
} else if (state == RADIOLIB_CHANNEL_FREE) {
// no preamble was detected, channel is free
Serial.println(F("channel is free!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait 100 ms before new scan
delay(100);
}

View File

@ -0,0 +1,109 @@
/*
RadioLib SX128x FLRC Modem Example
This example shows how to use FLRC modem in SX128x chips.
NOTE: The sketch below is just a guide on how to use
FLRC modem, so this code should not be run directly!
Instead, modify the other examples to use FLRC
modem and use the appropriate configuration
methods.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---flrc-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1280 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1280 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1280 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.beginFLRC();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// if needed, you can switch between any of the modems
//
// radio.begin() start LoRa modem (and disable FLRC)
// radio.beginFLRC() start FLRC modem (and disable LoRa)
// the following settings can also
// be modified at run-time
state = radio.setFrequency(2410.5);
state = radio.setBitRate(520);
state = radio.setCodingRate(2);
state = radio.setOutputPower(5);
state = radio.setDataShaping(1.0);
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67};
state = radio.setSyncWord(syncWord, 4);
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."
}
void loop() {
// FLRC modem can use the same transmit/receive methods
// as the LoRa modem, even their interrupt-driven versions
// transmit FLRC packet
int state = radio.transmit("Hello World!");
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Packet transmitted successfully!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Serial.println(F("[SX1280] Packet too long!"));
} 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 "));
Serial.println(state);
}
// receive FLRC packet
String str;
state = radio.receive(str);
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Received packet!"));
Serial.print(F("[SX1280] Data:\t"));
Serial.println(str);
} 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 "));
Serial.println(state);
}
}

View File

@ -0,0 +1,109 @@
/*
RadioLib SX128x GFSK Modem Example
This example shows how to use GFSK modem in SX128x chips.
NOTE: The sketch below is just a guide on how to use
GFSK modem, so this code should not be run directly!
Instead, modify the other examples to use GFSK
modem and use the appropriate configuration
methods.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---gfsk-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1280 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1280 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1280 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio.beginGFSK();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// if needed, you can switch between any of the modems
//
// radio.begin() start LoRa modem (and disable GFSK)
// radio.beginGFSK() start GFSK modem (and disable LoRa)
// the following settings can also
// be modified at run-time
state = radio.setFrequency(2410.5);
state = radio.setBitRate(200);
state = radio.setFrequencyDeviation(100.0);
state = radio.setOutputPower(5);
state = radio.setDataShaping(RADIOLIB_SHAPING_1_0);
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67, 0x89};
state = radio.setSyncWord(syncWord, 5);
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."
}
void loop() {
// GFSK modem can use the same transmit/receive methods
// as the LoRa modem, even their interrupt-driven versions
// transmit GFSK packet
int state = radio.transmit("Hello World!");
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Packet transmitted successfully!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
Serial.println(F("[SX1280] Packet too long!"));
} 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 "));
Serial.println(state);
}
// receive GFSK packet
String str;
state = radio.receive(str);
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("[SX1280] Received packet!"));
Serial.print(F("[SX1280] Data:\t"));
Serial.println(str);
} 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 "));
Serial.println(state);
}
}

View File

@ -0,0 +1,80 @@
/*
RadioLib SX128x Ranging Example
This example performs ranging exchange between two
SX1280 LoRa radio modules. Ranging allows to measure
distance between the modules using time-of-flight
measurement.
Only SX1280 and SX1282 support ranging!
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1280 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1280 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1280 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1280 with default settings
Serial.print(F("[SX1280] 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);
}
}
void loop() {
Serial.print(F("[SX1280] Ranging ... "));
// start ranging exchange
// range as master: true
// slave address: 0x12345678
int state = radio.range(true, 0x12345678);
// the other module must be configured as slave with the same address
/*
int state = radio.range(false, 0x12345678);
*/
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 == RADIOLIB_ERR_RANGING_TIMEOUT) {
// timed out waiting for ranging packet
Serial.println(F("timed out!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before ranging again
delay(1000);
}

View File

@ -0,0 +1,102 @@
/*
RadioLib SX128x Receive Example
This example listens for LoRa transmissions using SX126x Lora modules.
To successfully receive data, the following settings have to be the same
on both transmitter and receiver:
- carrier frequency
- bandwidth
- spreading factor
- coding rate
- sync word
- preamble length
Other modules from SX128x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1280 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1280 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1280 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1280 with default settings
Serial.print(F("[SX1280] 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);
}
}
void loop() {
Serial.print(F("[SX1280] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
// NOTE: receive() is a blocking method!
// See example ReceiveInterrupt for details
// on non-blocking reception method.
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[SX1280] Data:\t\t"));
Serial.println(str);
// print the RSSI (Received Signal Strength Indicator)
// of the last received packet
Serial.print(F("[SX1280] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print the SNR (Signal-to-Noise Ratio)
// of the last received packet
Serial.print(F("[SX1280] SNR:\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
} 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!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View File

@ -0,0 +1,155 @@
/*
RadioLib SX128x Receive with Interrupts Example
This example listens for LoRa transmissions and tries to
receive them. Once a packet is received, an interrupt is
triggered. To successfully receive data, the following
settings have to be the same on both transmitter
and receiver:
- carrier frequency
- bandwidth
- spreading factor
- coding rate
- sync word
Other modules from SX128x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1280 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1280 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1280 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1280 with default settings
Serial.print(F("[SX1280] 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);
// start listening for LoRa packets
Serial.print(F("[SX1280] 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);
}
// if needed, 'listen' mode can be disabled by calling
// any of the following methods:
//
// radio.standby()
// radio.sleep()
// radio.transmit();
// radio.receive();
// radio.readData();
// radio.scanChannel();
}
// flag to indicate that a packet was received
volatile bool receivedFlag = 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we got a packet, set the flag
receivedFlag = true;
}
void loop() {
// check if the flag is set
if(receivedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
receivedFlag = false;
// 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("[SX1280] Received packet!"));
// print data of the packet
Serial.print(F("[SX1280] Data:\t\t"));
Serial.println(str);
// print RSSI (Received Signal Strength Indicator)
Serial.print(F("[SX1280] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));
// print SNR (Signal-to-Noise Ratio)
Serial.print(F("[SX1280] SNR:\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// put module back to listen mode
radio.startReceive();
// we're ready to receive more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,129 @@
/*
RadioLib SX128x Settings Example
This example shows how to change all the properties of LoRa transmission.
RadioLib currently supports the following settings:
- pins (SPI slave select, DIO1, DIO2, BUSY pin)
- carrier frequency
- bandwidth
- spreading factor
- coding rate
- output power during transmission
- CRC
- preamble length
Other modules from SX128x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1280 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1280 radio1 = new Module(10, 2, 3, 9);
// SX1280 has the following connections:
// NSS pin: 8
// DIO1 pin: 4
// NRST pin: 5
// BUSY pin: 6
SX1281 radio2 = new Module(8, 4, 5, 6);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1282 radio3 = RadioShield.ModuleB;
void setup() {
Serial.begin(9600);
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
int state = radio1.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// initialize the second LoRa instance with
// non-default settings
// this LoRa link will have high data rate,
// but lower range
Serial.print(F("[SX1281] Initializing ... "));
// carrier frequency: 2450.0 MHz
// bandwidth: 1625.0 kHz
// spreading factor: 7
// coding rate: 5
// output power: 2 dBm
// preamble length: 20 symbols
state = radio2.begin(2450.0, 1625.0, 7, 5, 2, 20);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// you can also change the settings at runtime
// and check if the configuration was changed successfully
// set carrier frequency to 2410.5 MHz
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) == 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) == 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) == 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) == 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) == RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH) {
Serial.println(F("Selected preamble length is invalid for this module!"));
while (true);
}
// disable CRC
if (radio1.setCRC(false) == RADIOLIB_ERR_INVALID_CRC_CONFIGURATION) {
Serial.println(F("Selected CRC is invalid for this module!"));
while (true);
}
Serial.println(F("All settings succesfully changed!"));
}
void loop() {
// nothing here
}

View File

@ -0,0 +1,98 @@
/*
RadioLib SX128x Transmit Example
This example transmits packets using SX1280 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 SX128x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1280 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1280 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1280 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize SX1280 with default settings
Serial.print(F("[SX1280] Initializing ... "));
// carrier frequency: 2400.0 MHz
// bandwidth: 812.5 kHz
// spreading factor: 9
// coding rate: 7
// output power: 10 dBm
// preamble length: 12 symbols
// CRC: enabled
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// some modules have an external RF switch
// controlled via two pins (RX enable, TX enable)
// to enable automatic control of the switch,
// call the following method
// RX enable: 4
// TX enable: 5
/*
radio.setRfSwitchPins(4, 5);
*/
}
void loop() {
Serial.print(F("[SX1280] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
// NOTE: transmit() is a blocking method!
// See example SX128x_Transmit_Interrupt for details
// on non-blocking transmission method.
int state = radio.transmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(F("too long!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,131 @@
/*
RadioLib SX128x Transmit with Interrupts Example
This example transmits LoRa packets with one second delays
between them. 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 SX128x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#sx128x---lora-modem
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// SX1280 has the following connections:
// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
SX1280 radio = new Module(10, 2, 3, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1280 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
// initialize SX1280 with default settings
Serial.print(F("[SX1280] 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 packet transmission is finished
radio.setDio1Action(setFlag);
// start transmitting the first packet
Serial.print(F("[SX1280] Sending first packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.startTransmit(byteArr, 8);
*/
}
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we sent a packet, set the flag
transmittedFlag = true;
}
void loop() {
// check if the previous transmission finished
if(transmittedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// 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);
}
// wait a second before transmitting again
delay(1000);
// send another one
Serial.print(F("[SX1280] Sending another packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.startTransmit(byteArr, 8);
*/
// we're ready to send more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,84 @@
/*
RadioLib Si443x Receive Example
This example receives packets using Si443x FSK radio module.
To successfully receive data, the following settings have to be the same
on both transmitter and receiver:
- carrier frequency
- bit rate
- frequency deviation
- sync word
Other modules from Si443x/RFM2x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// Si4432 has the following connections:
// nSEL pin: 10
// nIRQ pin: 2
// SDN pin: 9
Si4432 radio = new Module(10, 2, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//Si4432 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize Si4432 with default settings
Serial.print(F("[Si4432] 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);
}
}
void loop() {
Serial.print(F("[Si4432] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[Si4432] Data:\t\t"));
Serial.println(str);
} 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!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View File

@ -0,0 +1,136 @@
/*
RadioLib Si443x Receive with Interrupts Example
This example listens for FSK transmissions and tries to
receive them. Once a packet is received, an interrupt is
triggered.
Other modules from Si443x/RFM2x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// Si4432 has the following connections:
// nSEL pin: 10
// nIRQ pin: 2
// SDN pin: 9
Si4432 radio = new Module(10, 2, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//Si4432 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize Si4432 with default settings
Serial.print(F("[Si4432] 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.setIrqAction(setFlag);
// start listening for packets
Serial.print(F("[Si4432] 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);
}
// if needed, 'listen' mode can be disabled by calling
// any of the following methods:
//
// radio.standby()
// radio.sleep()
// radio.transmit();
// radio.receive();
// radio.readData();
}
// flag to indicate that a packet was received
volatile bool receivedFlag = 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we got a packet, set the flag
receivedFlag = true;
}
void loop() {
// check if the flag is set
if(receivedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
receivedFlag = false;
// 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("[Si4432] Received packet!"));
// print data of the packet
Serial.print(F("[Si4432] Data:\t\t\t"));
Serial.println(str);
} else if (state == RADIOLIB_ERR_CRC_MISMATCH) {
// packet was received, but is malformed
Serial.println(F("CRC error!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// put module back to listen mode
radio.startReceive();
// we're ready to receive more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,123 @@
/*
RadioLib Si443x Settings Example
This example shows how to change all the properties of RF69 radio.
RadioLib currently supports the following settings:
- pins (SPI slave select, nIRQ, shutdown)
- carrier frequency
- bit rate
- receiver bandwidth
- frequency deviation
- output power during transmission
- sync word
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// Si4432 has the following connections:
// nSEL pin: 10
// nIRQ pin: 2
// SDN pin: 9
Si4432 radio1 = new Module(10, 2, 9);
// Si4432 has the following connections:
// nSEL pin: 8
// nIRQ pin: 3
// SDN pin: 7
Si4432 radio2 = new Module(8, 3, 7);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//Si4432 radio3 = RadioShield.ModuleB;
void setup() {
Serial.begin(9600);
// initialize Si4432 with default settings
Serial.print(F("[Si4432] Initializing ... "));
int state = radio1.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// initialize Si4432 with non-default settings
Serial.print(F("[Si4432] Initializing ... "));
// carrier frequency: 868.0 MHz
// bit rate: 200.0 kbps
// frequency deviation: 60.0 kHz
// Rx bandwidth: 335.5 kHz
// output power: 17 dBm
// preamble length: 32 bits
state = radio2.begin(868.0, 200.0, 60.0, 335.5, 17, 32);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
// you can also change the settings at runtime
// and check if the configuration was changed successfully
// set carrier frequency to 433.5 MHz
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 == RADIOLIB_ERR_INVALID_BIT_RATE) {
Serial.println(F("[Si4432] Selected bit rate is invalid for this module!"));
while (true);
} 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);
}
// set receiver bandwidth to 284.8 kHz
state = radio1.setRxBandwidth(284.8);
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) == 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) == RADIOLIB_ERR_INVALID_OUTPUT_POWER) {
Serial.println(F("[Si4432] Selected output power is invalid for this module!"));
while (true);
}
// 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) == RADIOLIB_ERR_INVALID_SYNC_WORD) {
Serial.println(F("[Si4432] Selected sync word is invalid for this module!"));
while (true);
}
Serial.println(F("[Si4432] All settings changed successfully!"));
}
void loop() {
// nothing here
}

View File

@ -0,0 +1,84 @@
/*
RadioLib Si443x Transmit Example
This example transmits packets using Si4432 FSK radio module.
Each packet contains up to 64 bytes of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
Other modules from Si443x/RFM2x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// Si4432 has the following connections:
// nSEL pin: 10
// nIRQ pin: 2
// SDN pin: 9
Si4432 radio = new Module(10, 2, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//Si4432 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize Si4432 with default settings
Serial.print(F("[Si4432] 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);
}
}
void loop() {
Serial.print(F("[Si4432] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to
// 64 characters long
// NOTE: transmit() is a blocking method!
// See example Si443x_Transmit_Interrupt for details
// on non-blocking transmission method.
int state = radio.transmit("Hello World!");
// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x56, 0x78, 0xAB, 0xCD, 0xEF};
int state = radio.transmit(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F(" success!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 256 bytes
Serial.println(F(" too long!"));
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
// timeout occured while transmitting packet
Serial.println(F(" timeout!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,129 @@
/*
RadioLib Si443x Transmit with Interrupts Example
This example transmits packets using Si4432 FSK radio module.
Each packet contains up to 64 bytes of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
Other modules from Si443x/RFM2x family can also be used.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#si443xrfm2x
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// Si4432 has the following connections:
// nSEL pin: 10
// nIRQ pin: 2
// SDN pin: 9
Si4432 radio = new Module(10, 2, 9);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//Si4432 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
// initialize Si4432 with default settings
Serial.print(F("[Si4432] 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 packet transmission is finished
radio.setIrqAction(setFlag);
// start transmitting the first packet
Serial.print(F("[Si4432] Sending first packet ... "));
// you can transmit C-string or Arduino string up to
// 64 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.startTransmit(byteArr, 8);
*/
}
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we sent a packet, set the flag
transmittedFlag = true;
}
void loop() {
// check if the previous transmission finished
if(transmittedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// 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);
}
// wait a second before transmitting again
delay(1000);
// send another one
Serial.print(F("[Si4432] Sending another packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 64 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.startTransmit(byteArr, 8);
*/
// we're ready to send more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,96 @@
/*
RadioLib nRF24 Receive Example
This example listens for FSK transmissions using nRF24 2.4 GHz radio module.
To successfully receive data, the following settings have to be the same
on both transmitter and receiver:
- carrier frequency
- data rate
- transmit pipe on transmitter must match receive pipe
on receiver
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// nRF24 has the following connections:
// CS pin: 10
// IRQ pin: 2
// CE pin: 3
nRF24 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//nRF24 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize nRF24 with default settings
Serial.print(F("[nRF24] 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 receive pipe 0 address
// NOTE: address width in bytes MUST be equal to the
// width set in begin() or setAddressWidth()
// methods (5 by default)
Serial.print(F("[nRF24] Setting address for receive pipe 0 ... "));
byte addr[] = {0x01, 0x23, 0x45, 0x67, 0x89};
state = radio.setReceivePipe(0, addr);
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("[nRF24] Waiting for incoming transmission ... "));
// you can receive data as an Arduino String
// NOTE: receive() is a blocking method!
// See example ReceiveInterrupt for details
// on non-blocking reception method.
String str;
int state = radio.receive(str);
// you can also receive data as byte array
/*
byte byteArr[8];
int state = radio.receive(byteArr, 8);
*/
if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("success!"));
// print the data of the packet
Serial.print(F("[nRF24] Data:\t\t"));
Serial.println(str);
} else if (state == RADIOLIB_ERR_RX_TIMEOUT) {
// timeout occurred while waiting for a packet
Serial.println(F("timeout!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
}

View File

@ -0,0 +1,150 @@
/*
RadioLib nRF24 Receive Example
This example listens for FSK transmissions using nRF24 2.4 GHz radio module.
Once a packet is received, an interrupt is triggered.
To successfully receive data, the following settings have to be the same
on both transmitter and receiver:
- carrier frequency
- data rate
- transmit pipe on transmitter must match receive pipe
on receiver
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// nRF24 has the following connections:
// CS pin: 10
// IRQ pin: 2
// CE pin: 3
nRF24 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//nRF24 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize nRF24 with default settings
Serial.print(F("[nRF24] 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 receive pipe 0 address
// NOTE: address width in bytes MUST be equal to the
// width set in begin() or setAddressWidth()
// methods (5 by default)
Serial.print(F("[nRF24] Setting address for receive pipe 0 ... "));
byte addr[] = {0x01, 0x23, 0x45, 0x67, 0x89};
state = radio.setReceivePipe(0, addr);
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.setIrqAction(setFlag);
// start listening
Serial.print(F("[nRF24] 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);
}
// if needed, 'listen' mode can be disabled by calling
// any of the following methods:
//
// radio.standby()
// radio.sleep()
// radio.transmit();
// radio.receive();
// radio.readData();
}
// flag to indicate that a packet was received
volatile bool receivedFlag = 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we got a packet, set the flag
receivedFlag = true;
}
void loop() {
// check if the flag is set
if(receivedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
receivedFlag = false;
// 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("[nRF24] Received packet!"));
// print data of the packet
Serial.print(F("[nRF24] Data:\t\t"));
Serial.println(str);
} else {
// some other error occurred
Serial.print(F("[nRF24] Failed, code "));
Serial.println(state);
}
// put module back to listen mode
radio.startReceive();
// we're ready to receive more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,95 @@
/*
RadioLib nRF24 Transmit Example
This example transmits packets using nRF24 2.4 GHz radio module.
Each packet contains up to 32 bytes of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
Packet delivery is automatically acknowledged by the receiver.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// nRF24 has the following connections:
// CS pin: 10
// IRQ pin: 2
// CE pin: 3
nRF24 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//nRF24 radio = RadioShield.ModuleA;
void setup() {
Serial.begin(9600);
// initialize nRF24 with default settings
Serial.print(F("[nRF24] 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 transmit address
// NOTE: address width in bytes MUST be equal to the
// width set in begin() or setAddressWidth()
// methods (5 by default)
byte addr[] = {0x01, 0x23, 0x45, 0x67, 0x89};
Serial.print(F("[nRF24] Setting transmit pipe ... "));
state = radio.setTransmitPipe(addr);
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("[nRF24] Transmitting packet ... "));
// you can transmit C-string or Arduino string up to
// 32 characters long
int state = radio.transmit("Hello World!");
if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Serial.println(F("success!"));
} else if (state == RADIOLIB_ERR_PACKET_TOO_LONG) {
// the supplied packet was longer than 32 bytes
Serial.println(F("too long!"));
} else if (state == RADIOLIB_ERR_ACK_NOT_RECEIVED) {
// acknowledge from destination module
// was not received within 15 retries
Serial.println(F("ACK not received!"));
} else if (state == RADIOLIB_ERR_TX_TIMEOUT) {
// timed out while transmitting
Serial.println(F("timeout!"));
} else {
// some other error occurred
Serial.print(F("failed, code "));
Serial.println(state);
}
// wait for a second before transmitting again
delay(1000);
}

View File

@ -0,0 +1,148 @@
/*
RadioLib nRF24 Transmit with Interrupts Example
This example transmits packets using nRF24 2.4 GHz radio module.
Each packet contains up to 32 bytes of data, in the form of:
- Arduino String
- null-terminated char array (C-string)
- arbitrary binary data (byte array)
Packet delivery is automatically acknowledged by the receiver.
For default module settings, see the wiki page
https://github.com/jgromes/RadioLib/wiki/Default-configuration#nrf24
For full API reference, see the GitHub Pages
https://jgromes.github.io/RadioLib/
*/
// include the library
#include <RadioLib.h>
// nRF24 has the following connections:
// CS pin: 10
// IRQ pin: 2
// CE pin: 3
nRF24 radio = new Module(10, 2, 3);
// or using RadioShield
// https://github.com/jgromes/RadioShield
//nRF24 radio = RadioShield.ModuleA;
// save transmission state between loops
int transmissionState = RADIOLIB_ERR_NONE;
void setup() {
Serial.begin(9600);
// initialize nRF24 with default settings
Serial.print(F("[nRF24] 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 transmit address
// NOTE: address width in bytes MUST be equal to the
// width set in begin() or setAddressWidth()
// methods (5 by default)
byte addr[] = {0x01, 0x23, 0x45, 0x67, 0x89};
Serial.print(F("[nRF24] Setting transmit pipe ... "));
state = radio.setTransmitPipe(addr);
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 packet transmission is finished
radio.setIrqAction(setFlag);
// start transmitting the first packet
Serial.print(F("[nRF24] Sending first packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
state = radio.startTransmit(byteArr, 8);
*/
}
// flag to indicate that a packet was sent
volatile bool transmittedFlag = false;
// disable interrupt when it's not needed
volatile bool enableInterrupt = true;
// 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!
void setFlag(void) {
// check if the interrupt is enabled
if(!enableInterrupt) {
return;
}
// we sent a packet, set the flag
transmittedFlag = true;
}
void loop() {
// check if the previous transmission finished
if(transmittedFlag) {
// disable the interrupt service routine while
// processing the data
enableInterrupt = false;
// reset flag
transmittedFlag = false;
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));
// NOTE: when using interrupt-driven transmit method,
// it is not possible to automatically measure
// transmission data rate using getDataRate()
} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
// wait a second before transmitting again
delay(1000);
// send another one
Serial.print(F("[nRF24] Sending another packet ... "));
// you can transmit C-string or Arduino string up to
// 256 characters long
transmissionState = radio.startTransmit("Hello World!");
// you can also transmit byte array up to 256 bytes long
/*
byte byteArr[] = {0x01, 0x23, 0x45, 0x67,
0x89, 0xAB, 0xCD, 0xEF};
int state = radio.startTransmit(byteArr, 8);
*/
// we're ready to send more packets,
// enable interrupt service routine
enableInterrupt = true;
}
}

View File

@ -0,0 +1,111 @@
import re, sys, argparse
from pathlib import Path
from argparse import RawTextHelpFormatter
'''
TODO list:
1. Parse macro values (the names of bits in all registers in header file)
2. Failed SPI write handling
3. SX126x/SX128x handling
'''
def get_macro_name(value, macros):
for macro in macros:
if macro[1] == value:
return macro[0]
return 'UNKNOWN_VALUE'
def get_macro_value(value):
return ' 0x{0:02X}\n'.format(int(value, 16))
parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter, description='''
RadioLib debug output decoder script. Turns RadioLib Serial dumps into readable text.
Step-by-step guid on how to use the decoder:
1. Uncomment lines 312 (#define RADIOLIB_DEBUG) and 313 (#define RADIOLIB_VERBOSE) in RadioLib/src/BuildOpt.h
2. Recompile and upload the failing Arduino sketch
3. Open Arduino IDE Serial Monitor and enable timestamps
4. Copy the Serial output and save it into a .txt file
5. Run this script
Output will be saved in the file specified by --out and printed to the terminal
''')
parser.add_argument('file', metavar='file', type=str, help='Text file of the debug output')
parser.add_argument('--out', metavar='out', default='./out.txt', type=str, help='Where to save the decoded file (defaults to ./out.txt)')
args = parser.parse_args()
# open the log file
log = open(args.file, 'r').readlines()
# find modules that are in use
used_modules = []
pattern_module = re.compile('(([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?.[0-9]{3} -> )?M\t')
for entry in log:
m = pattern_module.search(entry)
if m != None:
used_modules.append(entry[m.end():].rstrip())
# get paths to all relevant header files
header_files = []
for path in Path('../../src').rglob('*.h'):
for module in used_modules:
if module in path.name:
header_files.append(path)
# extract names of address macros from the header files
macro_addresses = []
pattern_define = re.compile('#define \w* +\w*(\n| +\/\/){1}')
for path in header_files:
file = open(path, 'r').readlines()
for line in file:
m = pattern_define.search(line)
if m != None:
s = re.split(' +', m.group().rstrip())
if (s.__len__() > 1) and ('_REG' in s[1]):
macro_addresses.append([s[1], int(s[2], 0)])
'''
# extract names of value macros for each adddress macro
macro_values = []
for path in header_files:
file = open(path, 'r').readlines()
for line in file:
for module in used_modules:
pattern_addr_macro = re.compile('\/\/ SI443X_REG_\w+'.format(module.capitalize()))
'''
# parse every line in the log file
out = []
pattern_debug = re.compile('(([01]?[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?.[0-9]{3} -> )?[RWM]\t.+')
for entry in log:
m = pattern_debug.search(entry)
if m != None:
s = re.split('( |\t)+', entry.rstrip())
cmd_len = int((s.__len__() - 7)/2)
new_entry = s[0] + s[1] + s[2] + s[3]
if s[4] == 'W':
macro_address = int(s[6], 16)
new_entry += 'write {0:>2} 0x{1:02X} {2}\n'.format(cmd_len, macro_address, get_macro_name(macro_address, macro_addresses))
for i in range(cmd_len):
new_entry += get_macro_value(s[8 + 2*i]);
elif s[4] == 'R':
macro_address = int(s[6], 16)
new_entry += 'read {0:>2} 0x{1:02X} {2}\n'.format(cmd_len, macro_address, get_macro_name(macro_address, macro_addresses))
for i in range(cmd_len):
new_entry += get_macro_value(s[8 + 2*i]);
elif s[4] == 'M':
new_entry += 'module {}\n'.format(s[6])
out.append(new_entry)
else:
out.append(entry)
# write the output file
out_file = open(args.out, 'w')
for line in out:
print(line, end='')
out_file.write(line)
out_file.close()

View File

@ -0,0 +1,22 @@
#include "<module_name>.h"
#if !defined(RADIOLIB_EXCLUDE_<module_name>)
<module_name>::<module_name>(Module* mod) {
/*
Constructor implementation MUST assign the provided "mod" pointer to the private "_mod" pointer.
*/
_mod = mod;
}
int16_t <module_name>::begin() {
/*
"begin" method implementation MUST call the "init" method with appropriate settings.
*/
_mod->init();
/*
"begin" method SHOULD implement some sort of mechanism to verify the connection between Arduino and the module.
For example, reading a version register
*/
}

View File

@ -0,0 +1,99 @@
/*
RadioLib Module Template header file
Before opening pull request, please make sure that:
1. All files MUST be compiled without errors using default Arduino IDE settings.
2. All files SHOULD be compiled without warnings with compiler warnings set to "All".
3. Example sketches MUST be working correctly and MUST be stable enough to run for prolonged periods of time.
4. Writing style SHOULD be consistent.
5. Comments SHOULD be in place for the most important chunks of code and SHOULD be free of typos.
6. To indent, 2 spaces MUST be used.
If at any point you are unsure about the required style, please refer to the rest of the modules.
*/
#if !defined(_RADIOLIB_<module_name>_H) && !defined(RADIOLIB_EXCLUDE_<module_name>)
#if !defined(_RADIOLIB_<module_name>_H)
#define _RADIOLIB_<module_name>_H
/*
Header file for each module MUST include Module.h and TypeDef.h in the src folder.
The header file MAY include additional header files.
*/
#include "../../Module.h"
#include "../../TypeDef.h"
/*
Only use the following include if the module implements methods for OSI physical layer control.
This concerns only modules similar to SX127x/RF69/CC1101 etc.
In this case, your class MUST implement all virtual methods of PhysicalLayer class.
*/
//#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
/*
Register map
Definition of SPI register map SHOULD be placed here. The register map SHOULD have two parts:
1 - Address map: only defines register names and addresses. Register names MUST match names in
official documentation (datasheets etc.).
2 - Variable map: defines variables inside register. This functions as a bit range map for a specific register.
Bit range (MSB and LSB) as well as short description for each variable MUST be provided in a comment.
See RF69 and SX127x header files for examples of register maps.
*/
// <module_name> register map | spaces up to this point
#define RADIOLIB_<module_name>_REG_<register_name> 0x00
// <module_name>_REG_<register_name> MSB LSB DESCRIPTION
#define RADIOLIB_<module_name>_<register_variable> 0b00000000 // 7 0 <description>
/*
Module class definition
The module class MAY inherit from the following classes:
1 - PhysicalLayer: In case the module implements methods for OSI physical layer control (e.g. SX127x).
2 - Common class: In case the module further specifies some more generic class (e.g. SX127x/SX1278)
*/
class <module_name> {
public:
/*
Constructor MUST have only one parameter "Module* mod".
The class MAY implement additional overloaded constructors.
*/
// constructor
<module_name>(Module* mod);
/*
The class MUST implement at least one basic method called "begin".
The "begin" method MUST initialize the module and return the status as int16_t type.
*/
// basic methods
int16_t begin();
/*
The class MAY implement additional methods.
All implemented methods SHOULD return the status as int16_t type.
*/
#if !defined(RADIOLIB_GODMODE)
private:
#endif
/*
The class MUST contain private member "Module* _mod"
*/
Module* _mod;
/*
The class MAY contain additional private variables and/or methods.
Private member variables MUST have a name prefixed with "_" (underscore, ASCII 0x5F)
Usually, these are variables for saving module configuration, or methods that do not have to be exposed to the end user.
*/
};
#endif
#endif

View File

@ -0,0 +1,298 @@
#######################################
# Syntax Coloring Map For RadioLib
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
RadioLib KEYWORD1
RadioShield KEYWORD1
Module KEYWORD1
# modules
CC1101 KEYWORD1
LLCC68 KEYWORD1
nRF24 KEYWORD1
RF69 KEYWORD1
RFM22 KEYWORD1
RFM23 KEYWORD1
RFM95 KEYWORD1
RFM96 KEYWORD1
RFM97 KEYWORD1
RFM98 KEYWORD1
Si4430 KEYWORD1
Si4431 KEYWORD1
Si4432 KEYWORD1
SIM800 KEYWORD1
SX1231 KEYWORD1
SX1261 KEYWORD1
SX1262 KEYWORD1
SX1268 KEYWORD1
SX1272 KEYWORD1
SX1273 KEYWORD1
SX1276 KEYWORD1
SX1277 KEYWORD1
SX1278 KEYWORD1
SX1279 KEYWORD1
SX1280 KEYWORD1
SX1281 KEYWORD1
SX1282 KEYWORD1
# protocols
RTTYClient KEYWORD1
MorseClient KEYWORD1
AX25Client KEYWORD1
AX25Frame KEYWORD1
SSTVClient KEYWORD1
HellClient KEYWORD1
AFSKClient KEYWORD1
FSK4Client KEYWORD1
# SSTV modes
Scottie1 KEYWORD1
Scottie2 KEYWORD1
ScottieDX KEYWORD1
Martin1 KEYWORD1
Martin2 KEYWORD1
Wrasse KEYWORD1
PasokonP3 KEYWORD1
PasokonP5 KEYWORD1
PasokonP7 KEYWORD1
#######################################
# Methods and Functions (KEYWORD2)
#######################################
# RadioLib
ModuleA KEYWORD2
ModuleB KEYWORD2
Module KEYWORD2
# SX127x/RFM9x + RF69 + CC1101
begin KEYWORD2
beginFSK KEYWORD2
transmit KEYWORD2
receive KEYWORD2
scanChannel KEYWORD2
sleep KEYWORD2
standby KEYWORD2
transmitDirect KEYWORD2
receiveDirect KEYWORD2
packetMode KEYWORD2
setDio0Action KEYWORD2
setDio1Action KEYWORD2
clearDio0Action KEYWORD2
clearDio1Action KEYWORD2
startTransmit KEYWORD2
startReceive KEYWORD2
readData KEYWORD2
startChannelScan KEYWORD2
getChannelScanResult KEYWORD2
setBandwidth KEYWORD2
setSpreadingFactor KEYWORD2
setCodingRate KEYWORD2
setFrequency KEYWORD2
setSyncWord KEYWORD2
setOutputPower KEYWORD2
setCurrentLimit KEYWORD2
setPreambleLength KEYWORD2
setGain KEYWORD2
getFrequencyError KEYWORD2
getRSSI KEYWORD2
getAFCError KEYWORD2
getSNR KEYWORD2
getDataRate KEYWORD2
setBitRate KEYWORD2
setRxBandwidth KEYWORD2
setAFCBandwidth KEYWORD2
setAFC KEYWORD2
setAFCAGCTrigger KEYWORD2
setFrequencyDeviation KEYWORD2
setNodeAddress KEYWORD2
setBroadcastAddress KEYWORD2
disableAddressFiltering KEYWORD2
setDataShaping KEYWORD2
setOOK KEYWORD2
setDataShapingOOK KEYWORD2
setCRC KEYWORD2
variablePacketLengthMode KEYWORD2
fixedPacketLengthMode KEYWORD2
setCrcFiltering KEYWORD2
enableSyncWordFiltering KEYWORD2
disableSyncWordFiltering KEYWORD2
setPromiscuous KEYWORD2
setRSSIConfig KEYWORD2
setEncoding KEYWORD2
getIRQFlags KEYWORD2
getModemStatus KEYWORD2
getTempRaw KEYWORD2
setRfSwitchPins KEYWORD2
forceLDRO KEYWORD2
autoLDRO KEYWORD2
getChipVersion KEYWORD2
invertIQ KEYWORD2
setOokThresholdType KEYWORD2
setOokPeakThresholdDecrement KEYWORD2
setOokFixedOrFloorThreshold KEYWORD2
setDirectSyncWord KEYWORD2
setDirectAction KEYWORD2
readBit KEYWORD2
enableBitSync KEYWORD2
disableBitSync KEYWORD2
# RF69-specific
setAESKey KEYWORD2
enableAES KEYWORD2
disableAES KEYWORD2
getTemperature KEYWORD2
setAmbientTemperature KEYWORD2
setLnaTestBoost KEYWORD2
setOokFixedThreshold KEYWORD2
enableContinuousModeBitSync KEYWORD2
disableContinuousModeBitSync KEYWORD2
# CC1101-specific
getLQI KEYWORD2
setGdo0Action KEYWORD2
setGdo2Action KEYWORD2
clearGdo0Action KEYWORD2
clearGdo2Action KEYWORD2
setCrcFiltering KEYWORD2
# SX126x-specific
setTCXO KEYWORD2
setDio2AsRfSwitch KEYWORD2
getTimeOnAir KEYWORD2
implicitHeader KEYWORD2
explicitHeader KEYWORD2
setSyncBits KEYWORD2
setWhitening KEYWORD2
startReceiveDutyCycle KEYWORD2
startReceiveDutyCycleAuto KEYWORD2
setRegulatorLDO KEYWORD2
setRegulatorDCDC KEYWORD2
getCurrentLimit KEYWORD2
# nRF24
setIrqAction KEYWORD2
setAddressWidth KEYWORD2
setTransmitPipe KEYWORD2
setReceivePipe KEYWORD2
disablePipe KEYWORD2
getStatus KEYWORD2
setAutoAck KEYWORD2
# RTTY
idle KEYWORD2
byteArr KEYWORD2
# Morse
startSignal KEYWORD2
# AX.25
setRepeaters KEYWORD2
setRecvSequence KEYWORD2
setSendSequence KEYWORD2
sendFrame KEYWORD2
setCorrection KEYWORD2
# SSTV
sendHeader KEYWORD2
sendLine KEYWORD2
getPictureHeight KEYWORD2
# SX128x
beginGFSK KEYWORD2
beginFLRC KEYWORD2
beginBLE KEYWORD2
setAccessAddress KEYWORD2
range KEYWORD2
startRanging KEYWORD2
getRangingResult KEYWORD2
# Hellschreiber
printGlyph KEYWORD2
# AFSK
tone KEYWORD2
noTone KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################
RADIOLIB_NC LITERAL1
RADIOLIB_VERSION LITERAL1
RADIOLIB_SHAPING_NONE LITERAL1
RADIOLIB_SHAPING_0_3 LITERAL1
RADIOLIB_SHAPING_0_5 LITERAL1
RADIOLIB_SHAPING_0_7 LITERAL1
RADIOLIB_SHAPING_1_0 LITERAL1
RADIOLIB_ENCODING_NRZ LITERAL1
RADIOLIB_ENCODING_MANCHESTER LITERAL1
RADIOLIB_ENCODING_WHITENING LITERAL1
RADIOLIB_ERR_NONE LITERAL1
RADIOLIB_ERR_UNKNOWN LITERAL1
RADIOLIB_ERR_CHIP_NOT_FOUND LITERAL1
RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED LITERAL1
RADIOLIB_ERR_PACKET_TOO_LONG LITERAL1
RADIOLIB_ERR_TX_TIMEOUT LITERAL1
RADIOLIB_ERR_RX_TIMEOUT LITERAL1
RADIOLIB_ERR_CRC_MISMATCH LITERAL1
RADIOLIB_ERR_INVALID_BANDWIDTH LITERAL1
RADIOLIB_ERR_INVALID_SPREADING_FACTOR LITERAL1
RADIOLIB_ERR_INVALID_CODING_RATE LITERAL1
RADIOLIB_ERR_INVALID_BIT_RANGE LITERAL1
RADIOLIB_ERR_INVALID_FREQUENCY LITERAL1
RADIOLIB_ERR_INVALID_OUTPUT_POWER LITERAL1
RADIOLIB_PREAMBLE_DETECTED LITERAL1
RADIOLIB_CHANNEL_FREE LITERAL1
RADIOLIB_ERR_SPI_WRITE_FAILED LITERAL1
RADIOLIB_ERR_INVALID_CURRENT_LIMIT LITERAL1
RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH LITERAL1
RADIOLIB_ERR_INVALID_GAIN LITERAL1
RADIOLIB_ERR_WRONG_MODEM LITERAL1
RADIOLIB_ERR_INVALID_NUM_SAMPLES LITERAL1
RADIOLIB_ERR_INVALID_RSSI_OFFSET LITERAL1
RADIOLIB_ERR_INVALID_ENCODING LITERAL1
RADIOLIB_ERR_INVALID_BIT_RATE LITERAL1
RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION LITERAL1
RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO LITERAL1
RADIOLIB_ERR_INVALID_RX_BANDWIDTH LITERAL1
RADIOLIB_ERR_INVALID_SYNC_WORD LITERAL1
RADIOLIB_ERR_INVALID_DATA_SHAPING LITERAL1
RADIOLIB_ERR_INVALID_MODULATION LITERAL1
RADIOLIB_ASCII LITERAL1
RADIOLIB_ASCII_EXTENDED LITERAL1
RADIOLIB_ITA2 LITERAL1
RADIOLIB_ERR_INVALID_RTTY_SHIFT LITERAL1
RADIOLIB_ERR_UNSUPPORTED_ENCODING LITERAL1
RADIOLIB_ERR_INVALID_DATA_RATE LITERAL1
RADIOLIB_ERR_INVALID_ADDRESS_WIDTH LITERAL1
RADIOLIB_ERR_INVALID_PIPE_NUMBER LITERAL1
RADIOLIB_ERR_ACK_NOT_RECEIVED LITERAL1
RADIOLIB_ERR_INVALID_NUM_BROAD_ADDRS LITERAL1
RADIOLIB_ERR_INVALID_CRC_CONFIGURATION LITERAL1
RADIOLIB_LORA_DETECTED LITERAL1
RADIOLIB_ERR_INVALID_TCXO_VOLTAGE LITERAL1
RADIOLIB_ERR_INVALID_MODULATION_PARAMETERS LITERAL1
RADIOLIB_ERR_SPI_CMD_TIMEOUT LITERAL1
RADIOLIB_ERR_SPI_CMD_INVALID LITERAL1
RADIOLIB_ERR_SPI_CMD_FAILED LITERAL1
RADIOLIB_ERR_INVALID_SLEEP_PERIOD LITERAL1
RADIOLIB_ERR_INVALID_RX_PERIOD LITERAL1
RADIOLIB_ERR_INVALID_CALLSIGN LITERAL1
RADIOLIB_ERR_INVALID_NUM_REPEATERS LITERAL1
RADIOLIB_ERR_INVALID_REPEATER_CALLSIGN LITERAL1
RADIOLIB_ERR_RANGING_TIMEOUT LITERAL1

View File

@ -0,0 +1,10 @@
name=RadioLib
version=4.6.0
author=Jan Gromes <gromes.jan@gmail.com>
maintainer=Jan Gromes <gromes.jan@gmail.com>
sentence=Universal wireless communication library for Arduino
paragraph=Enables user-friendly control of the RadioShield and various wireless modules.
category=Communication
url=https://github.com/jgromes/RadioLib
architectures=*
includes=RadioLib.h

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2018 Jan Gromeš
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,927 @@
#if !defined(_RADIOLIB_BUILD_OPTIONS_H)
#define _RADIOLIB_BUILD_OPTIONS_H
#if ARDUINO >= 100
// Arduino build
#include "Arduino.h"
#define RADIOLIB_BUILD_ARDUINO
#else
// generic build
#define RADIOLIB_BUILD_GENERIC
#endif
#if defined(RADIOLIB_BUILD_ARDUINO)
/*
* Platform-specific configuration.
*
* RADIOLIB_PLATFORM - platform name, used in debugging to quickly check the correct platform is detected.
* RADIOLIB_PIN_TYPE - which type should be used for pin numbers in functions like digitalRead().
* RADIOLIB_PIN_MODE - which type should be used for pin modes in functions like pinMode().
* RADIOLIB_PIN_STATUS - which type should be used for pin values in functions like digitalWrite().
* RADIOLIB_INTERRUPT_STATUS - which type should be used for pin changes in functions like attachInterrupt().
* RADIOLIB_DIGITAL_PIN_TO_INTERRUPT - function/macro to be used to convert digital pin number to interrupt pin number.
* RADIOLIB_NC - alias for unused pin, usually the largest possible value of RADIOLIB_PIN_TYPE.
* RADIOLIB_DEFAULT_SPI - default SPIClass instance to use.
* RADIOLIB_NONVOLATILE - macro to place variable into program storage (usually Flash).
* RADIOLIB_NONVOLATILE_READ_BYTE - function/macro to read variables saved in program storage (usually Flash).
* RADIOLIB_TYPE_ALIAS - construct to create an alias for a type, usually vai the `using` keyword.
* RADIOLIB_TONE_UNSUPPORTED - some platforms do not have tone()/noTone(), which is required for AFSK.
*
* In addition, some platforms may require RadioLib to disable specific drivers (such as ESP8266).
*
* Users may also specify their own configuration by uncommenting the RADIOLIB_CUSTOM_ARDUINO,
* and then specifying all platform parameters in the section below. This will override automatic
* platform detection.
*/
// uncomment to enable custom platform definition
//#define RADIOLIB_CUSTOM_ARDUINO
#if defined(RADIOLIB_CUSTOM_ARDUINO)
// name for your platform
#define RADIOLIB_PLATFORM "Custom"
// the following parameters must always be defined
#define RADIOLIB_PIN_TYPE uint8_t
#define RADIOLIB_PIN_MODE uint8_t
#define RADIOLIB_PIN_STATUS uint8_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
// the following are signatures of Arduino API functions of the custom platform
// for example, pinMode on Arduino Uno is defined as void pinMode(uint8_t pin, uint8_t mode)
// all fo the callbacks below are taken from Arduino Uno
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint8_t pin, uint8_t mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint8_t pin, uint8_t value)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (int, digitalRead, uint8_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t _pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t _pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint8_t interruptNum, void (*userFunc)(void), int mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint8_t interruptNum)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
// the following must be defined if the Arduino core does not support tone function
//#define RADIOLIB_TONE_UNSUPPORTED
// some platforms seem to have issues with SPI modules that use a command interface
// this can be mitigated by adding delays into SPI communication
// (see https://github.com/jgromes/RadioLib/issues/158 for details)
//#define RADIOLIB_SPI_SLOWDOWN
// some of RadioLib drivers may be excluded, to prevent collisions with platforms (or to speed up build process)
// the following is a complete list of all possible exclusion macros, uncomment any of them to disable that driver
// NOTE: Some of the exclusion macros are dependent on each other. For example, it is not possible to exclude RF69
// while keeping SX1231 (because RF69 is the base class for SX1231). The dependency is always uni-directional,
// so excluding SX1231 and keeping RF69 is valid.
//#define RADIOLIB_EXCLUDE_CC1101
//#define RADIOLIB_EXCLUDE_NRF24
//#define RADIOLIB_EXCLUDE_RF69
//#define RADIOLIB_EXCLUDE_SX1231 // dependent on RADIOLIB_EXCLUDE_RF69
//#define RADIOLIB_EXCLUDE_SI443X
//#define RADIOLIB_EXCLUDE_RFM2X // dependent on RADIOLIB_EXCLUDE_SI443X
//#define RADIOLIB_EXCLUDE_SX127X
//#define RADIOLIB_EXCLUDE_RFM9X // dependent on RADIOLIB_EXCLUDE_SX127X
//#define RADIOLIB_EXCLUDE_SX126X
//#define RADIOLIB_EXCLUDE_SX128X
//#define RADIOLIB_EXCLUDE_AFSK
//#define RADIOLIB_EXCLUDE_AX25
//#define RADIOLIB_EXCLUDE_HELLSCHREIBER
//#define RADIOLIB_EXCLUDE_MORSE
//#define RADIOLIB_EXCLUDE_RTTY
//#define RADIOLIB_EXCLUDE_SSTV
#else
#if defined(__AVR__) && !(defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY) || defined(ARDUINO_ARCH_MEGAAVR))
// Arduino AVR boards (except for megaAVR) - Uno, Mega etc.
#define RADIOLIB_PLATFORM "Arduino AVR"
#define RADIOLIB_PIN_TYPE uint8_t
#define RADIOLIB_PIN_MODE uint8_t
#define RADIOLIB_PIN_STATUS uint8_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint8_t pin, uint8_t mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint8_t pin, uint8_t value)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (int, digitalRead, uint8_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t _pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t _pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint8_t interruptNum, void (*userFunc)(void), int mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint8_t interruptNum)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ESP8266)
// ESP8266 boards
#define RADIOLIB_PLATFORM "ESP8266"
#define RADIOLIB_PIN_TYPE uint8_t
#define RADIOLIB_PIN_MODE uint8_t
#define RADIOLIB_PIN_STATUS uint8_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint8_t pin, uint8_t mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint8_t pin, uint8_t value)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (int, digitalRead, uint8_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t _pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t _pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint8_t pin, void (*)(void), int mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint8_t interruptNum)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ESP32)
// ESP32 boards
#define RADIOLIB_PLATFORM "ESP32"
#define RADIOLIB_PIN_TYPE uint8_t
#define RADIOLIB_PIN_MODE uint8_t
#define RADIOLIB_PIN_STATUS uint8_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// ESP32 doesn't support tone(), but it can be emulated via LED control peripheral
#define RADIOLIB_TONE_UNSUPPORTED
#define RADIOLIB_TONE_ESP32_CHANNEL (1)
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint8_t pin, uint8_t mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint8_t pin, uint8_t value)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (int, digitalRead, uint8_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, void)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, void)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint8_t pin, void (*)(void), int mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint8_t pin)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, uint32_t)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, uint32_t us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ARDUINO_ARCH_STM32)
// official STM32 Arduino core (https://github.com/stm32duino/Arduino_Core_STM32)
#define RADIOLIB_PLATFORM "Arduino STM32 (official)"
#define RADIOLIB_PIN_TYPE uint32_t
#define RADIOLIB_PIN_MODE uint32_t
#define RADIOLIB_PIN_STATUS uint32_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt((PinName)p)
#define RADIOLIB_NC (0xFFFFFFFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// slow down SX126x/8x SPI on this platform
#define RADIOLIB_SPI_SLOWDOWN
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint32_t dwPin, uint32_t dwMode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint32_t dwPin, uint32_t dwVal)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (int, digitalRead, uint32_t ulPin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t _pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t _pin, bool destruct)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint32_t pin, void (*callback)(void), uint32_t mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint32_t pin)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, uint32_t ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, uint32_t us)
#define RADIOLIB_CB_ARGS_MILLIS (uint32_t, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (uint32_t, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(SAMD_SERIES)
// Adafruit SAMD boards (M0 and M4)
#define RADIOLIB_PLATFORM "Adafruit SAMD"
#define RADIOLIB_PIN_TYPE uint32_t
#define RADIOLIB_PIN_MODE uint32_t
#define RADIOLIB_PIN_STATUS uint32_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFFFFFFFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// slow down SX126x/8x SPI on this platform
#define RADIOLIB_SPI_SLOWDOWN
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint32_t dwPin, uint32_t dwMode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint32_t dwPin, uint32_t dwVal)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (int, digitalRead, uint32_t ulPin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint32_t _pin, uint32_t frequency, uint32_t duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint32_t _pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint32_t pin, voidFuncPtr callback, uint32_t mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint32_t pin)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long dwMs)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ARDUINO_ARCH_SAMD)
// Arduino SAMD (Zero, MKR, etc.)
#define RADIOLIB_PLATFORM "Arduino SAMD"
#define RADIOLIB_PIN_TYPE pin_size_t
#define RADIOLIB_PIN_MODE PinMode
#define RADIOLIB_PIN_STATUS PinStatus
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, pin_size_t pinNumber, PinMode pinMode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, pin_size_t pinNumber, PinStatus status)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (PinStatus, digitalRead, pin_size_t pinNumber)
#define RADIOLIB_CB_ARGS_TONE (void, tone, unsigned char outputPin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t outputPin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, pin_size_t pin, voidFuncPtr callback, PinStatus mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, pin_size_t pin)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(__SAM3X8E__)
// Arduino Due
#define RADIOLIB_PLATFORM "Arduino Due"
#define RADIOLIB_PIN_TYPE uint32_t
#define RADIOLIB_PIN_MODE uint32_t
#define RADIOLIB_PIN_STATUS uint32_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFFFFFFFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
#define RADIOLIB_TONE_UNSUPPORTED
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint32_t dwPin, uint32_t dwMode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint32_t dwPin, uint32_t dwVal)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (int, digitalRead, uint32_t ulPin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, void)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, void)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint32_t pin, void (*callback)(void), uint32_t mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint32_t pin)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, uint32_t dwMs)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, uint32_t usec)
#define RADIOLIB_CB_ARGS_MILLIS (uint32_t, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (uint32_t, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif (defined(NRF52832_XXAA) || defined(NRF52840_XXAA)) && !defined(ARDUINO_ARDUINO_NANO33BLE)
// Adafruit nRF52 boards
#define RADIOLIB_PLATFORM "Adafruit nRF52"
#define RADIOLIB_PIN_TYPE uint32_t
#define RADIOLIB_PIN_MODE uint32_t
#define RADIOLIB_PIN_STATUS uint32_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFFFFFFFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint32_t dwPin, uint32_t dwMode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint32_t dwPin, uint32_t dwVal)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (int, digitalRead, uint32_t ulPin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (int, attachInterrupt, uint32_t pin, voidFuncPtr callback, uint32_t mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint32_t pin)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, uint32_t dwMs)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, uint32_t usec)
#define RADIOLIB_CB_ARGS_MILLIS (uint32_t, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (uint32_t, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ARDUINO_ARC32_TOOLS)
// Intel Curie
#define RADIOLIB_PLATFORM "Intel Curie"
#define RADIOLIB_PIN_TYPE uint8_t
#define RADIOLIB_PIN_MODE uint8_t
#define RADIOLIB_PIN_STATUS uint8_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint8_t pin, uint8_t mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint8_t pin, uint8_t val)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (int, digitalRead, uint8_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint32_t _pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint32_t _pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint32_t pin, void (*callback)(void), uint32_t mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint32_t pin)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, uint32_t dwMs)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, uint32_t dwUs)
#define RADIOLIB_CB_ARGS_MILLIS (uint64_t, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (uint64_t, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_AVR_NANO_EVERY)
// Arduino megaAVR boards - Uno Wifi Rev.2, Nano Every
#define RADIOLIB_PLATFORM "Arduino megaAVR"
#define RADIOLIB_PIN_TYPE uint8_t
#define RADIOLIB_PIN_MODE PinMode
#define RADIOLIB_PIN_STATUS PinStatus
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint8_t pin, PinMode mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint8_t pin, PinStatus val)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (PinStatus, digitalRead, uint8_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint8_t pin, void (*userFunc)(void), PinStatus mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint8_t pin)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ARDUINO_ARCH_APOLLO3)
// Sparkfun Apollo3 boards
#define RADIOLIB_PLATFORM "Sparkfun Apollo3"
#define RADIOLIB_PIN_TYPE pin_size_t
#define RADIOLIB_PIN_MODE Arduino_PinMode
#define RADIOLIB_PIN_STATUS PinStatus
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// slow down SX126x/8x SPI on this platform
#define RADIOLIB_SPI_SLOWDOWN
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, pin_size_t pinName, Arduino_PinMode pinMode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, pin_size_t pinName, PinStatus val)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (PinStatus, digitalRead, pin_size_t pinName)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t _pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t _pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, pin_size_t interruptNumber)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ARDUINO_ARDUINO_NANO33BLE)
// Arduino Nano 33 BLE
#define RADIOLIB_PLATFORM "Arduino Nano 33 BLE"
#define RADIOLIB_PIN_TYPE pin_size_t
#define RADIOLIB_PIN_MODE PinMode
#define RADIOLIB_PIN_STATUS PinStatus
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, pin_size_t pin, PinMode mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, pin_size_t pin, PinStatus val)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (PinStatus, digitalRead, pin_size_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, pin_size_t interruptNum, voidFuncPtr func, PinStatus mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, pin_size_t interruptNum)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
// Arduino Portenta H7
#define RADIOLIB_PLATFORM "Portenta H7"
#define RADIOLIB_PIN_TYPE pin_size_t
#define RADIOLIB_PIN_MODE PinMode
#define RADIOLIB_PIN_STATUS PinStatus
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, pin_size_t pin, PinMode mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, pin_size_t pin, PinStatus val)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (PinStatus, digitalRead, pin_size_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, pin_size_t interruptNum, voidFuncPtr func, PinStatus mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, pin_size_t interruptNum)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(__STM32F4__) || defined(__STM32F1__)
// Arduino STM32 core by Roger Clark (https://github.com/rogerclarkmelbourne/Arduino_STM32)
#define RADIOLIB_PLATFORM "STM32duino (unofficial)"
#define RADIOLIB_PIN_TYPE uint8_t
#define RADIOLIB_PIN_MODE WiringPinMode
#define RADIOLIB_PIN_STATUS uint8_t
#define RADIOLIB_INTERRUPT_STATUS ExtIntTriggerMode
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint8 pin, WiringPinMode mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint8 pin, uint8 val)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (uint32_t, digitalRead, uint8 pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint32_t _pin, uint32_t frequency, uint32_t duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint32_t _pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint8 pin, voidFuncPtr handler, ExtIntTriggerMode mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint8 pin)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, uint32 us)
#define RADIOLIB_CB_ARGS_MILLIS (uint32_t, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (uint32_t, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ARDUINO_ARCH_MEGAAVR)
// MegaCoreX by MCUdude (https://github.com/MCUdude/MegaCoreX)
#define RADIOLIB_PLATFORM "MegaCoreX"
#define RADIOLIB_PIN_TYPE uint8_t
#define RADIOLIB_PIN_MODE uint8_t
#define RADIOLIB_PIN_STATUS uint8_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint8_t pin, uint8_t mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint8_t pin, uint8_t value)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (uint8_t, digitalRead, uint8_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t _pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t _pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint8_t pin, void (*userFunc)(void), uint8_t mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint8_t interruptNum)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(ARDUINO_ARCH_RP2040)
// Raspberry Pi Pico
#define RADIOLIB_PLATFORM "Raspberry Pi Pico"
#define RADIOLIB_PIN_TYPE pin_size_t
#define RADIOLIB_PIN_MODE PinMode
#define RADIOLIB_PIN_STATUS PinStatus
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, pin_size_t pin, PinMode mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, pin_size_t pin, PinStatus val)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (PinStatus, digitalRead, pin_size_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, pin_size_t interruptNum, voidFuncPtr func, PinStatus mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, pin_size_t interruptNum)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#elif defined(__ASR6501__) || defined(ARDUINO_ARCH_ASR650X) || defined(DARDUINO_ARCH_ASR6601)
// CubeCell
#define RADIOLIB_PLATFORM "CubeCell"
#define RADIOLIB_PIN_TYPE uint8_t
#define RADIOLIB_PIN_MODE PINMODE
#define RADIOLIB_PIN_STATUS uint8_t
#define RADIOLIB_INTERRUPT_STATUS IrqModes
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint8_t pin, PINMODE mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint8_t pin_name, uint8_t level)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (uint8_t, digitalRead, uint8_t pin_name)
#define RADIOLIB_CB_ARGS_TONE (void, tone, void)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, void)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint8_t pin_name, GpioIrqHandler GpioIrqHandlerCallback, IrqModes interrupt_mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint8_t pin_name)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, uint32_t milliseconds)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, uint16 microseconds)
#define RADIOLIB_CB_ARGS_MILLIS (uint32_t, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (uint32_t, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
// CubeCell doesn't seem to define nullptr, let's do something like that now
#define nullptr NULL
// ... and also defines pinMode() as a macro, which is by far the stupidest thing I have seen on Arduino
#undef pinMode
// ... and uses an outdated GCC which does not support type aliases
#define RADIOLIB_TYPE_ALIAS(type, alias) typedef class type alias;
// ... and it also has no tone(). This platform was designed by an idiot.
#define RADIOLIB_TONE_UNSUPPORTED
// ... AND as the (hopefully) final nail in the coffin, IT F*CKING DEFINES YIELD() AS A MACRO THAT DOES NOTHING!!!
#define RADIOLIB_YIELD_UNSUPPORTED
#if defined(yield)
#undef yield
#endif
#else
// other Arduino platforms not covered by the above list - this may or may not work
#define RADIOLIB_PLATFORM "Unknown Arduino"
#define RADIOLIB_UNKNOWN_PLATFORM
#define RADIOLIB_PIN_TYPE uint8_t
#define RADIOLIB_PIN_MODE uint8_t
#define RADIOLIB_PIN_STATUS uint8_t
#define RADIOLIB_INTERRUPT_STATUS RADIOLIB_PIN_STATUS
#define RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(p) digitalPinToInterrupt(p)
#define RADIOLIB_NC (0xFF)
#define RADIOLIB_DEFAULT_SPI SPI
#define RADIOLIB_DEFAULT_SPI_SETTINGS SPISettings(2000000, MSBFIRST, SPI_MODE0)
#define RADIOLIB_NONVOLATILE PROGMEM
#define RADIOLIB_NONVOLATILE_READ_BYTE(addr) pgm_read_byte(addr)
#define RADIOLIB_TYPE_ALIAS(type, alias) using alias = type;
// Arduino API callbacks
#define RADIOLIB_CB_ARGS_PIN_MODE (void, pinMode, uint8_t pin, uint8_t mode)
#define RADIOLIB_CB_ARGS_DIGITAL_WRITE (void, digitalWrite, uint8_t pin, uint8_t value)
#define RADIOLIB_CB_ARGS_DIGITAL_READ (int, digitalRead, uint8_t pin)
#define RADIOLIB_CB_ARGS_TONE (void, tone, uint8_t _pin, unsigned int frequency, unsigned long duration)
#define RADIOLIB_CB_ARGS_NO_TONE (void, noTone, uint8_t _pin)
#define RADIOLIB_CB_ARGS_ATTACH_INTERRUPT (void, attachInterrupt, uint8_t interruptNum, void (*userFunc)(void), int mode)
#define RADIOLIB_CB_ARGS_DETACH_INTERRUPT (void, detachInterrupt, uint8_t interruptNum)
#define RADIOLIB_CB_ARGS_YIELD (void, yield, void)
#define RADIOLIB_CB_ARGS_DELAY (void, delay, unsigned long ms)
#define RADIOLIB_CB_ARGS_DELAY_MICROSECONDS (void, delayMicroseconds, unsigned int us)
#define RADIOLIB_CB_ARGS_MILLIS (unsigned long, millis, void)
#define RADIOLIB_CB_ARGS_MICROS (unsigned long, micros, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN (void, SPIbegin, void)
#define RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION (void, SPIbeginTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_TRANSFER (uint8_t, SPItransfer, uint8_t b)
#define RADIOLIB_CB_ARGS_SPI_END_TRANSACTION (void, SPIendTransaction, void)
#define RADIOLIB_CB_ARGS_SPI_END (void, SPIend, void)
#endif
#endif
#else
// generic non-Arduino platform
#define RADIOLIB_PLATFORM "Generic"
// platform properties may be defined here, or somewhere else in the build system
#endif
/*
* Uncomment to enable debug output.
* Warning: Debug output will slow down the whole system significantly.
* Also, it will result in larger compiled binary.
* Levels: debug - only main info
* verbose - full transcript of all SPI communication
*/
#if !defined(RADIOLIB_DEBUG)
//#define RADIOLIB_DEBUG
#endif
#if !defined(RADIOLIB_VERBOSE)
//#define RADIOLIB_VERBOSE
#endif
// set which output port should be used for debug output
// may be Serial port (on Arduino) or file like stdout or stderr (on generic platforms)
#if !defined(RADIOLIB_DEBUG_PORT)
#define RADIOLIB_DEBUG_PORT Serial
#endif
/*
* Uncomment to enable "paranoid" SPI mode
* Every write to an SPI register using SPI set function will be verified by a subsequent read operation.
* This improves reliablility, but slightly slows down communication.
* Note: Enabled by default.
*/
#if !defined(RADIOLIB_SPI_PARANOID)
#define RADIOLIB_SPI_PARANOID
#endif
/*
* Uncomment to enable parameter range checking
* RadioLib will check provided parameters (such as frequency) against limits determined by the device manufacturer.
* It is highly advised to keep this macro defined, removing it will allow invalid values to be set,
* possibly leading to bricked module and/or program crashing.
* Note: Enabled by default.
*/
#if !defined(RADIOLIB_CHECK_PARAMS)
#define RADIOLIB_CHECK_PARAMS
#endif
/*
* Uncomment to enable SX127x errata fix
* Warning: SX127x errata fix has been reported to cause issues with LoRa bandwidths lower than 62.5 kHz.
* It should only be enabled if you really are observing some errata-related issue.
* Note: Disabled by default.
*/
#if !defined(RADIOLIB_FIX_ERRATA_SX127X)
//#define RADIOLIB_FIX_ERRATA_SX127X
#endif
/*
* Uncomment to enable god mode - all methods and member variables in all classes will be made public, thus making them accessible from Arduino code.
* Warning: Come on, it's called GOD mode - obviously only use this if you know what you're doing.
* Failure to heed the above warning may result in bricked module.
*/
#if !defined(RADIOLIB_GODMODE)
//#define RADIOLIB_GODMODE
#endif
/*
* Uncomment to enable low-level hardware access
* This will make some hardware methods like SPI get/set accessible from the user sketch - think of it as "god mode lite"
* Warning: RadioLib won't stop you from writing invalid stuff into your device, so it's quite easy to brick your module with this.
*/
#if !defined(RADIOLIB_LOW_LEVEL)
//#define RADIOLIB_LOW_LEVEL
#endif
/*
* Uncomment to enable pre-defined modules when using RadioShield.
*/
#if !defined(RADIOLIB_RADIOSHIELD)
//#define RADIOLIB_RADIOSHIELD
#endif
/*
* Uncomment to enable static-only memory management: no dynamic allocation will be performed.
* Warning: Large static arrays will be created in some methods. It is not advised to send large packets in this mode.
*/
#if !defined(RADIOLIB_STATIC_ONLY)
//#define RADIOLIB_STATIC_ONLY
#endif
// set the size of static arrays to use
#if !defined(RADIOLIB_STATIC_ARRAY_SIZE)
#define RADIOLIB_STATIC_ARRAY_SIZE (256)
#endif
#if defined(RADIOLIB_DEBUG)
#if defined(RADIOLIB_BUILD_ARDUINO)
#define RADIOLIB_DEBUG_PRINT(...) { RADIOLIB_DEBUG_PORT.print(__VA_ARGS__); }
#define RADIOLIB_DEBUG_PRINTLN(...) { RADIOLIB_DEBUG_PORT.println(__VA_ARGS__); }
#else
#if !defined(RADIOLIB_DEBUG_PRINT)
#define RADIOLIB_DEBUG_PRINT(...) { frintf(RADIOLIB_DEBUG_PORT, __VA_ARGS__); }
#endif
#if !defined(RADIOLIB_DEBUG_PRINTLN)
#define RADIOLIB_DEBUG_PRINTLN(...) { printf(RADIOLIB_DEBUG_PORT, __VA_ARGS__ "\n"); }
#endif
#endif
#else
#define RADIOLIB_DEBUG_PRINT(...) {}
#define RADIOLIB_DEBUG_PRINTLN(...) {}
#endif
#if defined(RADIOLIB_VERBOSE)
#define RADIOLIB_VERBOSE_PRINT(...) RADIOLIB_DEBUG_PRINT(__VA_ARGS__)
#define RADIOLIB_VERBOSE_PRINTLN(...) RADIOLIB_DEBUG_PRINT(__VA_ARGS__)
#else
#define RADIOLIB_VERBOSE_PRINT(...) {}
#define RADIOLIB_VERBOSE_PRINTLN(...) {}
#endif
/*!
\brief A simple assert macro, will return on error.
*/
#define RADIOLIB_ASSERT(STATEVAR) { if((STATEVAR) != RADIOLIB_ERR_NONE) { return(STATEVAR); } }
/*
* Macros that create callback for the hardware abstraction layer.
*
* This is the most evil thing I have ever created. I am deeply sorry to anyone currently reading this text.
* Come one, come all and witness the horror:
* Variadics, forced expansions, inlined function, string concatenation, and it even messes up access specifiers.
*/
#define RADIOLIB_FIRST(arg, ...) arg
#define RADIOLIB_REST(arg, ...) __VA_ARGS__
#define RADIOLIB_EXP(...) __VA_ARGS__
#define RADIOLIB_GENERATE_CALLBACK_RET_FUNC(RET, FUNC, ...) public: typedef RET (*FUNC##_cb_t)(__VA_ARGS__); void setCb_##FUNC(FUNC##_cb_t cb) { cb_##FUNC = cb; }; private: FUNC##_cb_t cb_##FUNC;
#define RADIOLIB_GENERATE_CALLBACK_RET(RET, ...) RADIOLIB_GENERATE_CALLBACK_RET_FUNC(RET, __VA_ARGS__)
#define RADIOLIB_GENERATE_CALLBACK(CB) RADIOLIB_GENERATE_CALLBACK_RET(RADIOLIB_EXP(RADIOLIB_FIRST CB), RADIOLIB_EXP(RADIOLIB_REST CB))
#define RADIOLIB_GENERATE_CALLBACK_SPI_RET_FUNC(RET, FUNC, ...) public: typedef RET (Module::*FUNC##_cb_t)(__VA_ARGS__); void setCb_##FUNC(FUNC##_cb_t cb) { cb_##FUNC = cb; }; private: FUNC##_cb_t cb_##FUNC;
#define RADIOLIB_GENERATE_CALLBACK_SPI_RET(RET, ...) RADIOLIB_GENERATE_CALLBACK_SPI_RET_FUNC(RET, __VA_ARGS__)
#define RADIOLIB_GENERATE_CALLBACK_SPI(CB) RADIOLIB_GENERATE_CALLBACK_SPI_RET(RADIOLIB_EXP(RADIOLIB_FIRST CB), RADIOLIB_EXP(RADIOLIB_REST CB))
/*!
\brief Macro to check variable is within constraints - this is commonly used to check parameter ranges. Requires RADIOLIB_CHECK_RANGE to be enabled
*/
#if defined(RADIOLIB_CHECK_PARAMS)
#define RADIOLIB_CHECK_RANGE(VAR, MIN, MAX, ERR) { if(!(((VAR) >= (MIN)) && ((VAR) <= (MAX)))) { return(ERR); } }
#else
#define RADIOLIB_CHECK_RANGE(VAR, MIN, MAX, ERR) {}
#endif
#if defined(RADIOLIB_FIX_ERRATA_SX127X)
#define RADIOLIB_ERRATA_SX127X(...) { errataFix(__VA_ARGS__); }
#else
#define RADIOLIB_ERRATA_SX127X(...) {}
#endif
// version definitions
#define RADIOLIB_VERSION_MAJOR (0x04)
#define RADIOLIB_VERSION_MINOR (0x06)
#define RADIOLIB_VERSION_PATCH (0x00)
#define RADIOLIB_VERSION_EXTRA (0x00)
#define RADIOLIB_VERSION ((RADIOLIB_VERSION_MAJOR << 24) | (RADIOLIB_VERSION_MINOR << 16) | (RADIOLIB_VERSION_PATCH << 8) | (RADIOLIB_VERSION_EXTRA))
#endif

View File

@ -0,0 +1,445 @@
#include "Module.h"
#if defined(RADIOLIB_BUILD_ARDUINO)
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio):
_cs(cs),
_irq(irq),
_rst(rst),
_gpio(gpio)
{
_spi = &RADIOLIB_DEFAULT_SPI;
_initInterface = true;
// this is Arduino build, pre-set callbacks
setCb_pinMode(::pinMode);
setCb_digitalRead(::digitalRead);
setCb_digitalWrite(::digitalWrite);
#if !defined(RADIOLIB_TONE_UNSUPPORTED)
setCb_tone(::tone);
setCb_noTone(::noTone);
#endif
setCb_attachInterrupt(::attachInterrupt);
setCb_detachInterrupt(::detachInterrupt);
#if !defined(RADIOLIB_YIELD_UNSUPPORTED)
setCb_yield(::yield);
#endif
setCb_delay(::delay);
setCb_delayMicroseconds(::delayMicroseconds);
setCb_millis(::millis);
setCb_micros(::micros);
setCb_SPIbegin(&Module::SPIbegin);
setCb_SPIbeginTransaction(&Module::beginTransaction);
setCb_SPItransfer(&Module::transfer);
setCb_SPIendTransaction(&Module::endTransaction);
setCb_SPIend(&Module::end);
}
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings):
_cs(cs),
_irq(irq),
_rst(rst),
_gpio(gpio),
_spiSettings(spiSettings)
{
_spi = &spi;
_initInterface = false;
// this is Arduino build, pre-set callbacks
setCb_pinMode(::pinMode);
setCb_digitalRead(::digitalRead);
setCb_digitalWrite(::digitalWrite);
#if !defined(RADIOLIB_TONE_UNSUPPORTED)
setCb_tone(::tone);
setCb_noTone(::noTone);
#endif
setCb_attachInterrupt(::attachInterrupt);
setCb_detachInterrupt(::detachInterrupt);
#if !defined(RADIOLIB_YIELD_UNSUPPORTED)
setCb_yield(::yield);
#endif
setCb_delay(::delay);
setCb_delayMicroseconds(::delayMicroseconds);
setCb_millis(::millis);
setCb_micros(::micros);
setCb_SPIbegin(&Module::SPIbegin);
setCb_SPIbeginTransaction(&Module::beginTransaction);
setCb_SPItransfer(&Module::transfer);
setCb_SPIendTransaction(&Module::endTransaction);
setCb_SPIend(&Module::end);
}
#else
Module::Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio):
_cs(cs),
_irq(irq),
_rst(rst),
_gpio(gpio)
{
// not an Arduino build, it's up to the user to set all callbacks
}
#endif
Module::Module(const Module& mod) {
*this = mod;
}
Module& Module::operator=(const Module& mod) {
this->SPIreadCommand = mod.SPIreadCommand;
this->SPIwriteCommand = mod.SPIwriteCommand;
this->_cs = mod.getCs();
this->_irq = mod.getIrq();
this->_rst = mod.getRst();
this->_gpio = mod.getGpio();
return(*this);
}
void Module::init() {
this->pinMode(_cs, OUTPUT);
this->digitalWrite(_cs, HIGH);
if(_initInterface) {
(this->*cb_SPIbegin)();
}
}
void Module::term() {
// stop hardware interfaces (if they were initialized by the library)
if(!_initInterface) {
return;
}
if(_spi != nullptr) {
this->SPIend();
}
}
int16_t Module::SPIgetRegValue(uint8_t reg, uint8_t msb, uint8_t lsb) {
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
return(RADIOLIB_ERR_INVALID_BIT_RANGE);
}
uint8_t rawValue = SPIreadRegister(reg);
uint8_t maskedValue = rawValue & ((0b11111111 << lsb) & (0b11111111 >> (7 - msb)));
return(maskedValue);
}
int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t lsb, uint8_t checkInterval, uint8_t checkMask) {
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
return(RADIOLIB_ERR_INVALID_BIT_RANGE);
}
uint8_t currentValue = SPIreadRegister(reg);
uint8_t mask = ~((0b11111111 << (msb + 1)) | (0b11111111 >> (8 - lsb)));
uint8_t newValue = (currentValue & ~mask) | (value & mask);
SPIwriteRegister(reg, newValue);
#if defined(RADIOLIB_SPI_PARANOID)
// check register value each millisecond until check interval is reached
// some registers need a bit of time to process the change (e.g. SX127X_REG_OP_MODE)
uint32_t start = this->micros();
uint8_t readValue = 0x00;
while(this->micros() - start < (checkInterval * 1000)) {
readValue = SPIreadRegister(reg);
if((readValue & checkMask) == (newValue & checkMask)) {
// check passed, we can stop the loop
return(RADIOLIB_ERR_NONE);
}
}
// check failed, print debug info
RADIOLIB_DEBUG_PRINTLN();
RADIOLIB_DEBUG_PRINT(F("address:\t0x"));
RADIOLIB_DEBUG_PRINTLN(reg, HEX);
RADIOLIB_DEBUG_PRINT(F("bits:\t\t"));
RADIOLIB_DEBUG_PRINT(msb);
RADIOLIB_DEBUG_PRINT(' ');
RADIOLIB_DEBUG_PRINTLN(lsb);
RADIOLIB_DEBUG_PRINT(F("value:\t\t0b"));
RADIOLIB_DEBUG_PRINTLN(value, BIN);
RADIOLIB_DEBUG_PRINT(F("current:\t0b"));
RADIOLIB_DEBUG_PRINTLN(currentValue, BIN);
RADIOLIB_DEBUG_PRINT(F("mask:\t\t0b"));
RADIOLIB_DEBUG_PRINTLN(mask, BIN);
RADIOLIB_DEBUG_PRINT(F("new:\t\t0b"));
RADIOLIB_DEBUG_PRINTLN(newValue, BIN);
RADIOLIB_DEBUG_PRINT(F("read:\t\t0b"));
RADIOLIB_DEBUG_PRINTLN(readValue, BIN);
RADIOLIB_DEBUG_PRINTLN();
return(RADIOLIB_ERR_SPI_WRITE_FAILED);
#else
return(RADIOLIB_ERR_NONE);
#endif
}
void Module::SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes) {
SPItransfer(SPIreadCommand, reg, NULL, inBytes, numBytes);
}
uint8_t Module::SPIreadRegister(uint8_t reg) {
uint8_t resp = 0;
SPItransfer(SPIreadCommand, reg, NULL, &resp, 1);
return(resp);
}
void Module::SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, uint8_t numBytes) {
SPItransfer(SPIwriteCommand, reg, data, NULL, numBytes);
}
void Module::SPIwriteRegister(uint8_t reg, uint8_t data) {
SPItransfer(SPIwriteCommand, reg, &data, NULL, 1);
}
void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes) {
// start SPI transaction
this->SPIbeginTransaction();
// pull CS low
this->digitalWrite(_cs, LOW);
// send SPI register address with access command
this->SPItransfer(reg | cmd);
#if defined(RADIOLIB_VERBOSE)
if(cmd == SPIwriteCommand) {
RADIOLIB_VERBOSE_PRINT('W');
} else if(cmd == SPIreadCommand) {
RADIOLIB_VERBOSE_PRINT('R');
}
RADIOLIB_VERBOSE_PRINT('\t')
RADIOLIB_VERBOSE_PRINT(reg, HEX);
RADIOLIB_VERBOSE_PRINT('\t');
#endif
// send data or get response
if(cmd == SPIwriteCommand) {
if(dataOut != NULL) {
for(size_t n = 0; n < numBytes; n++) {
this->SPItransfer(dataOut[n]);
RADIOLIB_VERBOSE_PRINT(dataOut[n], HEX);
RADIOLIB_VERBOSE_PRINT('\t');
}
}
} else if (cmd == SPIreadCommand) {
if(dataIn != NULL) {
for(size_t n = 0; n < numBytes; n++) {
dataIn[n] = this->SPItransfer(0x00);
RADIOLIB_VERBOSE_PRINT(dataIn[n], HEX);
RADIOLIB_VERBOSE_PRINT('\t');
}
}
}
RADIOLIB_VERBOSE_PRINTLN();
// release CS
this->digitalWrite(_cs, HIGH);
// end SPI transaction
this->SPIendTransaction();
}
void Module::pinMode(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_MODE mode) {
if((pin == RADIOLIB_NC) || (cb_pinMode == nullptr)) {
return;
}
cb_pinMode(pin, mode);
}
void Module::digitalWrite(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_STATUS value) {
if((pin == RADIOLIB_NC) || (cb_digitalWrite == nullptr)) {
return;
}
cb_digitalWrite(pin, value);
}
RADIOLIB_PIN_STATUS Module::digitalRead(RADIOLIB_PIN_TYPE pin) {
if((pin == RADIOLIB_NC) || (cb_digitalRead == nullptr)) {
return((RADIOLIB_PIN_STATUS)0);
}
return(cb_digitalRead(pin));
}
void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value, uint32_t duration) {
#if !defined(RADIOLIB_TONE_UNSUPPORTED)
if((pin == RADIOLIB_NC) || (cb_tone == nullptr)) {
return;
}
cb_tone(pin, value, duration);
#else
if(pin == RADIOLIB_NC) {
return;
}
#if defined(ESP32)
// ESP32 tone() emulation
ledcAttachPin(pin, RADIOLIB_TONE_ESP32_CHANNEL);
ledcWriteTone(RADIOLIB_TONE_ESP32_CHANNEL, value);
#else
(void)value;
(void)duration;
#endif
#endif
}
void Module::noTone(RADIOLIB_PIN_TYPE pin) {
#if !defined(RADIOLIB_TONE_UNSUPPORTED)
if((pin == RADIOLIB_NC) || (cb_noTone == nullptr)) {
return;
}
#if defined(ARDUINO_ARCH_STM32)
cb_noTone(pin, false);
#else
cb_noTone(pin);
#endif
#else
if(pin == RADIOLIB_NC) {
return;
}
#if defined(ESP32)
// ESP32 tone() emulation
ledcDetachPin(pin);
ledcWrite(RADIOLIB_TONE_ESP32_CHANNEL, 0);
#endif
#endif
}
void Module::attachInterrupt(RADIOLIB_PIN_TYPE interruptNum, void (*userFunc)(void), RADIOLIB_INTERRUPT_STATUS mode) {
if((interruptNum == RADIOLIB_NC) || (cb_attachInterrupt == nullptr)) {
return;
}
cb_attachInterrupt(interruptNum, userFunc, mode);
}
void Module::detachInterrupt(RADIOLIB_PIN_TYPE interruptNum) {
if((interruptNum == RADIOLIB_NC) || (cb_detachInterrupt == nullptr)) {
return;
}
cb_detachInterrupt(interruptNum);
}
void Module::yield() {
if(cb_yield == nullptr) {
return;
}
#if !defined(RADIOLIB_YIELD_UNSUPPORTED)
cb_yield();
#endif
}
void Module::delay(uint32_t ms) {
if(cb_delay == nullptr) {
return;
}
cb_delay(ms);
}
void Module::delayMicroseconds(uint32_t us) {
if(cb_delayMicroseconds == nullptr) {
return;
}
cb_delayMicroseconds(us);
}
uint32_t Module::millis() {
if(cb_millis == nullptr) {
return(0);
}
return(cb_millis());
}
uint32_t Module::micros() {
if(cb_micros == nullptr) {
return(0);
}
return(cb_micros());
}
void Module::begin() {
if(cb_SPIbegin == nullptr) {
return;
}
(this->*cb_SPIbegin)();
}
void Module::beginTransaction() {
if(cb_SPIbeginTransaction == nullptr) {
return;
}
(this->*cb_SPIbeginTransaction)();
}
uint8_t Module::transfer(uint8_t b) {
if(cb_SPItransfer == nullptr) {
return(0xFF);
}
return((this->*cb_SPItransfer)(b));
}
void Module::endTransaction() {
if(cb_SPIendTransaction == nullptr) {
return;
}
(this->*cb_SPIendTransaction)();
}
void Module::end() {
if(cb_SPIend == nullptr) {
return;
}
(this->*cb_SPIend)();
}
#if defined(RADIOLIB_BUILD_ARDUINO)
void Module::SPIbegin() {
_spi->begin();
}
void Module::SPIbeginTransaction() {
_spi->beginTransaction(_spiSettings);
}
uint8_t Module::SPItransfer(uint8_t b) {
return(_spi->transfer(b));
}
void Module::SPIendTransaction() {
_spi->endTransaction();
}
void Module::SPIend() {
_spi->end();
}
#endif
uint8_t Module::flipBits(uint8_t b) {
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
b = (b & 0xCC) >> 2 | (b & 0x33) << 2;
b = (b & 0xAA) >> 1 | (b & 0x55) << 1;
return b;
}
uint16_t Module::flipBits16(uint16_t i) {
i = (i & 0xFF00) >> 8 | (i & 0x00FF) << 8;
i = (i & 0xF0F0) >> 4 | (i & 0x0F0F) << 4;
i = (i & 0xCCCC) >> 2 | (i & 0x3333) << 2;
i = (i & 0xAAAA) >> 1 | (i & 0x5555) << 1;
return i;
}
void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) {
_useRfSwitch = true;
_rxEn = rxEn;
_txEn = txEn;
this->pinMode(rxEn, OUTPUT);
this->pinMode(txEn, OUTPUT);
}
void Module::setRfSwitchState(RADIOLIB_PIN_STATUS rxPinState, RADIOLIB_PIN_STATUS txPinState) {
// check RF switch control is enabled
if(!_useRfSwitch) {
return;
}
// set pins
this->digitalWrite(_rxEn, rxPinState);
this->digitalWrite(_txEn, txPinState);
}

View File

@ -0,0 +1,431 @@
#if !defined(_RADIOLIB_MODULE_H)
#define _RADIOLIB_MODULE_H
#include "TypeDef.h"
#if defined(RADIOLIB_BUILD_ARDUINO)
#include <SPI.h>
#endif
/*!
\class Module
\brief Implements all common low-level methods to control the wireless module.
Every module class contains one private instance of this class.
*/
class Module {
public:
#if defined(RADIOLIB_BUILD_ARDUINO)
/*!
\brief Arduino Module constructor. Will use the default SPI interface and automatically initialize it
\param cs Arduino pin to be used as chip select.
\param irq Arduino pin to be used as interrupt/GPIO.
\param rst Arduino pin to be used as hardware reset for the module.
\param gpio Arduino pin to be used as additional interrupt/GPIO.
*/
Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio = RADIOLIB_NC);
/*!
\brief Arduino Module constructor. Will not attempt SPI interface initialization.
\param cs Arduino pin to be used as chip select.
\param irq Arduino pin to be used as interrupt/GPIO.
\param rst Arduino pin to be used as hardware reset for the module.
\param gpio Arduino pin to be used as additional interrupt/GPIO.
\param spi SPI interface to be used, can also use software SPI implementations.
\param spiSettings SPI interface settings.
*/
Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings);
#else
/*!
\brief Default constructor.
\param cs Pin to be used as chip select.
\param irq Pin to be used as interrupt/GPIO.
\param rst Pin to be used as hardware reset for the module.
\param gpio Pin to be used as additional interrupt/GPIO.
*/
Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio = RADIOLIB_NC);
#endif
/*!
\brief Copy constructor.
\param mod Module instance to copy.
*/
Module(const Module& mod);
/*!
\brief Overload for assignment operator.
\param frame rvalue Module.
*/
Module& operator=(const Module& mod);
// public member variables
/*!
\brief Basic SPI read command. Defaults to 0x00.
*/
uint8_t SPIreadCommand = 0b00000000;
/*!
\brief Basic SPI write command. Defaults to 0x80.
*/
uint8_t SPIwriteCommand = 0b10000000;
// basic methods
/*!
\brief Initialize low-level module control.
*/
void init();
/*!
\brief Terminate low-level module control.
*/
void term();
// SPI methods
/*!
\brief SPI read method that automatically masks unused bits. This method is the preferred SPI read mechanism.
\param reg Address of SPI register to read.
\param msb Most significant bit of the register variable. Bits above this one will be masked out.
\param lsb Least significant bit of the register variable. Bits below this one will be masked out.
\returns Masked register value or status code.
*/
int16_t SPIgetRegValue(uint8_t reg, uint8_t msb = 7, uint8_t lsb = 0);
/*!
\brief Overwrite-safe SPI write method with verification. This method is the preferred SPI write mechanism.
\param reg Address of SPI register to write.
\param value Single byte value that will be written to the SPI register.
\param msb Most significant bit of the register variable. Bits above this one will not be affected by the write operation.
\param lsb Least significant bit of the register variable. Bits below this one will not be affected by the write operation.
\param checkInterval Number of milliseconds between register writing and verification reading. Some registers need up to 10ms to process the change.
\param checkMask Mask of bits to check, only bits set to 1 will be verified.
\returns \ref status_codes
*/
int16_t SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb = 7, uint8_t lsb = 0, uint8_t checkInterval = 2, uint8_t checkMask = 0xFF);
/*!
\brief SPI burst read method.
\param reg Address of SPI register to read.
\param numBytes Number of bytes that will be read.
\param inBytes Pointer to array that will hold the read data.
*/
void SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes);
/*!
\brief SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead.
\param reg Address of SPI register to read.
\returns Value that was read from register.
*/
uint8_t SPIreadRegister(uint8_t reg);
/*!
\brief SPI burst write method.
\param reg Address of SPI register to write.
\param data Pointer to array that holds the data that will be written.
\param numBytes Number of bytes that will be written.
*/
void SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, uint8_t numBytes);
/*!
\brief SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead.
\param reg Address of SPI register to write.
\param data Value that will be written to the register.
*/
void SPIwriteRegister(uint8_t reg, uint8_t data);
/*!
\brief SPI single transfer method.
\param cmd SPI access command (read/write/burst/...).
\param reg Address of SPI register to transfer to/from.
\param dataOut Data that will be transfered from master to slave.
\param dataIn Data that was transfered from slave to master.
\param numBytes Number of bytes to transfer.
*/
void SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes);
// pin number access methods
/*!
\brief Access method to get the pin number of SPI chip select.
\returns Pin number of SPI chip select configured in the constructor.
*/
RADIOLIB_PIN_TYPE getCs() const { return(_cs); }
/*!
\brief Access method to get the pin number of interrupt/GPIO.
\returns Pin number of interrupt/GPIO configured in the constructor.
*/
RADIOLIB_PIN_TYPE getIrq() const { return(_irq); }
/*!
\brief Access method to get the pin number of hardware reset pin.
\returns Pin number of hardware reset pin configured in the constructor.
*/
RADIOLIB_PIN_TYPE getRst() const { return(_rst); }
/*!
\brief Access method to get the pin number of second interrupt/GPIO.
\returns Pin number of second interrupt/GPIO configured in the constructor.
*/
RADIOLIB_PIN_TYPE getGpio() const { return(_gpio); }
/*!
\brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state.
When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch!
\param rxEn RX enable pin.
\param txEn TX enable pin.
*/
void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn);
/*!
\brief Set RF switch state.
\param rxPinState Pin state to set on Tx enable pin (usually high to transmit).
\param txPinState Pin state to set on Rx enable pin (usually high to receive).
*/
void setRfSwitchState(RADIOLIB_PIN_STATUS rxPinState, RADIOLIB_PIN_STATUS txPinState);
// Arduino core overrides
/*!
\brief Arduino core pinMode override that checks RADIOLIB_NC as alias for unused pin.
\param pin Pin to change the mode of.
\param mode Which mode to set.
*/
void pinMode(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_MODE mode);
/*!
\brief Arduino core digitalWrite override that checks RADIOLIB_NC as alias for unused pin.
\param pin Pin to write to.
\param value Whether to set the pin high or low.
*/
void digitalWrite(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_STATUS value);
/*!
\brief Arduino core digitalWrite override that checks RADIOLIB_NC as alias for unused pin.
\param pin Pin to read from.
\returns Pin value.
*/
RADIOLIB_PIN_STATUS digitalRead(RADIOLIB_PIN_TYPE pin);
/*!
\brief Arduino core tone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone.
\param pin Pin to write to.
\param value Frequency to output.
*/
void tone(RADIOLIB_PIN_TYPE pin, uint16_t value, uint32_t duration = 0);
/*!
\brief Arduino core noTone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone.
\param pin Pin to write to.
*/
void noTone(RADIOLIB_PIN_TYPE pin);
/*!
\brief Arduino core attachInterrupt override.
\param interruptNum Interrupt number.
\param userFunc Interrupt service routine.
\param mode Pin hcange direction.
*/
void attachInterrupt(RADIOLIB_PIN_TYPE interruptNum, void (*userFunc)(void), RADIOLIB_INTERRUPT_STATUS mode);
/*!
\brief Arduino core detachInterrupt override.
\param interruptNum Interrupt number.
*/
void detachInterrupt(RADIOLIB_PIN_TYPE interruptNum);
/*!
\brief Arduino core yield override.
*/
void yield();
/*!
\brief Arduino core delay override.
\param ms Delay length in milliseconds.
*/
void delay(uint32_t ms);
/*!
\brief Arduino core delayMicroseconds override.
\param us Delay length in microseconds.
*/
void delayMicroseconds(uint32_t us);
/*!
\brief Arduino core millis override.
*/
uint32_t millis();
/*!
\brief Arduino core micros override.
*/
uint32_t micros();
/*!
\brief Arduino core SPI begin override.
*/
void begin();
/*!
\brief Arduino core SPI beginTransaction override.
*/
void beginTransaction();
/*!
\brief Arduino core SPI transfer override.
*/
uint8_t transfer(uint8_t b);
/*!
\brief Arduino core SPI endTransaction override.
*/
void endTransaction();
/*!
\brief Arduino core SPI end override.
*/
void end();
// helper functions to set up SPI overrides on Arduino
#if defined(RADIOLIB_BUILD_ARDUINO)
void SPIbegin();
void SPIbeginTransaction();
uint8_t SPItransfer(uint8_t b);
void SPIendTransaction();
void SPIend();
#endif
/*!
\brief Function to reflect bits within a byte.
*/
static uint8_t flipBits(uint8_t b);
/*!
\brief Function to reflect bits within an integer.
*/
static uint16_t flipBits16(uint16_t i);
// hardware abstraction layer callbacks
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_PIN_MODE);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DIGITAL_WRITE);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DIGITAL_READ);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_TONE);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_NO_TONE);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_ATTACH_INTERRUPT);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DETACH_INTERRUPT);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_YIELD);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DELAY);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DELAY_MICROSECONDS);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_MILLIS);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_MICROS);
#if defined(RADIOLIB_BUILD_ARDUINO)
RADIOLIB_GENERATE_CALLBACK_SPI(RADIOLIB_CB_ARGS_SPI_BEGIN);
RADIOLIB_GENERATE_CALLBACK_SPI(RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION);
RADIOLIB_GENERATE_CALLBACK_SPI(RADIOLIB_CB_ARGS_SPI_TRANSFER);
RADIOLIB_GENERATE_CALLBACK_SPI(RADIOLIB_CB_ARGS_SPI_END_TRANSACTION);
RADIOLIB_GENERATE_CALLBACK_SPI(RADIOLIB_CB_ARGS_SPI_END);
#else
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_SPI_BEGIN);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_SPI_TRANSFER);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_SPI_END_TRANSACTION);
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_SPI_END);
#endif
#if !defined(RADIOLIB_GODMODE)
private:
#endif
// pins
RADIOLIB_PIN_TYPE _cs = RADIOLIB_NC;
RADIOLIB_PIN_TYPE _irq = RADIOLIB_NC;
RADIOLIB_PIN_TYPE _rst = RADIOLIB_NC;
RADIOLIB_PIN_TYPE _gpio = RADIOLIB_NC;
// SPI interface (Arduino only)
#if defined(RADIOLIB_BUILD_ARDUINO)
SPIClass* _spi = NULL;
SPISettings _spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS;
bool _initInterface = false;
#endif
// RF switch presence and pins
bool _useRfSwitch = false;
RADIOLIB_PIN_TYPE _rxEn = RADIOLIB_NC;
RADIOLIB_PIN_TYPE _txEn = RADIOLIB_NC;
};
#endif

View File

@ -0,0 +1,135 @@
#if !defined(_RADIOLIB_H)
#define _RADIOLIB_H
/*!
\mainpage RadioLib Documentation
Universal wireless communication library for Arduino.
\par Currently Supported Wireless Modules and Protocols
- CC1101 FSK module
- RF69 FSK module
- Si443x FSK module
- SX126x LoRa/FSK module
- SX127x LoRa/FSK module
- SX128x LoRa/GFSK/BLE/FLRC module
- SX1231 FSK module
- PhysicalLayer protocols
- RTTY (RTTYClient)
- Morse Code (MorseClient)
- AX.25 (AX25Client)
- SSTV (SSTVClient)
- Hellschreiber (HellClient)
- 4-FSK (FSK4Client)
\par Quick Links
Documentation for most common methods can be found in its reference page (see the list above).\n
Some methods (mainly configuration) are also overridden in derived classes, such as SX1272, SX1278, RFM96 etc. for SX127x.\n
\ref status_codes have their own page.\n
Some modules implement methods of one or more compatibility layers, loosely based on the ISO/OSI model:
- PhysicalLayer - FSK and LoRa radio modules
\see https://github.com/jgromes/RadioLib
\copyright Copyright (c) 2019 Jan Gromes
*/
#include "TypeDef.h"
#include "Module.h"
// warnings are printed in this file since BuildOpt.h is compiled in multiple places
// check God mode
#if defined(RADIOLIB_GODMODE)
#warning "God mode active, I hope it was intentional. Buckle up, lads."
#endif
// print debug info
#if defined(RADIOLIB_DEBUG)
#pragma message "RADIOLIB_PLATFORM: " RADIOLIB_PLATFORM
#endif
// check unknown/unsupported platform
#if defined(RADIOLIB_UNKNOWN_PLATFORM)
#warning "RadioLib might not be compatible with this Arduino board - check supported platforms at https://github.com/jgromes/RadioLib!"
#endif
#include "modules/CC1101/CC1101.h"
#include "modules/LLCC68/LLCC68.h"
#include "modules/nRF24/nRF24.h"
#include "modules/RF69/RF69.h"
#include "modules/RFM2x/RFM22.h"
#include "modules/RFM2x/RFM23.h"
#include "modules/RFM9x/RFM95.h"
#include "modules/RFM9x/RFM96.h"
#include "modules/RFM9x/RFM97.h"
#include "modules/Si443x/Si4430.h"
#include "modules/Si443x/Si4431.h"
#include "modules/Si443x/Si4432.h"
#include "modules/SX1231/SX1231.h"
#include "modules/SX126x/SX1261.h"
#include "modules/SX126x/SX1262.h"
#include "modules/SX126x/SX1268.h"
#include "modules/SX127x/SX1272.h"
#include "modules/SX127x/SX1273.h"
#include "modules/SX127x/SX1276.h"
#include "modules/SX127x/SX1277.h"
#include "modules/SX127x/SX1278.h"
#include "modules/SX127x/SX1279.h"
#include "modules/SX128x/SX1280.h"
#include "modules/SX128x/SX1281.h"
#include "modules/SX128x/SX1282.h"
// physical layer protocols
#include "protocols/PhysicalLayer/PhysicalLayer.h"
#include "protocols/AFSK/AFSK.h"
#include "protocols/AX25/AX25.h"
#include "protocols/Hellschreiber/Hellschreiber.h"
#include "protocols/Morse/Morse.h"
#include "protocols/RTTY/RTTY.h"
#include "protocols/SSTV/SSTV.h"
#include "protocols/FSK4/FSK4.h"
// only create Radio class when using RadioShield
#if defined(RADIOLIB_RADIOSHIELD)
// RadioShield pin definitions
#define RADIOSHIELD_CS_A 10
#define RADIOSHIELD_IRQ_A 2
#define RADIOSHIELD_RST_A 9
#define RADIOSHIELD_GPIO_A 8
#define RADIOSHIELD_CS_B 5
#define RADIOSHIELD_IRQ_B 3
#define RADIOSHIELD_RST_B 7
#define RADIOSHIELD_GPIO_B 6
/*!
\class Radio
\brief Library control object when using RadioShield.
Contains two pre-configured "modules", which correspond to the slots on shield.
*/
class Radio {
public:
Module* ModuleA;
Module* ModuleB;
/*!
\brief Default constructor. Only used to set ModuleA and ModuleB configuration.
*/
Radio() {
ModuleA = new Module(RADIOSHIELD_CS_A, RADIOSHIELD_IRQ_A, RADIOSHIELD_RST_A, RADIOSHIELD_GPIO_A);
ModuleB = new Module(RADIOSHIELD_CS_B, RADIOSHIELD_IRQ_B, RADIOSHIELD_RST_B, RADIOSHIELD_GPIO_B);
}
#if defined(RADIOLIB_GODMODE)
private:
#endif
};
Radio RadioShield;
#endif
#endif

View File

@ -0,0 +1,375 @@
#if !defined(_RADIOLIB_TYPES_H)
#define _RADIOLIB_TYPES_H
#include "BuildOpt.h"
/*!
\defgroup config_shaping Data shaping filter values aliases.
\{
*/
/*!
\brief No shaping.
*/
#define RADIOLIB_SHAPING_NONE (0x00)
/*!
\brief Gaussin shaping filter, BT = 0.3
*/
#define RADIOLIB_SHAPING_0_3 (0x01)
/*!
\brief Gaussin shaping filter, BT = 0.5
*/
#define RADIOLIB_SHAPING_0_5 (0x02)
/*!
\brief Gaussin shaping filter, BT = 0.7
*/
#define RADIOLIB_SHAPING_0_7 (0x03)
/*!
\brief Gaussin shaping filter, BT = 1.0
*/
#define RADIOLIB_SHAPING_1_0 (0x04)
/*!
\}
*/
/*!
\defgroup config_encoding Encoding type aliases.
\{
*/
/*!
\brief Non-return to zero - no encoding.
*/
#define RADIOLIB_ENCODING_NRZ (0x00)
/*!
\brief Manchester encoding.
*/
#define RADIOLIB_ENCODING_MANCHESTER (0x01)
/*!
\brief Whitening.
*/
#define RADIOLIB_ENCODING_WHITENING (0x02)
/*!
\}
*/
/*!
\defgroup status_codes Status Codes
\{
*/
// common status codes
/*!
\brief No error, method executed successfully.
*/
#define RADIOLIB_ERR_NONE (0)
/*!
\brief There was an unexpected, unknown error. If you see this, something went incredibly wrong.
Your Arduino may be possessed, contact your local exorcist to resolve this error.
*/
#define RADIOLIB_ERR_UNKNOWN (-1)
// SX127x/RFM9x status codes
/*!
\brief Radio chip was not found during initialization. This can be caused by specifying wrong chip type in the constructor
(i.e. calling SX1272 constructor for SX1278 chip) or by a fault in your wiring (incorrect slave select pin).
*/
#define RADIOLIB_ERR_CHIP_NOT_FOUND (-2)
/*!
\brief Failed to allocate memory for temporary buffer. This can be cause by not enough RAM or by passing invalid pointer.
*/
#define RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED (-3)
/*!
\brief Packet supplied to transmission method was longer than limit.
*/
#define RADIOLIB_ERR_PACKET_TOO_LONG (-4)
/*!
\brief Timed out waiting for transmission finish.
*/
#define RADIOLIB_ERR_TX_TIMEOUT (-5)
/*!
\brief Timed out waiting for incoming transmission.
*/
#define RADIOLIB_ERR_RX_TIMEOUT (-6)
/*!
\brief The calculated and expected CRCs of received packet do not match.
This means that the packet was damaged during transmission and should be sent again.
*/
#define RADIOLIB_ERR_CRC_MISMATCH (-7)
/*!
\brief The supplied bandwidth value is invalid for this module.
*/
#define RADIOLIB_ERR_INVALID_BANDWIDTH (-8)
/*!
\brief The supplied spreading factor value is invalid for this module.
*/
#define RADIOLIB_ERR_INVALID_SPREADING_FACTOR (-9)
/*!
\brief The supplied coding rate value is invalid for this module.
*/
#define RADIOLIB_ERR_INVALID_CODING_RATE (-10)
/*!
\brief Internal only.
*/
#define RADIOLIB_ERR_INVALID_BIT_RANGE (-11)
/*!
\brief The supplied frequency value is invalid for this module.
*/
#define RADIOLIB_ERR_INVALID_FREQUENCY (-12)
/*!
\brief The supplied output power value is invalid for this module.
*/
#define RADIOLIB_ERR_INVALID_OUTPUT_POWER (-13)
/*!
\brief LoRa preamble was detected during channel activity detection.
This means that there is some LoRa device currently transmitting in your channel.
*/
#define RADIOLIB_PREAMBLE_DETECTED (-14)
/*!
\brief No LoRa preambles were detected during channel activity detection. Your channel is free.
*/
#define RADIOLIB_CHANNEL_FREE (-15)
/*!
\brief Real value in SPI register does not match the expected one. This can be caused by faulty SPI wiring.
*/
#define RADIOLIB_ERR_SPI_WRITE_FAILED (-16)
/*!
\brief The supplied current limit value is invalid.
*/
#define RADIOLIB_ERR_INVALID_CURRENT_LIMIT (-17)
/*!
\brief The supplied preamble length is invalid.
*/
#define RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH (-18)
/*!
\brief The supplied gain value is invalid.
*/
#define RADIOLIB_ERR_INVALID_GAIN (-19)
/*!
\brief User tried to execute modem-exclusive method on a wrong modem.
For example, this can happen when you try to change LoRa configuration when FSK modem is active.
*/
#define RADIOLIB_ERR_WRONG_MODEM (-20)
/*!
\brief The supplied number of RSSI samples is invalid.
*/
#define RADIOLIB_ERR_INVALID_NUM_SAMPLES (-21)
/*!
\brief The supplied RSSI offset is invalid.
*/
#define RADIOLIB_ERR_INVALID_RSSI_OFFSET (-22)
/*!
\brief The supplied encoding is invalid.
*/
#define RADIOLIB_ERR_INVALID_ENCODING (-23)
/*!
\brief LoRa packet header has been damaged.
*/
#define RADIOLIB_ERR_LORA_HEADER_DAMAGED (-24)
// RF69-specific status codes
/*!
\brief The supplied bit rate value is invalid.
*/
#define RADIOLIB_ERR_INVALID_BIT_RATE (-101)
/*!
\brief The supplied frequency deviation value is invalid.
*/
#define RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION (-102)
/*!
\brief The supplied bit rate to bandwidth ratio is invalid. See the module datasheet for more information.
*/
#define RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO (-103)
/*!
\brief The supplied receiver bandwidth value is invalid.
*/
#define RADIOLIB_ERR_INVALID_RX_BANDWIDTH (-104)
/*!
\brief The supplied FSK sync word is invalid.
*/
#define RADIOLIB_ERR_INVALID_SYNC_WORD (-105)
/*!
\brief The supplied FSK data shaping option is invalid.
*/
#define RADIOLIB_ERR_INVALID_DATA_SHAPING (-106)
/*!
\brief The current modulation is invalid for the requested operation.
*/
#define RADIOLIB_ERR_INVALID_MODULATION (-107)
/*!
\brief Supplied Peak type is invalid.
*/
#define RADIOLIB_ERR_INVALID_OOK_RSSI_PEAK_TYPE (-108)
// RTTY status codes
/*!
\brief Supplied RTTY frequency shift is invalid for this module.
*/
#define RADIOLIB_ERR_INVALID_RTTY_SHIFT (-401)
/*!
\brief Supplied RTTY encoding is invalid.
*/
#define RADIOLIB_ERR_UNSUPPORTED_ENCODING (-402)
// nRF24-specific status codes
/*!
\brief Supplied data rate is invalid.
*/
#define RADIOLIB_ERR_INVALID_DATA_RATE (-501)
/*!
\brief Supplied address width is invalid.
*/
#define RADIOLIB_ERR_INVALID_ADDRESS_WIDTH (-502)
/*!
\brief Supplied data pipe number is invalid.
*/
#define RADIOLIB_ERR_INVALID_PIPE_NUMBER (-503)
/*!
\brief ACK packet from destination module was not received within 15 retries.
*/
#define RADIOLIB_ERR_ACK_NOT_RECEIVED (-504)
// CC1101-specific status codes
/*!
\brief Supplied number of broadcast addresses is invalid.
*/
#define RADIOLIB_ERR_INVALID_NUM_BROAD_ADDRS (-601)
// SX126x-specific status codes
/*!
\brief Supplied CRC configuration is invalid.
*/
#define RADIOLIB_ERR_INVALID_CRC_CONFIGURATION (-701)
/*!
\brief Detected LoRa transmission while scanning channel.
*/
#define RADIOLIB_LORA_DETECTED (-702)
/*!
\brief Supplied TCXO reference voltage is invalid.
*/
#define RADIOLIB_ERR_INVALID_TCXO_VOLTAGE (-703)
/*!
\brief Bit rate / bandwidth / frequency deviation ratio is invalid. See SX126x datasheet for details.
*/
#define RADIOLIB_ERR_INVALID_MODULATION_PARAMETERS (-704)
/*!
\brief SX126x timed out while waiting for complete SPI command.
*/
#define RADIOLIB_ERR_SPI_CMD_TIMEOUT (-705)
/*!
\brief SX126x received invalid SPI command.
*/
#define RADIOLIB_ERR_SPI_CMD_INVALID (-706)
/*!
\brief SX126x failed to execute SPI command.
*/
#define RADIOLIB_ERR_SPI_CMD_FAILED (-707)
/*!
\brief The supplied sleep period is invalid.
The specified sleep period is shorter than the time necessary to sleep and wake the hardware
including TCXO delay, or longer than the maximum possible
*/
#define RADIOLIB_ERR_INVALID_SLEEP_PERIOD (-708)
/*!
\brief The supplied Rx period is invalid.
The specified Rx period is shorter or longer than the hardware can handle.
*/
#define RADIOLIB_ERR_INVALID_RX_PERIOD (-709)
// AX.25-specific status codes
/*!
\brief The provided callsign is invalid.
The specified callsign is longer than 6 ASCII characters.
*/
#define RADIOLIB_ERR_INVALID_CALLSIGN (-801)
/*!
\brief The provided repeater configuration is invalid.
The specified number of repeaters does not match number of repeater IDs or their callsigns.
*/
#define RADIOLIB_ERR_INVALID_NUM_REPEATERS (-802)
/*!
\brief One of the provided repeater callsigns is invalid.
The specified callsign is longer than 6 ASCII characters.
*/
#define RADIOLIB_ERR_INVALID_REPEATER_CALLSIGN (-803)
// SX128x-specific status codes
/*!
\brief Timed out waiting for ranging exchange finish.
*/
#define RADIOLIB_ERR_RANGING_TIMEOUT (-901)
/*!
\}
*/
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,959 @@
#if !defined(_RADIOLIB_CC1101_H) && !defined(RADIOLIB_EXCLUDE_CC1101)
#define _RADIOLIB_CC1101_H
#include "../../TypeDef.h"
#include "../../Module.h"
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
// CC1101 physical layer properties
#define RADIOLIB_CC1101_FREQUENCY_STEP_SIZE 396.7285156
#define RADIOLIB_CC1101_MAX_PACKET_LENGTH 255
#define RADIOLIB_CC1101_CRYSTAL_FREQ 26.0
#define RADIOLIB_CC1101_DIV_EXPONENT 16
#define RADIOLIB_CC1101_FIFO_SIZE 64
// CC1101 SPI commands
#define RADIOLIB_CC1101_CMD_READ 0b10000000
#define RADIOLIB_CC1101_CMD_WRITE 0b00000000
#define RADIOLIB_CC1101_CMD_BURST 0b01000000
#define RADIOLIB_CC1101_CMD_ACCESS_STATUS_REG 0b01000000
#define RADIOLIB_CC1101_CMD_FIFO_RX 0b10000000
#define RADIOLIB_CC1101_CMD_FIFO_TX 0b00000000
#define RADIOLIB_CC1101_CMD_RESET 0x30
#define RADIOLIB_CC1101_CMD_FSTXON 0x31
#define RADIOLIB_CC1101_CMD_XOFF 0x32
#define RADIOLIB_CC1101_CMD_CAL 0x33
#define RADIOLIB_CC1101_CMD_RX 0x34
#define RADIOLIB_CC1101_CMD_TX 0x35
#define RADIOLIB_CC1101_CMD_IDLE 0x36
#define RADIOLIB_CC1101_CMD_WOR 0x38
#define RADIOLIB_CC1101_CMD_POWER_DOWN 0x39
#define RADIOLIB_CC1101_CMD_FLUSH_RX 0x3A
#define RADIOLIB_CC1101_CMD_FLUSH_TX 0x3B
#define RADIOLIB_CC1101_CMD_WOR_RESET 0x3C
#define RADIOLIB_CC1101_CMD_NOP 0x3D
// CC1101 register map
#define RADIOLIB_CC1101_REG_IOCFG2 0x00
#define RADIOLIB_CC1101_REG_IOCFG1 0x01
#define RADIOLIB_CC1101_REG_IOCFG0 0x02
#define RADIOLIB_CC1101_REG_FIFOTHR 0x03
#define RADIOLIB_CC1101_REG_SYNC1 0x04
#define RADIOLIB_CC1101_REG_SYNC0 0x05
#define RADIOLIB_CC1101_REG_PKTLEN 0x06
#define RADIOLIB_CC1101_REG_PKTCTRL1 0x07
#define RADIOLIB_CC1101_REG_PKTCTRL0 0x08
#define RADIOLIB_CC1101_REG_ADDR 0x09
#define RADIOLIB_CC1101_REG_CHANNR 0x0A
#define RADIOLIB_CC1101_REG_FSCTRL1 0x0B
#define RADIOLIB_CC1101_REG_FSCTRL0 0x0C
#define RADIOLIB_CC1101_REG_FREQ2 0x0D
#define RADIOLIB_CC1101_REG_FREQ1 0x0E
#define RADIOLIB_CC1101_REG_FREQ0 0x0F
#define RADIOLIB_CC1101_REG_MDMCFG4 0x10
#define RADIOLIB_CC1101_REG_MDMCFG3 0x11
#define RADIOLIB_CC1101_REG_MDMCFG2 0x12
#define RADIOLIB_CC1101_REG_MDMCFG1 0x13
#define RADIOLIB_CC1101_REG_MDMCFG0 0x14
#define RADIOLIB_CC1101_REG_DEVIATN 0x15
#define RADIOLIB_CC1101_REG_MCSM2 0x16
#define RADIOLIB_CC1101_REG_MCSM1 0x17
#define RADIOLIB_CC1101_REG_MCSM0 0x18
#define RADIOLIB_CC1101_REG_FOCCFG 0x19
#define RADIOLIB_CC1101_REG_BSCFG 0x1A
#define RADIOLIB_CC1101_REG_AGCCTRL2 0x1B
#define RADIOLIB_CC1101_REG_AGCCTRL1 0x1C
#define RADIOLIB_CC1101_REG_AGCCTRL0 0x1D
#define RADIOLIB_CC1101_REG_WOREVT1 0x1E
#define RADIOLIB_CC1101_REG_WOREVT0 0x1F
#define RADIOLIB_CC1101_REG_WORCTRL 0x20
#define RADIOLIB_CC1101_REG_FREND1 0x21
#define RADIOLIB_CC1101_REG_FREND0 0x22
#define RADIOLIB_CC1101_REG_FSCAL3 0x23
#define RADIOLIB_CC1101_REG_FSCAL2 0x24
#define RADIOLIB_CC1101_REG_FSCAL1 0x25
#define RADIOLIB_CC1101_REG_FSCAL0 0x26
#define RADIOLIB_CC1101_REG_RCCTRL1 0x27
#define RADIOLIB_CC1101_REG_RCCTRL0 0x28
#define RADIOLIB_CC1101_REG_FSTEST 0x29
#define RADIOLIB_CC1101_REG_PTEST 0x2A
#define RADIOLIB_CC1101_REG_AGCTEST 0x2B
#define RADIOLIB_CC1101_REG_TEST2 0x2C
#define RADIOLIB_CC1101_REG_TEST1 0x2D
#define RADIOLIB_CC1101_REG_TEST0 0x2E
#define RADIOLIB_CC1101_REG_PARTNUM 0x30
#define RADIOLIB_CC1101_REG_VERSION 0x31
#define RADIOLIB_CC1101_REG_FREQEST 0x32
#define RADIOLIB_CC1101_REG_LQI 0x33
#define RADIOLIB_CC1101_REG_RSSI 0x34
#define RADIOLIB_CC1101_REG_MARCSTATE 0x35
#define RADIOLIB_CC1101_REG_WORTIME1 0x36
#define RADIOLIB_CC1101_REG_WORTIME0 0x37
#define RADIOLIB_CC1101_REG_PKTSTATUS 0x38
#define RADIOLIB_CC1101_REG_VCO_VC_DAC 0x39
#define RADIOLIB_CC1101_REG_TXBYTES 0x3A
#define RADIOLIB_CC1101_REG_RXBYTES 0x3B
#define RADIOLIB_CC1101_REG_RCCTRL1_STATUS 0x3C
#define RADIOLIB_CC1101_REG_RCCTRL0_STATUS 0x3D
#define RADIOLIB_CC1101_REG_PATABLE 0x3E
#define RADIOLIB_CC1101_REG_FIFO 0x3F
// CC1101_REG_IOCFG2 MSB LSB DESCRIPTION
#define RADIOLIB_CC1101_GDO2_NORM 0b00000000 // 6 6 GDO2 output: active high (default)
#define RADIOLIB_CC1101_GDO2_INV 0b01000000 // 6 6 active low
// CC1101_REG_IOCFG1
#define RADIOLIB_CC1101_GDO1_DS_LOW 0b00000000 // 7 7 GDO1 output drive strength: low (default)
#define RADIOLIB_CC1101_GDO1_DS_HIGH 0b10000000 // 7 7 high
#define RADIOLIB_CC1101_GDO1_NORM 0b00000000 // 6 6 GDO1 output: active high (default)
#define RADIOLIB_CC1101_GDO1_INV 0b01000000 // 6 6 active low
// CC1101_REG_IOCFG0
#define RADIOLIB_CC1101_GDO0_TEMP_SENSOR_OFF 0b00000000 // 7 7 analog temperature sensor output: disabled (default)
#define RADIOLIB_CC1101_GDO0_TEMP_SENSOR_ON 0b10000000 // 7 0 enabled
#define RADIOLIB_CC1101_GDO0_NORM 0b00000000 // 6 6 GDO0 output: active high (default)
#define RADIOLIB_CC1101_GDO0_INV 0b01000000 // 6 6 active low
// CC1101_REG_IOCFG2 + REG_IOCFG1 + REG_IOCFG0
#define RADIOLIB_CC1101_GDOX_RX_FIFO_FULL 0x00 // 5 0 Rx FIFO full or above threshold
#define RADIOLIB_CC1101_GDOX_RX_FIFO_FULL_OR_PKT_END 0x01 // 5 0 Rx FIFO full or above threshold or reached packet end
#define RADIOLIB_CC1101_GDOX_TX_FIFO_ABOVE_THR 0x02 // 5 0 Tx FIFO above threshold
#define RADIOLIB_CC1101_GDOX_TX_FIFO_FULL 0x03 // 5 0 Tx FIFO full
#define RADIOLIB_CC1101_GDOX_RX_FIFO_OVERFLOW 0x04 // 5 0 Rx FIFO overflowed
#define RADIOLIB_CC1101_GDOX_TX_FIFO_UNDERFLOW 0x05 // 5 0 Tx FIFO underflowed
#define RADIOLIB_CC1101_GDOX_SYNC_WORD_SENT_OR_RECEIVED 0x06 // 5 0 sync word was sent or received
#define RADIOLIB_CC1101_GDOX_PKT_RECEIVED_CRC_OK 0x07 // 5 0 packet received and CRC check passed
#define RADIOLIB_CC1101_GDOX_PREAMBLE_QUALITY_REACHED 0x08 // 5 0 received preamble quality is above threshold
#define RADIOLIB_CC1101_GDOX_CHANNEL_CLEAR 0x09 // 5 0 RSSI level below threshold (channel is clear)
#define RADIOLIB_CC1101_GDOX_PLL_LOCKED 0x0A // 5 0 PLL is locked
#define RADIOLIB_CC1101_GDOX_SERIAL_CLOCK 0x0B // 5 0 serial data clock
#define RADIOLIB_CC1101_GDOX_SERIAL_DATA_SYNC 0x0C // 5 0 serial data output in: synchronous mode
#define RADIOLIB_CC1101_GDOX_SERIAL_DATA_ASYNC 0x0D // 5 0 asynchronous mode
#define RADIOLIB_CC1101_GDOX_CARRIER_SENSE 0x0E // 5 0 RSSI above threshold
#define RADIOLIB_CC1101_GDOX_CRC_OK 0x0F // 5 0 CRC check passed
#define RADIOLIB_CC1101_GDOX_RX_HARD_DATA1 0x16 // 5 0 direct access to demodulated data
#define RADIOLIB_CC1101_GDOX_RX_HARD_DATA0 0x17 // 5 0 direct access to demodulated data
#define RADIOLIB_CC1101_GDOX_PA_PD 0x1B // 5 0 power amplifier circuit is powered down
#define RADIOLIB_CC1101_GDOX_LNA_PD 0x1C // 5 0 low-noise amplifier circuit is powered down
#define RADIOLIB_CC1101_GDOX_RX_SYMBOL_TICK 0x1D // 5 0 direct access to symbol tick of received data
#define RADIOLIB_CC1101_GDOX_WOR_EVNT0 0x24 // 5 0 wake-on-radio event 0
#define RADIOLIB_CC1101_GDOX_WOR_EVNT1 0x25 // 5 0 wake-on-radio event 1
#define RADIOLIB_CC1101_GDOX_CLK_256 0x26 // 5 0 256 Hz clock
#define RADIOLIB_CC1101_GDOX_CLK_32K 0x27 // 5 0 32 kHz clock
#define RADIOLIB_CC1101_GDOX_CHIP_RDYN 0x29 // 5 0 (default for GDO2)
#define RADIOLIB_CC1101_GDOX_XOSC_STABLE 0x2B // 5 0
#define RADIOLIB_CC1101_GDOX_HIGH_Z 0x2E // 5 0 high impedance state (default for GDO1)
#define RADIOLIB_CC1101_GDOX_HW_TO_0 0x2F // 5 0
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_1 0x30 // 5 0 crystal oscillator clock: f = f(XOSC)/1
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_1_5 0x31 // 5 0 f = f(XOSC)/1.5
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_2 0x32 // 5 0 f = f(XOSC)/2
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_3 0x33 // 5 0 f = f(XOSC)/3
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_4 0x34 // 5 0 f = f(XOSC)/4
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_6 0x35 // 5 0 f = f(XOSC)/6
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_8 0x36 // 5 0 f = f(XOSC)/8
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_12 0x37 // 5 0 f = f(XOSC)/12
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_16 0x38 // 5 0 f = f(XOSC)/16
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_24 0x39 // 5 0 f = f(XOSC)/24
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_32 0x3A // 5 0 f = f(XOSC)/32
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_48 0x3B // 5 0 f = f(XOSC)/48
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_64 0x3C // 5 0 f = f(XOSC)/64
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_96 0x3D // 5 0 f = f(XOSC)/96
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_128 0x3E // 5 0 f = f(XOSC)/128
#define RADIOLIB_CC1101_GDOX_CLOCK_XOSC_192 0x3F // 5 0 f = f(XOSC)/192 (default for GDO0)
// CC1101_REG_FIFOTHR
#define RADIOLIB_CC1101_ADC_RETENTION_OFF 0b00000000 // 6 6 do not retain ADC settings in sleep mode (default)
#define RADIOLIB_CC1101_ADC_RETENTION_ON 0b01000000 // 6 6 retain ADC settings in sleep mode
#define RADIOLIB_CC1101_RX_ATTEN_0_DB 0b00000000 // 5 4 Rx attenuation: 0 dB (default)
#define RADIOLIB_CC1101_RX_ATTEN_6_DB 0b00010000 // 5 4 6 dB
#define RADIOLIB_CC1101_RX_ATTEN_12_DB 0b00100000 // 5 4 12 dB
#define RADIOLIB_CC1101_RX_ATTEN_18_DB 0b00110000 // 5 4 18 dB
#define RADIOLIB_CC1101_FIFO_THR_TX_61_RX_4 0b00000000 // 3 0 TX fifo threshold: 61, RX fifo threshold: 4
// CC1101_REG_SYNC1
#define RADIOLIB_CC1101_SYNC_WORD_MSB 0xD3 // 7 0 sync word MSB
// CC1101_REG_SYNC0
#define RADIOLIB_CC1101_SYNC_WORD_LSB 0x91 // 7 0 sync word LSB
// CC1101_REG_PKTLEN
#define RADIOLIB_CC1101_PACKET_LENGTH 0xFF // 7 0 packet length in bytes
// CC1101_REG_PKTCTRL1
#define RADIOLIB_CC1101_PQT 0x00 // 7 5 preamble quality threshold
#define RADIOLIB_CC1101_CRC_AUTOFLUSH_OFF 0b00000000 // 3 3 automatic Rx FIFO flush on CRC check fail: disabled (default)
#define RADIOLIB_CC1101_CRC_AUTOFLUSH_ON 0b00001000 // 3 3 enabled
#define RADIOLIB_CC1101_APPEND_STATUS_OFF 0b00000000 // 2 2 append 2 status bytes to packet: disabled
#define RADIOLIB_CC1101_APPEND_STATUS_ON 0b00000100 // 2 2 enabled (default)
#define RADIOLIB_CC1101_ADR_CHK_NONE 0b00000000 // 1 0 address check: none (default)
#define RADIOLIB_CC1101_ADR_CHK_NO_BROADCAST 0b00000001 // 1 0 without broadcast
#define RADIOLIB_CC1101_ADR_CHK_SINGLE_BROADCAST 0b00000010 // 1 0 broadcast address 0x00
#define RADIOLIB_CC1101_ADR_CHK_DOUBLE_BROADCAST 0b00000011 // 1 0 broadcast addresses 0x00 and 0xFF
// CC1101_REG_PKTCTRL0
#define RADIOLIB_CC1101_WHITE_DATA_OFF 0b00000000 // 6 6 data whitening: disabled
#define RADIOLIB_CC1101_WHITE_DATA_ON 0b01000000 // 6 6 enabled (default)
#define RADIOLIB_CC1101_PKT_FORMAT_NORMAL 0b00000000 // 5 4 packet format: normal (FIFOs)
#define RADIOLIB_CC1101_PKT_FORMAT_SYNCHRONOUS 0b00010000 // 5 4 synchronous serial
#define RADIOLIB_CC1101_PKT_FORMAT_RANDOM 0b00100000 // 5 4 random transmissions
#define RADIOLIB_CC1101_PKT_FORMAT_ASYNCHRONOUS 0b00110000 // 5 4 asynchronous serial
#define RADIOLIB_CC1101_CRC_OFF 0b00000000 // 2 2 CRC disabled
#define RADIOLIB_CC1101_CRC_ON 0b00000100 // 2 2 CRC enabled (default)
#define RADIOLIB_CC1101_LENGTH_CONFIG_FIXED 0b00000000 // 1 0 packet length: fixed
#define RADIOLIB_CC1101_LENGTH_CONFIG_VARIABLE 0b00000001 // 1 0 variable (default)
#define RADIOLIB_CC1101_LENGTH_CONFIG_INFINITE 0b00000010 // 1 0 infinite
// CC1101_REG_ADDR
#define RADIOLIB_CC1101_DEVICE_ADDR 0x00 // 7 0 device address
// CC1101_REG_CHANNR
#define RADIOLIB_CC1101_CHAN 0x00 // 7 0 channel number
// CC1101_REG_FSCTRL1
#define RADIOLIB_CC1101_FREQ_IF 0x0F // 4 0 IF frequency setting; f_IF = (f(XOSC) / 2^10) * CC1101_FREQ_IF
// CC1101_REG_FSCTRL0
#define RADIOLIB_CC1101_FREQOFF 0x00 // 7 0 base frequency offset (2s-compliment)
// CC1101_REG_FREQ2 + REG_FREQ1 + REG_FREQ0
#define RADIOLIB_CC1101_FREQ_MSB 0x1E // 5 0 base frequency setting: f_carrier = (f(XOSC) / 2^16) * FREQ
#define RADIOLIB_CC1101_FREQ_MID 0xC4 // 7 0 where f(XOSC) = 26 MHz
#define RADIOLIB_CC1101_FREQ_LSB 0xEC // 7 0 FREQ = 3-byte value of FREQ registers
// CC1101_REG_MDMCFG4
#define RADIOLIB_CC1101_CHANBW_E 0b10000000 // 7 6 channel bandwidth: BW_channel = f(XOSC) / (8 * (4 + CHANBW_M)*2^CHANBW_E) [Hz]
#define RADIOLIB_CC1101_CHANBW_M 0b00000000 // 5 4 default value for 26 MHz crystal: 203 125 Hz
#define RADIOLIB_CC1101_DRATE_E 0x0C // 3 0 symbol rate: R_data = (((256 + DRATE_M) * 2^DRATE_E) / 2^28) * f(XOSC) [Baud]
// CC1101_REG_MDMCFG3
#define RADIOLIB_CC1101_DRATE_M 0x22 // 7 0 default value for 26 MHz crystal: 115 051 Baud
// CC1101_REG_MDMCFG2
#define RADIOLIB_CC1101_DEM_DCFILT_OFF 0b10000000 // 7 7 digital DC filter: disabled
#define RADIOLIB_CC1101_DEM_DCFILT_ON 0b00000000 // 7 7 enabled - only for data rates above 250 kBaud (default)
#define RADIOLIB_CC1101_MOD_FORMAT_2_FSK 0b00000000 // 6 4 modulation format: 2-FSK (default)
#define RADIOLIB_CC1101_MOD_FORMAT_GFSK 0b00010000 // 6 4 GFSK
#define RADIOLIB_CC1101_MOD_FORMAT_ASK_OOK 0b00110000 // 6 4 ASK/OOK
#define RADIOLIB_CC1101_MOD_FORMAT_4_FSK 0b01000000 // 6 4 4-FSK
#define RADIOLIB_CC1101_MOD_FORMAT_MFSK 0b01110000 // 6 4 MFSK - only for data rates above 26 kBaud
#define RADIOLIB_CC1101_MANCHESTER_EN_OFF 0b00000000 // 3 3 Manchester encoding: disabled (default)
#define RADIOLIB_CC1101_MANCHESTER_EN_ON 0b00001000 // 3 3 enabled
#define RADIOLIB_CC1101_SYNC_MODE_NONE 0b00000000 // 2 0 synchronization: no preamble/sync
#define RADIOLIB_CC1101_SYNC_MODE_15_16 0b00000001 // 2 0 15/16 sync word bits
#define RADIOLIB_CC1101_SYNC_MODE_16_16 0b00000010 // 2 0 16/16 sync word bits (default)
#define RADIOLIB_CC1101_SYNC_MODE_30_32 0b00000011 // 2 0 30/32 sync word bits
#define RADIOLIB_CC1101_SYNC_MODE_NONE_THR 0b00000100 // 2 0 no preamble sync, carrier sense above threshold
#define RADIOLIB_CC1101_SYNC_MODE_15_16_THR 0b00000101 // 2 0 15/16 sync word bits, carrier sense above threshold
#define RADIOLIB_CC1101_SYNC_MODE_16_16_THR 0b00000110 // 2 0 16/16 sync word bits, carrier sense above threshold
#define RADIOLIB_CC1101_SYNC_MODE_30_32_THR 0b00000111 // 2 0 30/32 sync word bits, carrier sense above threshold
// CC1101_REG_MDMCFG1
#define RADIOLIB_CC1101_FEC_OFF 0b00000000 // 7 7 forward error correction: disabled (default)
#define RADIOLIB_CC1101_FEC_ON 0b10000000 // 7 7 enabled - only for fixed packet length
#define RADIOLIB_CC1101_NUM_PREAMBLE_2 0b00000000 // 6 4 number of preamble bytes: 2
#define RADIOLIB_CC1101_NUM_PREAMBLE_3 0b00010000 // 6 4 3
#define RADIOLIB_CC1101_NUM_PREAMBLE_4 0b00100000 // 6 4 4 (default)
#define RADIOLIB_CC1101_NUM_PREAMBLE_6 0b00110000 // 6 4 6
#define RADIOLIB_CC1101_NUM_PREAMBLE_8 0b01000000 // 6 4 8
#define RADIOLIB_CC1101_NUM_PREAMBLE_12 0b01010000 // 6 4 12
#define RADIOLIB_CC1101_NUM_PREAMBLE_16 0b01100000 // 6 4 16
#define RADIOLIB_CC1101_NUM_PREAMBLE_24 0b01110000 // 6 4 24
#define RADIOLIB_CC1101_CHANSPC_E 0x02 // 1 0 channel spacing: df_channel = (f(XOSC) / 2^18) * (256 + CHANSPC_M) * 2^CHANSPC_E [Hz]
// CC1101_REG_MDMCFG0
#define RADIOLIB_CC1101_CHANSPC_M 0xF8 // 7 0 default value for 26 MHz crystal: 199 951 kHz
// CC1101_REG_DEVIATN
#define RADIOLIB_CC1101_DEVIATION_E 0b01000000 // 6 4 frequency deviation: f_dev = (f(XOSC) / 2^17) * (8 + DEVIATION_M) * 2^DEVIATION_E [Hz]
#define RADIOLIB_CC1101_DEVIATION_M 0b00000111 // 2 0 default value for 26 MHz crystal: +- 47 607 Hz
#define RADIOLIB_CC1101_MSK_PHASE_CHANGE_PERIOD 0x07 // 2 0 phase change symbol period fraction: 1 / (MSK_PHASE_CHANGE_PERIOD + 1)
// CC1101_REG_MCSM2
#define RADIOLIB_CC1101_RX_TIMEOUT_RSSI_OFF 0b00000000 // 4 4 Rx timeout based on RSSI value: disabled (default)
#define RADIOLIB_CC1101_RX_TIMEOUT_RSSI_ON 0b00010000 // 4 4 enabled
#define RADIOLIB_CC1101_RX_TIMEOUT_QUAL_OFF 0b00000000 // 3 3 check for sync word on Rx timeout
#define RADIOLIB_CC1101_RX_TIMEOUT_QUAL_ON 0b00001000 // 3 3 check for PQI set on Rx timeout
#define RADIOLIB_CC1101_RX_TIMEOUT_OFF 0b00000111 // 2 0 Rx timeout: disabled (default)
#define RADIOLIB_CC1101_RX_TIMEOUT_MAX 0b00000000 // 2 0 max value (actual value depends on WOR_RES, EVENT0 and f(XOSC))
// CC1101_REG_MCSM1
#define RADIOLIB_CC1101_CCA_MODE_ALWAYS 0b00000000 // 5 4 clear channel indication: always
#define RADIOLIB_CC1101_CCA_MODE_RSSI_THR 0b00010000 // 5 4 RSSI below threshold
#define RADIOLIB_CC1101_CCA_MODE_RX_PKT 0b00100000 // 5 4 unless receiving packet
#define RADIOLIB_CC1101_CCA_MODE_RSSI_THR_RX_PKT 0b00110000 // 5 4 RSSI below threshold unless receiving packet (default)
#define RADIOLIB_CC1101_RXOFF_IDLE 0b00000000 // 3 2 next mode after packet reception: idle (default)
#define RADIOLIB_CC1101_RXOFF_FSTXON 0b00000100 // 3 2 FSTxOn
#define RADIOLIB_CC1101_RXOFF_TX 0b00001000 // 3 2 Tx
#define RADIOLIB_CC1101_RXOFF_RX 0b00001100 // 3 2 Rx
#define RADIOLIB_CC1101_TXOFF_IDLE 0b00000000 // 1 0 next mode after packet transmission: idle (default)
#define RADIOLIB_CC1101_TXOFF_FSTXON 0b00000001 // 1 0 FSTxOn
#define RADIOLIB_CC1101_TXOFF_TX 0b00000010 // 1 0 Tx
#define RADIOLIB_CC1101_TXOFF_RX 0b00000011 // 1 0 Rx
// CC1101_REG_MCSM0
#define RADIOLIB_CC1101_FS_AUTOCAL_NEVER 0b00000000 // 5 4 automatic calibration: never (default)
#define RADIOLIB_CC1101_FS_AUTOCAL_IDLE_TO_RXTX 0b00010000 // 5 4 every transition from idle to Rx/Tx
#define RADIOLIB_CC1101_FS_AUTOCAL_RXTX_TO_IDLE 0b00100000 // 5 4 every transition from Rx/Tx to idle
#define RADIOLIB_CC1101_FS_AUTOCAL_RXTX_TO_IDLE_4TH 0b00110000 // 5 4 every 4th transition from Rx/Tx to idle
#define RADIOLIB_CC1101_PO_TIMEOUT_COUNT_1 0b00000000 // 3 2 number of counter expirations before CHP_RDYN goes low: 1 (default)
#define RADIOLIB_CC1101_PO_TIMEOUT_COUNT_16 0b00000100 // 3 2 16
#define RADIOLIB_CC1101_PO_TIMEOUT_COUNT_64 0b00001000 // 3 2 64
#define RADIOLIB_CC1101_PO_TIMEOUT_COUNT_256 0b00001100 // 3 2 256
#define RADIOLIB_CC1101_PIN_CTRL_OFF 0b00000000 // 1 1 pin radio control: disabled (default)
#define RADIOLIB_CC1101_PIN_CTRL_ON 0b00000010 // 1 1 enabled
#define RADIOLIB_CC1101_XOSC_FORCE_OFF 0b00000000 // 0 0 do not force XOSC to remain on in sleep (default)
#define RADIOLIB_CC1101_XOSC_FORCE_ON 0b00000001 // 0 0 force XOSC to remain on in sleep
// CC1101_REG_FOCCFG
#define RADIOLIB_CC1101_FOC_BS_CS_GATE_OFF 0b00000000 // 5 5 do not freeze frequency compensation until CS goes high
#define RADIOLIB_CC1101_FOC_BS_CS_GATE_ON 0b00100000 // 5 5 freeze frequency compensation until CS goes high (default)
#define RADIOLIB_CC1101_FOC_PRE_K 0b00000000 // 4 3 frequency compensation loop gain before sync word: K
#define RADIOLIB_CC1101_FOC_PRE_2K 0b00001000 // 4 3 2K
#define RADIOLIB_CC1101_FOC_PRE_3K 0b00010000 // 4 3 3K (default)
#define RADIOLIB_CC1101_FOC_PRE_4K 0b00011000 // 4 3 4K
#define RADIOLIB_CC1101_FOC_POST_K 0b00000000 // 2 2 frequency compensation loop gain after sync word: same as FOC_PRE
#define RADIOLIB_CC1101_FOC_POST_K_2 0b00000100 // 2 2 K/2 (default)
#define RADIOLIB_CC1101_FOC_LIMIT_NO_COMPENSATION 0b00000000 // 1 0 frequency compensation saturation point: no compensation - required for ASK/OOK
#define RADIOLIB_CC1101_FOC_LIMIT_BW_CHAN_8 0b00000001 // 1 0 +- BW_chan/8
#define RADIOLIB_CC1101_FOC_LIMIT_BW_CHAN_4 0b00000010 // 1 0 +- BW_chan/4 (default)
#define RADIOLIB_CC1101_FOC_LIMIT_BW_CHAN_2 0b00000011 // 1 0 +- BW_chan/2
// CC1101_REG_BSCFG
#define RADIOLIB_CC1101_BS_PRE_KI 0b00000000 // 7 6 clock recovery integral gain before sync word: Ki
#define RADIOLIB_CC1101_BS_PRE_2KI 0b01000000 // 7 6 2Ki (default)
#define RADIOLIB_CC1101_BS_PRE_3KI 0b10000000 // 7 6 3Ki
#define RADIOLIB_CC1101_BS_PRE_4KI 0b11000000 // 7 6 4Ki
#define RADIOLIB_CC1101_BS_PRE_KP 0b00000000 // 5 4 clock recovery proportional gain before sync word: Kp
#define RADIOLIB_CC1101_BS_PRE_2KP 0b00010000 // 5 4 2Kp
#define RADIOLIB_CC1101_BS_PRE_3KP 0b00100000 // 5 4 3Kp (default)
#define RADIOLIB_CC1101_BS_PRE_4KP 0b00110000 // 5 4 4Kp
#define RADIOLIB_CC1101_BS_POST_KI 0b00000000 // 3 3 clock recovery integral gain after sync word: same as BS_PRE
#define RADIOLIB_CC1101_BS_POST_KI_2 0b00001000 // 3 3 Ki/2 (default)
#define RADIOLIB_CC1101_BS_POST_KP 0b00000000 // 2 2 clock recovery proportional gain after sync word: same as BS_PRE
#define RADIOLIB_CC1101_BS_POST_KP_1 0b00000100 // 2 2 Kp (default)
#define RADIOLIB_CC1101_BS_LIMIT_NO_COMPENSATION 0b00000000 // 1 0 data rate compensation saturation point: no compensation
#define RADIOLIB_CC1101_BS_LIMIT_3_125 0b00000001 // 1 0 +- 3.125 %
#define RADIOLIB_CC1101_BS_LIMIT_6_25 0b00000010 // 1 0 +- 6.25 %
#define RADIOLIB_CC1101_BS_LIMIT_12_5 0b00000011 // 1 0 +- 12.5 %
// CC1101_REG_AGCCTRL2
#define RADIOLIB_CC1101_MAX_DVGA_GAIN_0 0b00000000 // 7 6 reduce maximum available DVGA gain: no reduction (default)
#define RADIOLIB_CC1101_MAX_DVGA_GAIN_1 0b01000000 // 7 6 disable top gain setting
#define RADIOLIB_CC1101_MAX_DVGA_GAIN_2 0b10000000 // 7 6 disable top two gain setting
#define RADIOLIB_CC1101_MAX_DVGA_GAIN_3 0b11000000 // 7 6 disable top three gain setting
#define RADIOLIB_CC1101_LNA_GAIN_REDUCE_0_DB 0b00000000 // 5 3 reduce maximum LNA gain by: 0 dB (default)
#define RADIOLIB_CC1101_LNA_GAIN_REDUCE_2_6_DB 0b00001000 // 5 3 2.6 dB
#define RADIOLIB_CC1101_LNA_GAIN_REDUCE_6_1_DB 0b00010000 // 5 3 6.1 dB
#define RADIOLIB_CC1101_LNA_GAIN_REDUCE_7_4_DB 0b00011000 // 5 3 7.4 dB
#define RADIOLIB_CC1101_LNA_GAIN_REDUCE_9_2_DB 0b00100000 // 5 3 9.2 dB
#define RADIOLIB_CC1101_LNA_GAIN_REDUCE_11_5_DB 0b00101000 // 5 3 11.5 dB
#define RADIOLIB_CC1101_LNA_GAIN_REDUCE_14_6_DB 0b00110000 // 5 3 14.6 dB
#define RADIOLIB_CC1101_LNA_GAIN_REDUCE_17_1_DB 0b00111000 // 5 3 17.1 dB
#define RADIOLIB_CC1101_MAGN_TARGET_24_DB 0b00000000 // 2 0 average amplitude target for filter: 24 dB
#define RADIOLIB_CC1101_MAGN_TARGET_27_DB 0b00000001 // 2 0 27 dB
#define RADIOLIB_CC1101_MAGN_TARGET_30_DB 0b00000010 // 2 0 30 dB
#define RADIOLIB_CC1101_MAGN_TARGET_33_DB 0b00000011 // 2 0 33 dB (default)
#define RADIOLIB_CC1101_MAGN_TARGET_36_DB 0b00000100 // 2 0 36 dB
#define RADIOLIB_CC1101_MAGN_TARGET_38_DB 0b00000101 // 2 0 38 dB
#define RADIOLIB_CC1101_MAGN_TARGET_40_DB 0b00000110 // 2 0 40 dB
#define RADIOLIB_CC1101_MAGN_TARGET_42_DB 0b00000111 // 2 0 42 dB
// CC1101_REG_AGCCTRL1
#define RADIOLIB_CC1101_AGC_LNA_PRIORITY_LNA2 0b00000000 // 6 6 LNA priority setting: LNA2 first
#define RADIOLIB_CC1101_AGC_LNA_PRIORITY_LNA 0b01000000 // 6 6 LNA first (default)
#define RADIOLIB_CC1101_CARRIER_SENSE_REL_THR_OFF 0b00000000 // 5 4 RSSI relative change to assert carrier sense: disabled (default)
#define RADIOLIB_CC1101_CARRIER_SENSE_REL_THR_6_DB 0b00010000 // 5 4 6 dB
#define RADIOLIB_CC1101_CARRIER_SENSE_REL_THR_10_DB 0b00100000 // 5 4 10 dB
#define RADIOLIB_CC1101_CARRIER_SENSE_REL_THR_14_DB 0b00110000 // 5 4 14 dB
#define RADIOLIB_CC1101_CARRIER_SENSE_ABS_THR 0x00 // 3 0 RSSI threshold to assert carrier sense in 2s compliment, Thr = MAGN_TARGET + CARRIER_SENSE_ABS_TH [dB]
// CC1101_REG_AGCCTRL0
#define RADIOLIB_CC1101_HYST_LEVEL_NONE 0b00000000 // 7 6 AGC hysteresis level: none
#define RADIOLIB_CC1101_HYST_LEVEL_LOW 0b01000000 // 7 6 low
#define RADIOLIB_CC1101_HYST_LEVEL_MEDIUM 0b10000000 // 7 6 medium (default)
#define RADIOLIB_CC1101_HYST_LEVEL_HIGH 0b11000000 // 7 6 high
#define RADIOLIB_CC1101_WAIT_TIME_8_SAMPLES 0b00000000 // 5 4 AGC wait time: 8 samples
#define RADIOLIB_CC1101_WAIT_TIME_16_SAMPLES 0b00010000 // 5 4 16 samples (default)
#define RADIOLIB_CC1101_WAIT_TIME_24_SAMPLES 0b00100000 // 5 4 24 samples
#define RADIOLIB_CC1101_WAIT_TIME_32_SAMPLES 0b00110000 // 5 4 32 samples
#define RADIOLIB_CC1101_AGC_FREEZE_NEVER 0b00000000 // 3 2 freeze AGC gain: never (default)
#define RADIOLIB_CC1101_AGC_FREEZE_SYNC_WORD 0b00000100 // 3 2 when sync word is found
#define RADIOLIB_CC1101_AGC_FREEZE_MANUAL_A 0b00001000 // 3 2 manually freeze analog control
#define RADIOLIB_CC1101_AGC_FREEZE_MANUAL_AD 0b00001100 // 3 2 manually freeze analog and digital control
#define RADIOLIB_CC1101_FILTER_LENGTH_8 0b00000000 // 1 0 averaging length for channel filter: 8 samples
#define RADIOLIB_CC1101_FILTER_LENGTH_16 0b00000001 // 1 0 16 samples (default)
#define RADIOLIB_CC1101_FILTER_LENGTH_32 0b00000010 // 1 0 32 samples
#define RADIOLIB_CC1101_FILTER_LENGTH_64 0b00000011 // 1 0 64 samples
#define RADIOLIB_CC1101_ASK_OOK_BOUNDARY_4_DB 0b00000000 // 1 0 ASK/OOK decision boundary: 4 dB
#define RADIOLIB_CC1101_ASK_OOK_BOUNDARY_8_DB 0b00000001 // 1 0 8 dB (default)
#define RADIOLIB_CC1101_ASK_OOK_BOUNDARY_12_DB 0b00000010 // 1 0 12 dB
#define RADIOLIB_CC1101_ASK_OOK_BOUNDARY_16_DB 0b00000011 // 1 0 16 dB
// CC1101_REG_WOREVT1 + REG_WOREVT0
#define RADIOLIB_CC1101_EVENT0_TIMEOUT_MSB 0x87 // 7 0 EVENT0 timeout: t_event0 = (750 / f(XOSC)) * EVENT0_TIMEOUT * 2^(5 * WOR_RES) [s]
#define RADIOLIB_CC1101_EVENT0_TIMEOUT_LSB 0x6B // 7 0 default value for 26 MHz crystal: 1.0 s
// CC1101_REG_WORCTRL
#define RADIOLIB_CC1101_RC_POWER_UP 0b00000000 // 7 7 power up RC oscillator
#define RADIOLIB_CC1101_RC_POWER_DOWN 0b10000000 // 7 7 power down RC oscillator
#define RADIOLIB_CC1101_EVENT1_TIMEOUT_4 0b00000000 // 6 4 EVENT1 timeout: 4 RC periods
#define RADIOLIB_CC1101_EVENT1_TIMEOUT_6 0b00010000 // 6 4 6 RC periods
#define RADIOLIB_CC1101_EVENT1_TIMEOUT_8 0b00100000 // 6 4 8 RC periods
#define RADIOLIB_CC1101_EVENT1_TIMEOUT_12 0b00110000 // 6 4 12 RC periods
#define RADIOLIB_CC1101_EVENT1_TIMEOUT_16 0b01000000 // 6 4 16 RC periods
#define RADIOLIB_CC1101_EVENT1_TIMEOUT_24 0b01010000 // 6 4 24 RC periods
#define RADIOLIB_CC1101_EVENT1_TIMEOUT_32 0b01100000 // 6 4 32 RC periods
#define RADIOLIB_CC1101_EVENT1_TIMEOUT_48 0b01110000 // 6 4 48 RC periods (default)
#define RADIOLIB_CC1101_RC_CAL_OFF 0b00000000 // 3 3 disable RC oscillator calibration
#define RADIOLIB_CC1101_RC_CAL_ON 0b00001000 // 3 3 enable RC oscillator calibration (default)
#define RADIOLIB_CC1101_WOR_RES_1 0b00000000 // 1 0 EVENT0 resolution: 1 period (default)
#define RADIOLIB_CC1101_WOR_RES_2_5 0b00000001 // 1 0 2^5 periods
#define RADIOLIB_CC1101_WOR_RES_2_10 0b00000010 // 1 0 2^10 periods
#define RADIOLIB_CC1101_WOR_RES_2_15 0b00000011 // 1 0 2^15 periods
// CC1101_REG_FREND1
#define RADIOLIB_CC1101_LNA_CURRENT 0x01 // 7 6 front-end LNA PTAT current output adjustment
#define RADIOLIB_CC1101_LNA2MIX_CURRENT 0x01 // 5 4 front-end PTAT output adjustment
#define RADIOLIB_CC1101_LODIV_BUF_CURRENT_RX 0x01 // 3 2 Rx LO buffer current adjustment
#define RADIOLIB_CC1101_MIX_CURRENT 0x02 // 1 0 mixer current adjustment
// CC1101_REG_FREND0
#define RADIOLIB_CC1101_LODIV_BUF_CURRENT_TX 0x01 // 5 4 Tx LO buffer current adjustment
#define RADIOLIB_CC1101_PA_POWER 0x00 // 2 0 set power amplifier power according to PATABLE
// CC1101_REG_FSCAL3
#define RADIOLIB_CC1101_CHP_CURR_CAL_OFF 0b00000000 // 5 4 disable charge pump calibration
#define RADIOLIB_CC1101_CHP_CURR_CAL_ON 0b00100000 // 5 4 enable charge pump calibration (default)
#define RADIOLIB_CC1101_FSCAL3 0x09 // 3 0 charge pump output current: I_out = I_0 * 2^(FSCAL3/4) [A]
// CC1101_REG_FSCAL2
#define RADIOLIB_CC1101_VCO_CORE_LOW 0b00000000 // 5 5 VCO: low (default)
#define RADIOLIB_CC1101_VCO_CORE_HIGH 0b00100000 // 5 5 high
#define RADIOLIB_CC1101_FSCAL2 0x0A // 4 0 VCO current result/override
// CC1101_REG_FSCAL1
#define RADIOLIB_CC1101_FSCAL1 0x20 // 5 0 capacitor array setting for coarse VCO tuning
// CC1101_REG_FSCAL0
#define RADIOLIB_CC1101_FSCAL0 0x0D // 6 0 frequency synthesizer calibration setting
// CC1101_REG_RCCTRL1
#define RADIOLIB_CC1101_RCCTRL1 0x41 // 6 0 RC oscillator configuration
// CC1101_REG_RCCTRL0
#define RADIOLIB_CC1101_RCCTRL0 0x00 // 6 0 RC oscillator configuration
// CC1101_REG_PTEST
#define RADIOLIB_CC1101_TEMP_SENS_IDLE_OFF 0x7F // 7 0 temperature sensor will not be available in idle mode (default)
#define RADIOLIB_CC1101_TEMP_SENS_IDLE_ON 0xBF // 7 0 temperature sensor will be available in idle mode
// CC1101_REG_TEST0
#define RADIOLIB_CC1101_VCO_SEL_CAL_OFF 0b00000000 // 1 1 disable VCO selection calibration stage
#define RADIOLIB_CC1101_VCO_SEL_CAL_ON 0b00000010 // 1 1 enable VCO selection calibration stage
// CC1101_REG_PARTNUM
#define RADIOLIB_CC1101_PARTNUM 0x00
// CC1101_REG_VERSION
#define RADIOLIB_CC1101_VERSION_CURRENT 0x14
#define RADIOLIB_CC1101_VERSION_LEGACY 0x04
#define RADIOLIB_CC1101_VERSION_CLONE 0x17
// CC1101_REG_MARCSTATE
#define RADIOLIB_CC1101_MARC_STATE_SLEEP 0x00 // 4 0 main radio control state: sleep
#define RADIOLIB_CC1101_MARC_STATE_IDLE 0x01 // 4 0 idle
#define RADIOLIB_CC1101_MARC_STATE_XOFF 0x02 // 4 0 XOFF
#define RADIOLIB_CC1101_MARC_STATE_VCOON_MC 0x03 // 4 0 VCOON_MC
#define RADIOLIB_CC1101_MARC_STATE_REGON_MC 0x04 // 4 0 REGON_MC
#define RADIOLIB_CC1101_MARC_STATE_MANCAL 0x05 // 4 0 MANCAL
#define RADIOLIB_CC1101_MARC_STATE_VCOON 0x06 // 4 0 VCOON
#define RADIOLIB_CC1101_MARC_STATE_REGON 0x07 // 4 0 REGON
#define RADIOLIB_CC1101_MARC_STATE_STARTCAL 0x08 // 4 0 STARTCAL
#define RADIOLIB_CC1101_MARC_STATE_BWBOOST 0x09 // 4 0 BWBOOST
#define RADIOLIB_CC1101_MARC_STATE_FS_LOCK 0x0A // 4 0 FS_LOCK
#define RADIOLIB_CC1101_MARC_STATE_IFADCON 0x0B // 4 0 IFADCON
#define RADIOLIB_CC1101_MARC_STATE_ENDCAL 0x0C // 4 0 ENDCAL
#define RADIOLIB_CC1101_MARC_STATE_RX 0x0D // 4 0 RX
#define RADIOLIB_CC1101_MARC_STATE_RX_END 0x0E // 4 0 RX_END
#define RADIOLIB_CC1101_MARC_STATE_RX_RST 0x0F // 4 0 RX_RST
#define RADIOLIB_CC1101_MARC_STATE_TXRX_SWITCH 0x10 // 4 0 TXRX_SWITCH
#define RADIOLIB_CC1101_MARC_STATE_RXFIFO_OVERFLOW 0x11 // 4 0 RXFIFO_OVERFLOW
#define RADIOLIB_CC1101_MARC_STATE_FSTXON 0x12 // 4 0 FSTXON
#define RADIOLIB_CC1101_MARC_STATE_TX 0x13 // 4 0 TX
#define RADIOLIB_CC1101_MARC_STATE_TX_END 0x14 // 4 0 TX_END
#define RADIOLIB_CC1101_MARC_STATE_RXTX_SWITCH 0x15 // 4 0 RXTX_SWITCH
#define RADIOLIB_CC1101_MARC_STATE_TXFIFO_UNDERFLOW 0x16 // 4 0 TXFIFO_UNDERFLOW
// CC1101_REG_WORTIME1 + REG_WORTIME0
#define RADIOLIB_CC1101_WORTIME_MSB 0x00 // 7 0 WOR timer value
#define RADIOLIB_CC1101_WORTIME_LSB 0x00 // 7 0
// CC1101_REG_PKTSTATUS
#define RADIOLIB_CC1101_CRC_OK 0b10000000 // 7 7 CRC check passed
#define RADIOLIB_CC1101_CRC_ERROR 0b00000000 // 7 7 CRC check failed
#define RADIOLIB_CC1101_CS 0b01000000 // 6 6 carrier sense
#define RADIOLIB_CC1101_PQT_REACHED 0b00100000 // 5 5 preamble quality reached
#define RADIOLIB_CC1101_CCA 0b00010000 // 4 4 channel clear
#define RADIOLIB_CC1101_SFD 0b00001000 // 3 3 start of frame delimiter - sync word received
#define RADIOLIB_CC1101_GDO2_ACTIVE 0b00000100 // 2 2 GDO2 is active/asserted
#define RADIOLIB_CC1101_GDO0_ACTIVE 0b00000001 // 0 0 GDO0 is active/asserted
/*!
\class CC1101
\brief Control class for %CC1101 module.
*/
class CC1101: public PhysicalLayer {
public:
// introduce PhysicalLayer overloads
using PhysicalLayer::transmit;
using PhysicalLayer::receive;
using PhysicalLayer::startTransmit;
using PhysicalLayer::readData;
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
CC1101(Module* module);
Module* getMod();
// basic methods
/*!
\brief Initialization method.
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
\param br Bit rate to be used in kbps. Defaults to 48.0 kbps.
\param freqDev Frequency deviation from carrier frequency in kHz Defaults to 48.0 kHz.
\param rxBw Receiver bandwidth in kHz. Defaults to 135.0 kHz.
\param power Output power in dBm. Defaults to 10 dBm.
\param preambleLength Preamble Length in bits. Defaults to 16 bits.
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 48.0, float rxBw = 135.0, int8_t power = 10, uint8_t preambleLength = 16);
/*!
\brief Blocking binary transmit method.
Overloads for string-based transmissions are implemented in PhysicalLayer.
\param data Binary data to be sent.
\param len Number of bytes to send.
\param addr Address to send the data to. Will only be added if address filtering was enabled.
\returns \ref status_codes
*/
int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
/*!
\brief Blocking binary receive method.
Overloads for string-based transmissions are implemented in PhysicalLayer.
\param data Binary data to be sent.
\param len Number of bytes to send.
\returns \ref status_codes
*/
int16_t receive(uint8_t* data, size_t len) override;
/*!
\brief Sets the module to standby mode.
\returns \ref status_codes
*/
int16_t standby() override;
/*!
\brief Starts direct mode transmission.
\param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY.
\returns \ref status_codes
*/
int16_t transmitDirect(uint32_t frf = 0) override;
/*!
\brief Starts direct mode reception.
\returns \ref status_codes
*/
int16_t receiveDirect() override;
/*!
\brief Stops direct mode. It is required to call this method to switch from direct transmissions to packet-based transmissions.
*/
int16_t packetMode();
// interrupt methods
/*!
\brief Sets interrupt service routine to call when GDO0 activates.
\param func ISR to call.
\param dir Signal change direction. Defaults to RISING.
*/
void setGdo0Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir = RISING);
/*!
\brief Clears interrupt service routine to call when GDO0 activates.
*/
void clearGdo0Action();
/*!
\brief Sets interrupt service routine to call when GDO2 activates.
\param func ISR to call.
\param dir Signal change direction. Defaults to FALLING.
*/
void setGdo2Action(void (*func)(void), RADIOLIB_INTERRUPT_STATUS dir = FALLING);
/*!
\brief Clears interrupt service routine to call when GDO0 activates.
*/
void clearGdo2Action();
/*!
\brief Interrupt-driven binary transmit method.
Overloads for string-based transmissions are implemented in PhysicalLayer.
\param data Binary data to be sent.
\param len Number of bytes to send.
\param addr Address to send the data to. Will only be added if address filtering was enabled.
\returns \ref status_codes
*/
int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
/*!
\brief Interrupt-driven receive method. GDO0 will be activated when full packet is received.
\returns \ref status_codes
*/
int16_t startReceive();
/*!
\brief Reads data received after calling startReceive method.
\param data Pointer to array to save the received binary data.
\param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically.
When more bytes than received are requested, only the number of bytes requested will be returned.
\returns \ref status_codes
*/
int16_t readData(uint8_t* data, size_t len) override;
// configuration methods
/*!
\brief Sets carrier frequency. Allowed values are in bands 300.0 to 348.0 MHz, 387.0 to 464.0 MHz and 779.0 to 928.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
/*!
\brief Sets bit rate. Allowed values range from 0.025 to 600.0 kbps.
\param br Bit rate to be set in kbps.
\returns \ref status_codes
*/
int16_t setBitRate(float br);
/*!
\brief Sets receiver bandwidth. Allowed values range from 58.0 to 812.0 kHz.
\param rxBw Receiver bandwidth to be set in kHz.
\returns \ref status_codes
*/
int16_t setRxBandwidth(float rxBw);
/*!
\brief Sets frequency deviation. Allowed values range from 1.587 to 380.8 kHz.
\param freqDev Frequency deviation to be set in kHz.
\returns \ref status_codes
*/
int16_t setFrequencyDeviation(float freqDev) override;
/*!
\brief Sets output power. Allowed values are -30, -20, -15, -10, 0, 5, 7 or 10 dBm.
\param power Output power to be set in dBm.
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power);
/*!
\brief Sets 16-bit sync word as a two byte value.
\param syncH MSB of the sync word.
\param syncL LSB of the sync word.
\param maxErrBits Maximum allowed number of bit errors in received sync word. Defaults to 0.
\param requireCarrierSense Require carrier sense above threshold in addition to sync word.
\returns \ref status_codes
*/
int16_t setSyncWord(uint8_t syncH, uint8_t syncL, uint8_t maxErrBits = 0, bool requireCarrierSense = false);
/*!
\brief Sets 1 or 2 bytes of sync word.
\param syncWord Pointer to the array of sync word bytes.
\param len Sync word length in bytes.
\param maxErrBits Maximum allowed number of bit errors in received sync word. Defaults to 0.
\param requireCarrierSense Require carrier sense above threshold in addition to sync word.
\returns \ref status_codes
*/
int16_t setSyncWord(uint8_t* syncWord, uint8_t len, uint8_t maxErrBits = 0, bool requireCarrierSense = false);
/*!
\brief Sets preamble length.
\param preambleLength Preamble length to be set (in bits), allowed values: 16, 24, 32, 48, 64, 96, 128 and 192.
\returns \ref status_codes
*/
int16_t setPreambleLength(uint8_t preambleLength);
/*!
\brief Sets node and broadcast addresses. Calling this method will also enable address filtering.
\param nodeAddr Node address to be set.
\param numBroadcastAddrs Number of broadcast addresses to be used. Can be set to 0 (no broadcast), 1 (broadcast at 0x00) or 2 (broadcast at 0x00 and 0xFF).
\returns \ref status_codes
*/
int16_t setNodeAddress(uint8_t nodeAddr, uint8_t numBroadcastAddrs = 0);
/*!
\brief Disables address filtering. Calling this method will also erase previously set addresses.
\returns \ref status_codes
*/
int16_t disableAddressFiltering();
/*!
\brief Enables/disables OOK modulation instead of FSK.
\param enableOOK Enable (true) or disable (false) OOK.
\returns \ref status_codes
*/
int16_t setOOK(bool enableOOK);
/*!
\brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
\returns Last packet RSSI in dBm.
*/
float getRSSI() const;
/*!
\brief Gets LQI (Link Quality Indicator) of the last received packet.
\returns Last packet LQI (lower is better).
*/
uint8_t getLQI() const;
/*!
\brief Query modem for the packet length of received payload.
\param update Update received packet length. Will return cached value when set to false.
\returns Length of last received packet in bytes.
*/
size_t getPacketLength(bool update = true) override;
/*!
\brief Set modem in fixed packet length mode.
\param len Packet length.
\returns \ref status_codes
*/
int16_t fixedPacketLengthMode(uint8_t len = RADIOLIB_CC1101_MAX_PACKET_LENGTH);
/*!
\brief Set modem in variable packet length mode.
\param len Maximum packet length.
\returns \ref status_codes
*/
int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_CC1101_MAX_PACKET_LENGTH);
/*!
\brief Enable sync word filtering and generation.
\param numBits Sync word length in bits.
\param requireCarrierSense Require carrier sense above threshold in addition to sync word.
\returns \ref status_codes
*/
int16_t enableSyncWordFiltering(uint8_t maxErrBits = 0, bool requireCarrierSense = false);
/*!
\brief Disable preamble and sync word filtering and generation.
\param requireCarrierSense Require carrier sense above threshold.
\returns \ref status_codes
*/
int16_t disableSyncWordFiltering(bool requireCarrierSense = false);
/*!
\brief Enable CRC filtering and generation.
\param crcOn Set or unset promiscuous mode.
\returns \ref status_codes
*/
int16_t setCrcFiltering(bool crcOn = true);
/*!
\brief Set modem in "sniff" mode: no packet filtering (e.g., no preamble, sync word, address, CRC).
\param promiscuous Set or unset promiscuous mode.
\returns \ref status_codes
*/
int16_t setPromiscuousMode(bool promiscuous = true);
/*!
\brief Get whether the modem is in promiscuous mode: no packet filtering (e.g., no preamble, sync word, address, CRC).
\returns Whether the modem is in promiscuous mode
*/
bool getPromiscuousMode();
/*!
\brief Sets Gaussian filter bandwidth-time product that will be used for data shaping.
Allowed value is RADIOLIB_SHAPING_0_5. Set to RADIOLIB_SHAPING_NONE to disable data shaping.
\param sh Gaussian shaping bandwidth-time product that will be used for data shaping.
\returns \ref status_codes
*/
int16_t setDataShaping(uint8_t sh) override;
/*!
\brief Sets transmission encoding. Allowed values are RADIOLIB_ENCODING_NRZ and RADIOLIB_ENCODING_WHITENING.
\param encoding Encoding to be used.
\returns \ref status_codes
*/
int16_t setEncoding(uint8_t encoding) override;
/*!
\brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state.
When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch!
\param rxEn RX enable pin.
\param txEn TX enable pin.
*/
void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn);
/*!
\brief Get one truly random byte from RSSI noise.
\returns TRNG byte.
*/
uint8_t randomByte();
/*!
\brief Read version SPI register. Should return CC1101_VERSION_LEGACY (0x04) or CC1101_VERSION_CURRENT (0x14) if CC1101 is connected and working.
\returns Version register contents or \ref status_codes
*/
int16_t getChipVersion();
/*!
\brief Set interrupt service routine function to call when data bit is receveid in direct mode.
\param func Pointer to interrupt service routine.
*/
void setDirectAction(void (*func)(void));
/*!
\brief Function to read and process data bit in direct reception mode.
\param pin Pin on which to read.
*/
void readBit(RADIOLIB_PIN_TYPE pin);
#if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
protected:
#endif
Module* _mod;
// SPI read overrides to set bit for burst write and status registers access
int16_t SPIgetRegValue(uint8_t reg, uint8_t msb = 7, uint8_t lsb = 0);
int16_t SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb = 7, uint8_t lsb = 0, uint8_t checkInterval = 2);
void SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes);
uint8_t SPIreadRegister(uint8_t reg);
void SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, size_t len);
void SPIwriteRegister(uint8_t reg, uint8_t data);
void SPIsendCommand(uint8_t cmd);
#if !defined(RADIOLIB_GODMODE)
protected:
#endif
float _freq = 0;
float _br = 0;
uint8_t _rawRSSI = 0;
uint8_t _rawLQI = 0;
uint8_t _modulation = RADIOLIB_CC1101_MOD_FORMAT_2_FSK;
size_t _packetLength = 0;
bool _packetLengthQueried = false;
uint8_t _packetLengthConfig = RADIOLIB_CC1101_LENGTH_CONFIG_VARIABLE;
bool _promiscuous = false;
bool _crcOn = true;
uint8_t _syncWordLength = 2;
int8_t _power = 0;
int16_t config();
int16_t directMode();
static void getExpMant(float target, uint16_t mantOffset, uint8_t divExp, uint8_t expMax, uint8_t& exp, uint8_t& mant);
int16_t setPacketMode(uint8_t mode, uint16_t len);
};
#endif

View File

@ -0,0 +1,31 @@
#include "LLCC68.h"
#if !defined(RADIOLIB_EXCLUDE_SX126X)
LLCC68::LLCC68(Module* mod) : SX1262(mod) {
}
int16_t LLCC68::setBandwidth(float bw) {
RADIOLIB_CHECK_RANGE(bw, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
return(SX1262::setBandwidth(bw));
}
int16_t LLCC68::setSpreadingFactor(uint8_t sf) {
switch(SX126x::_bw) {
case RADIOLIB_SX126X_LORA_BW_125_0:
RADIOLIB_CHECK_RANGE(sf, 5, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
break;
case RADIOLIB_SX126X_LORA_BW_250_0:
RADIOLIB_CHECK_RANGE(sf, 5, 10, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
break;
case RADIOLIB_SX126X_LORA_BW_500_0:
RADIOLIB_CHECK_RANGE(sf, 5, 11, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
break;
default:
return(RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
}
return(SX1262::setSpreadingFactor(sf));
}
#endif

View File

@ -0,0 +1,53 @@
#if !defined(_RADIOLIB_LLCC68_H)
#define _RADIOLIB_LLCC68_H
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_SX126X)
#include "../../Module.h"
#include "../SX126x/SX1262.h"
/*!
\class LLCC68
\brief Derived class for %LLCC68 modules.
*/
class LLCC68: public SX1262 {
public:
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
LLCC68(Module* mod);
// configuration methods
/*!
\brief Sets LoRa bandwidth. Allowed values are 125.0, 250.0 and 500.0 kHz.
\param bw LoRa bandwidth to be set in kHz.
\returns \ref status_codes
*/
int16_t setBandwidth(float bw);
/*!
\brief Sets LoRa spreading factor. Allowed values range from 5 to 11, depending on currently set spreading factor.
\param sf LoRa spreading factor to be set.
\returns \ref status_codes
*/
int16_t setSpreadingFactor(uint8_t sf);
#if !defined(RADIOLIB_GODMODE)
private:
#endif
};
#endif
#endif

View File

@ -0,0 +1,953 @@
#include "RF69.h"
#if !defined(RADIOLIB_EXCLUDE_RF69)
RF69::RF69(Module* module) : PhysicalLayer(RADIOLIB_RF69_FREQUENCY_STEP_SIZE, RADIOLIB_RF69_MAX_PACKET_LENGTH) {
_mod = module;
}
Module* RF69::getMod() {
return(_mod);
}
int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) {
// set module properties
_mod->init();
_mod->pinMode(_mod->getIrq(), INPUT);
// try to find the RF69 chip
uint8_t i = 0;
bool flagFound = false;
while((i < 10) && !flagFound) {
// reset the module
reset();
// check version register
int16_t version = getChipVersion();
if(version == RADIOLIB_RF69_CHIP_VERSION) {
flagFound = true;
} else {
#if defined(RADIOLIB_DEBUG)
RADIOLIB_DEBUG_PRINT(F("RF69 not found! ("));
RADIOLIB_DEBUG_PRINT(i + 1);
RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RADIOLIB_RF69_REG_VERSION == "));
char buffHex[7];
sprintf(buffHex, "0x%04X", version);
RADIOLIB_DEBUG_PRINT(buffHex);
RADIOLIB_DEBUG_PRINT(F(", expected 0x0024"));
RADIOLIB_DEBUG_PRINTLN();
#endif
_mod->delay(10);
i++;
}
}
if(!flagFound) {
RADIOLIB_DEBUG_PRINTLN(F("No RF69 found!"));
_mod->term();
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
} else {
RADIOLIB_DEBUG_PRINTLN(F("M\tRF69"));
}
// configure settings not accessible by API
int16_t state = config();
RADIOLIB_ASSERT(state);
// configure publicly accessible settings
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
// configure bitrate
_rxBw = 125.0;
state = setBitRate(br);
RADIOLIB_ASSERT(state);
// configure default RX bandwidth
state = setRxBandwidth(rxBw);
RADIOLIB_ASSERT(state);
// configure default frequency deviation
state = setFrequencyDeviation(freqDev);
RADIOLIB_ASSERT(state);
// configure default TX output power
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
// configure default preamble length
state = setPreambleLength(preambleLen);
RADIOLIB_ASSERT(state);
// set default packet length mode
state = variablePacketLengthMode();
RADIOLIB_ASSERT(state);
// set default sync word
uint8_t syncWord[] = {0x12, 0xAD};
state = setSyncWord(syncWord, sizeof(syncWord));
RADIOLIB_ASSERT(state);
// set default data shaping
state = setDataShaping(RADIOLIB_SHAPING_NONE);
RADIOLIB_ASSERT(state);
// set default encoding
state = setEncoding(RADIOLIB_ENCODING_NRZ);
RADIOLIB_ASSERT(state);
// set CRC on by default
state = setCrcFiltering(true);
RADIOLIB_ASSERT(state);
return(state);
}
void RF69::reset() {
_mod->pinMode(_mod->getRst(), OUTPUT);
_mod->digitalWrite(_mod->getRst(), HIGH);
_mod->delay(1);
_mod->digitalWrite(_mod->getRst(), LOW);
_mod->delay(10);
}
int16_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) {
// calculate timeout (5ms + 500 % of expected time-on-air)
uint32_t timeout = 5000000 + (uint32_t)((((float)(len * 8)) / (_br * 1000.0)) * 5000000.0);
// start transmission
int16_t state = startTransmit(data, len, addr);
RADIOLIB_ASSERT(state);
// wait for transmission end or timeout
uint32_t start = _mod->micros();
while(!_mod->digitalRead(_mod->getIrq())) {
_mod->yield();
if(_mod->micros() - start > timeout) {
standby();
clearIRQFlags();
return(RADIOLIB_ERR_TX_TIMEOUT);
}
}
// set mode to standby
standby();
// clear interrupt flags
clearIRQFlags();
return(RADIOLIB_ERR_NONE);
}
int16_t RF69::receive(uint8_t* data, size_t len) {
// calculate timeout (500 ms + 400 full 64-byte packets at current bit rate)
uint32_t timeout = 500000 + (1.0/(_br*1000.0))*(RADIOLIB_RF69_MAX_PACKET_LENGTH*400.0);
// start reception
int16_t state = startReceive();
RADIOLIB_ASSERT(state);
// wait for packet reception or timeout
uint32_t start = _mod->micros();
while(!_mod->digitalRead(_mod->getIrq())) {
_mod->yield();
if(_mod->micros() - start > timeout) {
standby();
clearIRQFlags();
return(RADIOLIB_ERR_RX_TIMEOUT);
}
}
// read packet data
return(readData(data, len));
}
int16_t RF69::sleep() {
// set RF switch (if present)
_mod->setRfSwitchState(LOW, LOW);
// set module to sleep
return(setMode(RADIOLIB_RF69_SLEEP));
}
int16_t RF69::standby() {
// set RF switch (if present)
_mod->setRfSwitchState(LOW, LOW);
// set module to standby
return(setMode(RADIOLIB_RF69_STANDBY));
}
int16_t RF69::transmitDirect(uint32_t frf) {
// set RF switch (if present)
_mod->setRfSwitchState(LOW, HIGH);
// user requested to start transmitting immediately (required for RTTY)
if(frf != 0) {
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MSB, (frf & 0xFF0000) >> 16);
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MID, (frf & 0x00FF00) >> 8);
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_LSB, frf & 0x0000FF);
return(setMode(RADIOLIB_RF69_TX));
}
// activate direct mode
int16_t state = directMode();
RADIOLIB_ASSERT(state);
// start transmitting
return(setMode(RADIOLIB_RF69_TX));
}
int16_t RF69::receiveDirect() {
// set RF switch (if present)
_mod->setRfSwitchState(HIGH, LOW);
// activate direct mode
int16_t state = directMode();
RADIOLIB_ASSERT(state);
// start receiving
return(setMode(RADIOLIB_RF69_RX));
}
int16_t RF69::directMode() {
// set mode to standby
int16_t state = setMode(RADIOLIB_RF69_STANDBY);
RADIOLIB_ASSERT(state);
// set DIO mapping
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO1_CONT_DCLK | RADIOLIB_RF69_DIO2_CONT_DATA, 5, 2);
RADIOLIB_ASSERT(state);
// set continuous mode
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE_WITH_SYNC, 6, 5));
}
int16_t RF69::packetMode() {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_PACKET_MODE, 6, 5));
}
void RF69::setAESKey(uint8_t* key) {
_mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_AES_KEY_1, key, 16);
}
int16_t RF69::enableAES() {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_AES_ON, 0, 0));
}
int16_t RF69::disableAES() {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_AES_OFF, 0, 0));
}
int16_t RF69::startReceive() {
// set mode to standby
int16_t state = setMode(RADIOLIB_RF69_STANDBY);
RADIOLIB_ASSERT(state);
// set RX timeouts and DIO pin mapping
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO0_PACK_PAYLOAD_READY, 7, 4);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_1, RADIOLIB_RF69_TIMEOUT_RX_START);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_2, RADIOLIB_RF69_TIMEOUT_RSSI_THRESH);
RADIOLIB_ASSERT(state);
// clear interrupt flags
clearIRQFlags();
// set RF switch (if present)
_mod->setRfSwitchState(HIGH, LOW);
// set mode to receive
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA1, RADIOLIB_RF69_PA1_NORMAL);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA2, RADIOLIB_RF69_PA2_NORMAL);
RADIOLIB_ASSERT(state);
state = setMode(RADIOLIB_RF69_RX);
return(state);
}
void RF69::setDio0Action(void (*func)(void)) {
_mod->attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, RISING);
}
void RF69::clearDio0Action() {
_mod->detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()));
}
void RF69::setDio1Action(void (*func)(void)) {
if(_mod->getGpio() == RADIOLIB_NC) {
return;
}
_mod->pinMode(_mod->getGpio(), INPUT);
_mod->attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getGpio()), func, RISING);
}
void RF69::clearDio1Action() {
if(_mod->getGpio() == RADIOLIB_NC) {
return;
}
_mod->detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getGpio()));
}
int16_t RF69::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
// check packet length
if(len > RADIOLIB_RF69_MAX_PACKET_LENGTH) {
return(RADIOLIB_ERR_PACKET_TOO_LONG);
}
// set mode to standby
int16_t state = setMode(RADIOLIB_RF69_STANDBY);
RADIOLIB_ASSERT(state);
// set DIO pin mapping
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO0_PACK_PACKET_SENT, 7, 6);
RADIOLIB_ASSERT(state);
// clear interrupt flags
clearIRQFlags();
// optionally write packet length
if (_packetLengthConfig == RADIOLIB_RF69_PACKET_FORMAT_VARIABLE) {
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FIFO, len);
}
// check address filtering
uint8_t filter = _mod->SPIgetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, 2, 1);
if((filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST)) {
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FIFO, addr);
}
// write packet to FIFO
_mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_FIFO, data, len);
// enable +20 dBm operation
if(_power > 17) {
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_OFF | 0x0F);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA1, RADIOLIB_RF69_PA1_20_DBM);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA2, RADIOLIB_RF69_PA2_20_DBM);
RADIOLIB_ASSERT(state);
}
// set RF switch (if present)
_mod->setRfSwitchState(LOW, HIGH);
// set mode to transmit
state = setMode(RADIOLIB_RF69_TX);
return(state);
}
int16_t RF69::readData(uint8_t* data, size_t len) {
// set mode to standby
int16_t state = standby();
RADIOLIB_ASSERT(state);
// get packet length
size_t length = getPacketLength();
size_t dumpLen = 0;
if((len != 0) && (len < length)) {
// user requested less data than we got, only return what was requested
dumpLen = length - len;
length = len;
}
// check address filtering
uint8_t filter = _mod->SPIgetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, 2, 1);
if((filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST)) {
_mod->SPIreadRegister(RADIOLIB_RF69_REG_FIFO);
}
// read packet data
_mod->SPIreadRegisterBurst(RADIOLIB_RF69_REG_FIFO, length, data);
// dump the bytes that weren't requested
if(dumpLen != 0) {
clearFIFO(dumpLen);
}
// clear internal flag so getPacketLength can return the new packet length
_packetLengthQueried = false;
// clear interrupt flags
clearIRQFlags();
return(RADIOLIB_ERR_NONE);
}
int16_t RF69::setOOK(bool enableOOK) {
// set OOK and if successful, save the new setting
int16_t state = RADIOLIB_ERR_NONE;
if(enableOOK) {
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_OOK, 4, 3, 5);
} else {
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK, 4, 3, 5);
}
if(state == RADIOLIB_ERR_NONE) {
_ook = enableOOK;
}
return(state);
}
int16_t RF69::setOokThresholdType(uint8_t type) {
if((type != RADIOLIB_RF69_OOK_THRESH_FIXED) && (type != RADIOLIB_RF69_OOK_THRESH_PEAK) && (type != RADIOLIB_RF69_OOK_THRESH_AVERAGE)) {
return(RADIOLIB_ERR_INVALID_OOK_RSSI_PEAK_TYPE);
}
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_OOK_PEAK, type, 7, 3, 5));
}
int16_t RF69::setOokFixedThreshold(uint8_t value) {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_OOK_FIX, value, 7, 0, 5));
}
int16_t RF69::setOokPeakThresholdDecrement(uint8_t value) {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_OOK_PEAK, value, 2, 0, 5));
}
int16_t RF69::setFrequency(float freq) {
// check allowed frequency range
if(!(((freq > 290.0) && (freq < 340.0)) ||
((freq > 431.0) && (freq < 510.0)) ||
((freq > 862.0) && (freq < 1020.0)))) {
return(RADIOLIB_ERR_INVALID_FREQUENCY);
}
// set mode to standby
setMode(RADIOLIB_RF69_STANDBY);
//set carrier frequency
uint32_t FRF = (freq * (uint32_t(1) << RADIOLIB_RF69_DIV_EXPONENT)) / RADIOLIB_RF69_CRYSTAL_FREQ;
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MSB, (FRF & 0xFF0000) >> 16);
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MID, (FRF & 0x00FF00) >> 8);
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_LSB, FRF & 0x0000FF);
_freq = freq;
return(RADIOLIB_ERR_NONE);
}
int16_t RF69::setBitRate(float br) {
RADIOLIB_CHECK_RANGE(br, 1.2, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
// check bitrate-bandwidth ratio
if(!(br < 2000 * _rxBw)) {
return(RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO);
}
// set mode to standby
setMode(RADIOLIB_RF69_STANDBY);
// set bit rate
uint16_t bitRate = 32000 / br;
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0);
if(state == RADIOLIB_ERR_NONE) {
RF69::_br = br;
}
return(state);
}
int16_t RF69::setRxBandwidth(float rxBw) {
// check bitrate-bandwidth ratio
if(!(_br < 2000 * rxBw)) {
return(RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO);
}
// check allowed bandwidth values
uint8_t bwMant, bwExp;
if(rxBw == 2.6) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_24;
bwExp = 7;
} else if(rxBw == 3.1) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_20;
bwExp = 7;
} else if(rxBw == 3.9) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_16;
bwExp = 7;
} else if(rxBw == 5.2) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_24;
bwExp = 6;
} else if(rxBw == 6.3) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_20;
bwExp = 6;
} else if(rxBw == 7.8) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_16;
bwExp = 6;
} else if(rxBw == 10.4) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_24;
bwExp = 5;
} else if(rxBw == 12.5) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_20;
bwExp = 5;
} else if(rxBw == 15.6) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_16;
bwExp = 5;
} else if(rxBw == 20.8) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_24;
bwExp = 4;
} else if(rxBw == 25.0) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_20;
bwExp = 4;
} else if(rxBw == 31.3) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_16;
bwExp = 4;
} else if(rxBw == 41.7) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_24;
bwExp = 3;
} else if(rxBw == 50.0) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_20;
bwExp = 3;
} else if(rxBw == 62.5) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_16;
bwExp = 3;
} else if(rxBw == 83.3) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_24;
bwExp = 2;
} else if(rxBw == 100.0) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_20;
bwExp = 2;
} else if(rxBw == 125.0) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_16;
bwExp = 2;
} else if(rxBw == 166.7) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_24;
bwExp = 1;
} else if(rxBw == 200.0) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_20;
bwExp = 1;
} else if(rxBw == 250.0) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_16;
bwExp = 1;
} else if(rxBw == 333.3) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_24;
bwExp = 0;
} else if(rxBw == 400.0) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_20;
bwExp = 0;
} else if(rxBw == 500.0) {
bwMant = RADIOLIB_RF69_RX_BW_MANT_16;
bwExp = 0;
} else {
return(RADIOLIB_ERR_INVALID_RX_BANDWIDTH);
}
// set mode to standby
setMode(RADIOLIB_RF69_STANDBY);
// set Rx bandwidth
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_BW, RADIOLIB_RF69_DCC_FREQ | bwMant | bwExp, 7, 0);
if(state == RADIOLIB_ERR_NONE) {
RF69::_rxBw = rxBw;
}
return(state);
}
int16_t RF69::setFrequencyDeviation(float freqDev) {
// set frequency deviation to lowest available setting (required for digimodes)
float newFreqDev = freqDev;
if(freqDev < 0.0) {
newFreqDev = 0.6;
}
// check frequency deviation range
if(!((newFreqDev + _br/2 <= 500))) {
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
}
// set mode to standby
setMode(RADIOLIB_RF69_STANDBY);
// set frequency deviation from carrier frequency
uint32_t base = 1;
uint32_t fdev = (newFreqDev * (base << 19)) / 32000;
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_FDEV_MSB, (fdev & 0xFF00) >> 8, 5, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_FDEV_LSB, fdev & 0x00FF, 7, 0);
return(state);
}
int16_t RF69::setOutputPower(int8_t power, bool highPower) {
if(highPower) {
RADIOLIB_CHECK_RANGE(power, -2, 20, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
} else {
RADIOLIB_CHECK_RANGE(power, -18, 13, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
// set mode to standby
setMode(RADIOLIB_RF69_STANDBY);
// set output power
int16_t state;
if(highPower) {
// check if both PA1 and PA2 are needed
if(power <= 10) {
// -2 to 13 dBm, PA1 is enough
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_OFF | RADIOLIB_RF69_PA1_ON | RADIOLIB_RF69_PA2_OFF | (power + 18), 7, 0);
} else if(power <= 17) {
// 13 to 17 dBm, both PAs required
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_OFF | RADIOLIB_RF69_PA1_ON | RADIOLIB_RF69_PA2_ON | (power + 14), 7, 0);
} else {
// 18 - 20 dBm, both PAs and hig power settings required
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_OFF | RADIOLIB_RF69_PA1_ON | RADIOLIB_RF69_PA2_ON | (power + 11), 7, 0);
}
} else {
// low power module, use only PA0
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_ON | RADIOLIB_RF69_PA1_OFF | RADIOLIB_RF69_PA2_OFF | (power + 18), 7, 0);
}
// cache the power value
if(state == RADIOLIB_ERR_NONE) {
_power = power;
}
return(state);
}
int16_t RF69::setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits) {
// check constraints
if((maxErrBits > 7) || (len > 8)) {
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
}
// sync word must not contain value 0x00
for(uint8_t i = 0; i < len; i++) {
if(syncWord[i] == 0x00) {
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
}
}
_syncWordLength = len;
int16_t state = enableSyncWordFiltering(maxErrBits);
RADIOLIB_ASSERT(state);
// set sync word register
_mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_SYNC_VALUE_1, syncWord, len);
return(RADIOLIB_ERR_NONE);
}
int16_t RF69::setPreambleLength(uint8_t preambleLen) {
// RF69 configures preamble length in bytes
if(preambleLen % 8 != 0) {
return(RADIOLIB_ERR_INVALID_PREAMBLE_LENGTH);
}
uint8_t preLenBytes = preambleLen / 8;
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_PREAMBLE_MSB, 0x00);
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PREAMBLE_LSB, preLenBytes));
}
int16_t RF69::setNodeAddress(uint8_t nodeAddr) {
// enable address filtering (node only)
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_ADDRESS_FILTERING_NODE, 2, 1);
RADIOLIB_ASSERT(state);
// set node address
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_NODE_ADRS, nodeAddr));
}
int16_t RF69::setBroadcastAddress(uint8_t broadAddr) {
// enable address filtering (node + broadcast)
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST, 2, 1);
RADIOLIB_ASSERT(state);
// set broadcast address
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_BROADCAST_ADRS, broadAddr));
}
int16_t RF69::disableAddressFiltering() {
// disable address filtering
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_ADDRESS_FILTERING_OFF, 2, 1);
RADIOLIB_ASSERT(state);
// set node address to default (0x00)
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_NODE_ADRS, 0x00);
RADIOLIB_ASSERT(state);
// set broadcast address to default (0x00)
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_BROADCAST_ADRS, 0x00));
}
void RF69::setAmbientTemperature(int16_t tempAmbient) {
_tempOffset = getTemperature() - tempAmbient;
}
int16_t RF69::getTemperature() {
// set mode to STANDBY
setMode(RADIOLIB_RF69_STANDBY);
// start temperature measurement
_mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEMP_1, RADIOLIB_RF69_TEMP_MEAS_START, 3, 3);
// wait until measurement is finished
while(_mod->SPIgetRegValue(RADIOLIB_RF69_REG_TEMP_1, 2, 2) == RADIOLIB_RF69_TEMP_MEAS_RUNNING) {
// check every 10 us
_mod->delay(10);
}
int8_t rawTemp = _mod->SPIgetRegValue(RADIOLIB_RF69_REG_TEMP_2);
return(0 - (rawTemp + _tempOffset));
}
size_t RF69::getPacketLength(bool update) {
if(!_packetLengthQueried && update) {
if (_packetLengthConfig == RADIOLIB_RF69_PACKET_FORMAT_VARIABLE) {
_packetLength = _mod->SPIreadRegister(RADIOLIB_RF69_REG_FIFO);
} else {
_packetLength = _mod->SPIreadRegister(RADIOLIB_RF69_REG_PAYLOAD_LENGTH);
}
_packetLengthQueried = true;
}
return(_packetLength);
}
int16_t RF69::fixedPacketLengthMode(uint8_t len) {
return(setPacketMode(RADIOLIB_RF69_PACKET_FORMAT_FIXED, len));
}
int16_t RF69::variablePacketLengthMode(uint8_t maxLen) {
return(setPacketMode(RADIOLIB_RF69_PACKET_FORMAT_VARIABLE, maxLen));
}
int16_t RF69::enableSyncWordFiltering(uint8_t maxErrBits) {
// enable sync word recognition
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_SYNC_CONFIG, RADIOLIB_RF69_SYNC_ON | RADIOLIB_RF69_FIFO_FILL_CONDITION_SYNC | (_syncWordLength - 1) << 3 | maxErrBits, 7, 0));
}
int16_t RF69::disableSyncWordFiltering() {
// disable preamble detection and generation
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PREAMBLE_LSB, 0, 7, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PREAMBLE_MSB, 0, 7, 0);
RADIOLIB_ASSERT(state);
// disable sync word detection and generation
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_SYNC_CONFIG, RADIOLIB_RF69_SYNC_OFF | RADIOLIB_RF69_FIFO_FILL_CONDITION, 7, 6);
return(state);
}
int16_t RF69::enableContinuousModeBitSync() {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE_WITH_SYNC, 6, 5));
}
int16_t RF69::disableContinuousModeBitSync() {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE, 6, 5));
}
int16_t RF69::setCrcFiltering(bool crcOn) {
if (crcOn == true) {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_CRC_ON, 4, 4));
} else {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_CRC_OFF, 4, 4));
}
}
int16_t RF69::setPromiscuousMode(bool promiscuous) {
int16_t state = RADIOLIB_ERR_NONE;
if (_promiscuous == promiscuous) {
return(state);
}
if (promiscuous == true) {
// disable preamble and sync word filtering and insertion
state = disableSyncWordFiltering();
RADIOLIB_ASSERT(state);
// disable CRC filtering
state = setCrcFiltering(false);
} else {
// enable preamble and sync word filtering and insertion
state = enableSyncWordFiltering();
RADIOLIB_ASSERT(state);
// enable CRC filtering
state = setCrcFiltering(true);
}
return(state);
}
int16_t RF69::setDataShaping(uint8_t sh) {
// set mode to standby
int16_t state = standby();
RADIOLIB_ASSERT(state);
// set data shaping
switch(sh) {
case RADIOLIB_SHAPING_NONE:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_NO_SHAPING, 1, 0));
case RADIOLIB_SHAPING_0_3:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_0_3, 1, 0));
case RADIOLIB_SHAPING_0_5:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_0_5, 1, 0));
case RADIOLIB_SHAPING_1_0:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_1_0, 1, 0));
default:
return(RADIOLIB_ERR_INVALID_DATA_SHAPING);
}
}
int16_t RF69::setEncoding(uint8_t encoding) {
// set mode to standby
int16_t state = standby();
RADIOLIB_ASSERT(state);
// set encoding
switch(encoding) {
case RADIOLIB_ENCODING_NRZ:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_DC_FREE_NONE, 6, 5));
case RADIOLIB_ENCODING_MANCHESTER:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_DC_FREE_MANCHESTER, 6, 5));
case RADIOLIB_ENCODING_WHITENING:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_DC_FREE_WHITENING, 6, 5));
default:
return(RADIOLIB_ERR_INVALID_ENCODING);
}
}
int16_t RF69::setLnaTestBoost(bool value) {
if(value) {
return (_mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_LNA, RADIOLIB_RF69_TEST_LNA_BOOST_HIGH, 7, 0));
}
return(_mod->SPIsetRegValue(RADIOLIB_RF69_TEST_LNA_BOOST_NORMAL, RADIOLIB_RF69_TEST_LNA_BOOST_HIGH, 7, 0));
}
float RF69::getRSSI() {
return(-1.0 * (_mod->SPIgetRegValue(RADIOLIB_RF69_REG_RSSI_VALUE)/2.0));
}
void RF69::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) {
_mod->setRfSwitchPins(rxEn, txEn);
}
uint8_t RF69::randomByte() {
// set mode to Rx
setMode(RADIOLIB_RF69_RX);
// wait a bit for the RSSI reading to stabilise
_mod->delay(10);
// read RSSI value 8 times, always keep just the least significant bit
uint8_t randByte = 0x00;
for(uint8_t i = 0; i < 8; i++) {
randByte |= ((_mod->SPIreadRegister(RADIOLIB_RF69_REG_RSSI_VALUE) & 0x01) << i);
}
// set mode to standby
setMode(RADIOLIB_RF69_STANDBY);
return(randByte);
}
void RF69::setDirectAction(void (*func)(void)) {
setDio1Action(func);
}
void RF69::readBit(RADIOLIB_PIN_TYPE pin) {
updateDirectBuffer((uint8_t)digitalRead(pin));
}
int16_t RF69::getChipVersion() {
return(_mod->SPIgetRegValue(RADIOLIB_RF69_REG_VERSION));
}
int16_t RF69::config() {
int16_t state = RADIOLIB_ERR_NONE;
// set mode to STANDBY
state = setMode(RADIOLIB_RF69_STANDBY);
RADIOLIB_ASSERT(state);
// set operation modes
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OP_MODE, RADIOLIB_RF69_SEQUENCER_ON | RADIOLIB_RF69_LISTEN_OFF, 7, 6);
RADIOLIB_ASSERT(state);
// enable over-current protection
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON, 4, 4);
RADIOLIB_ASSERT(state);
// set data mode, modulation type and shaping
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_PACKET_MODE | RADIOLIB_RF69_FSK, 6, 3);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_0_3, 1, 0);
RADIOLIB_ASSERT(state);
// set RSSI threshold
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RSSI_THRESH, RADIOLIB_RF69_RSSI_THRESHOLD, 7, 0);
RADIOLIB_ASSERT(state);
// reset FIFO flag
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_2, RADIOLIB_RF69_IRQ_FIFO_OVERRUN);
// disable ClkOut on DIO5
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_2, RADIOLIB_RF69_CLK_OUT_OFF, 2, 0);
RADIOLIB_ASSERT(state);
// set packet configuration and disable encryption
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_PACKET_FORMAT_VARIABLE | RADIOLIB_RF69_DC_FREE_NONE | RADIOLIB_RF69_CRC_ON | RADIOLIB_RF69_CRC_AUTOCLEAR_ON | RADIOLIB_RF69_ADDRESS_FILTERING_OFF, 7, 1);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_INTER_PACKET_RX_DELAY, 7, 4);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_AUTO_RX_RESTART_ON | RADIOLIB_RF69_AES_OFF, 1, 0);
RADIOLIB_ASSERT(state);
// set payload length
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PAYLOAD_LENGTH, RADIOLIB_RF69_PAYLOAD_LENGTH, 7, 0);
RADIOLIB_ASSERT(state);
// set FIFO threshold
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_FIFO_THRESH, RADIOLIB_RF69_TX_START_CONDITION_FIFO_NOT_EMPTY | RADIOLIB_RF69_FIFO_THRESHOLD, 7, 0);
RADIOLIB_ASSERT(state);
// set Rx timeouts
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_1, RADIOLIB_RF69_TIMEOUT_RX_START, 7, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_2, RADIOLIB_RF69_TIMEOUT_RSSI_THRESH, 7, 0);
RADIOLIB_ASSERT(state);
// enable improved fading margin
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_DAGC, RADIOLIB_RF69_CONTINUOUS_DAGC_LOW_BETA_OFF, 7, 0);
return(state);
}
int16_t RF69::setPacketMode(uint8_t mode, uint8_t len) {
// check length
if (len > RADIOLIB_RF69_MAX_PACKET_LENGTH) {
return(RADIOLIB_ERR_PACKET_TOO_LONG);
}
// set to fixed packet length
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, mode, 7, 7);
RADIOLIB_ASSERT(state);
// set length to register
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PAYLOAD_LENGTH, len);
RADIOLIB_ASSERT(state);
// update the cached value
_packetLengthConfig = mode;
return(state);
}
int16_t RF69::setMode(uint8_t mode) {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_OP_MODE, mode, 4, 2));
}
void RF69::clearIRQFlags() {
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_1, 0b11111111);
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_2, 0b11111111);
}
void RF69::clearFIFO(size_t count) {
while(count) {
_mod->SPIreadRegister(RADIOLIB_RF69_REG_FIFO);
count--;
}
}
#endif

View File

@ -0,0 +1,959 @@
#if !defined(_RADIOLIB_RF69_H)
#define _RADIOLIB_RF69_H
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_RF69)
#include "../../Module.h"
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
// RF69 physical layer properties
#define RADIOLIB_RF69_FREQUENCY_STEP_SIZE 61.03515625
#define RADIOLIB_RF69_MAX_PACKET_LENGTH 64
#define RADIOLIB_RF69_CRYSTAL_FREQ 32.0
#define RADIOLIB_RF69_DIV_EXPONENT 19
// RF69 register map
#define RADIOLIB_RF69_REG_FIFO 0x00
#define RADIOLIB_RF69_REG_OP_MODE 0x01
#define RADIOLIB_RF69_REG_DATA_MODUL 0x02
#define RADIOLIB_RF69_REG_BITRATE_MSB 0x03
#define RADIOLIB_RF69_REG_BITRATE_LSB 0x04
#define RADIOLIB_RF69_REG_FDEV_MSB 0x05
#define RADIOLIB_RF69_REG_FDEV_LSB 0x06
#define RADIOLIB_RF69_REG_FRF_MSB 0x07
#define RADIOLIB_RF69_REG_FRF_MID 0x08
#define RADIOLIB_RF69_REG_FRF_LSB 0x09
#define RADIOLIB_RF69_REG_OSC_1 0x0A
#define RADIOLIB_RF69_REG_AFC_CTRL 0x0B
#define RADIOLIB_RF69_REG_LISTEN_1 0x0D
#define RADIOLIB_RF69_REG_LISTEN_2 0x0E
#define RADIOLIB_RF69_REG_LISTEN_3 0x0F
#define RADIOLIB_RF69_REG_VERSION 0x10
#define RADIOLIB_RF69_REG_PA_LEVEL 0x11
#define RADIOLIB_RF69_REG_PA_RAMP 0x12
#define RADIOLIB_RF69_REG_OCP 0x13
#define RADIOLIB_RF69_REG_LNA 0x18
#define RADIOLIB_RF69_REG_RX_BW 0x19
#define RADIOLIB_RF69_REG_AFC_BW 0x1A
#define RADIOLIB_RF69_REG_OOK_PEAK 0x1B
#define RADIOLIB_RF69_REG_OOK_AVG 0x1C
#define RADIOLIB_RF69_REG_OOK_FIX 0x1D
#define RADIOLIB_RF69_REG_AFC_FEI 0x1E
#define RADIOLIB_RF69_REG_AFC_MSB 0x1F
#define RADIOLIB_RF69_REG_AFC_LSB 0x20
#define RADIOLIB_RF69_REG_FEI_MSB 0x21
#define RADIOLIB_RF69_REG_FEI_LSB 0x22
#define RADIOLIB_RF69_REG_RSSI_CONFIG 0x23
#define RADIOLIB_RF69_REG_RSSI_VALUE 0x24
#define RADIOLIB_RF69_REG_DIO_MAPPING_1 0x25
#define RADIOLIB_RF69_REG_DIO_MAPPING_2 0x26
#define RADIOLIB_RF69_REG_IRQ_FLAGS_1 0x27
#define RADIOLIB_RF69_REG_IRQ_FLAGS_2 0x28
#define RADIOLIB_RF69_REG_RSSI_THRESH 0x29
#define RADIOLIB_RF69_REG_RX_TIMEOUT_1 0x2A
#define RADIOLIB_RF69_REG_RX_TIMEOUT_2 0x2B
#define RADIOLIB_RF69_REG_PREAMBLE_MSB 0x2C
#define RADIOLIB_RF69_REG_PREAMBLE_LSB 0x2D
#define RADIOLIB_RF69_REG_SYNC_CONFIG 0x2E
#define RADIOLIB_RF69_REG_SYNC_VALUE_1 0x2F
#define RADIOLIB_RF69_REG_SYNC_VALUE_2 0x30
#define RADIOLIB_RF69_REG_SYNC_VALUE_3 0x31
#define RADIOLIB_RF69_REG_SYNC_VALUE_4 0x32
#define RADIOLIB_RF69_REG_SYNC_VALUE_5 0x33
#define RADIOLIB_RF69_REG_SYNC_VALUE_6 0x34
#define RADIOLIB_RF69_REG_SYNC_VALUE_7 0x35
#define RADIOLIB_RF69_REG_SYNC_VALUE_8 0x36
#define RADIOLIB_RF69_REG_PACKET_CONFIG_1 0x37
#define RADIOLIB_RF69_REG_PAYLOAD_LENGTH 0x38
#define RADIOLIB_RF69_REG_NODE_ADRS 0x39
#define RADIOLIB_RF69_REG_BROADCAST_ADRS 0x3A
#define RADIOLIB_RF69_REG_AUTO_MODES 0x3B
#define RADIOLIB_RF69_REG_FIFO_THRESH 0x3C
#define RADIOLIB_RF69_REG_PACKET_CONFIG_2 0x3D
#define RADIOLIB_RF69_REG_AES_KEY_1 0x3E
#define RADIOLIB_RF69_REG_AES_KEY_2 0x3F
#define RADIOLIB_RF69_REG_AES_KEY_3 0x40
#define RADIOLIB_RF69_REG_AES_KEY_4 0x41
#define RADIOLIB_RF69_REG_AES_KEY_5 0x42
#define RADIOLIB_RF69_REG_AES_KEY_6 0x43
#define RADIOLIB_RF69_REG_AES_KEY_7 0x44
#define RADIOLIB_RF69_REG_AES_KEY_8 0x45
#define RADIOLIB_RF69_REG_AES_KEY_9 0x46
#define RADIOLIB_RF69_REG_AES_KEY_10 0x47
#define RADIOLIB_RF69_REG_AES_KEY_11 0x48
#define RADIOLIB_RF69_REG_AES_KEY_12 0x49
#define RADIOLIB_RF69_REG_AES_KEY_13 0x4A
#define RADIOLIB_RF69_REG_AES_KEY_14 0x4B
#define RADIOLIB_RF69_REG_AES_KEY_15 0x4C
#define RADIOLIB_RF69_REG_AES_KEY_16 0x4D
#define RADIOLIB_RF69_REG_TEMP_1 0x4E
#define RADIOLIB_RF69_REG_TEMP_2 0x4F
#define RADIOLIB_RF69_REG_TEST_LNA 0x58
#define RADIOLIB_RF69_REG_TEST_PA1 0x5A
#define RADIOLIB_RF69_REG_TEST_PA2 0x5C
#define RADIOLIB_RF69_REG_TEST_DAGC 0x6F
// RF69 modem settings
// RF69_REG_OP_MODE MSB LSB DESCRIPTION
#define RADIOLIB_RF69_SEQUENCER_OFF 0b00000000 // 7 7 disable automatic sequencer
#define RADIOLIB_RF69_SEQUENCER_ON 0b10000000 // 7 7 enable automatic sequencer
#define RADIOLIB_RF69_LISTEN_OFF 0b00000000 // 6 6 disable Listen mode
#define RADIOLIB_RF69_LISTEN_ON 0b01000000 // 6 6 enable Listen mode
#define RADIOLIB_RF69_LISTEN_ABORT 0b00100000 // 5 5 abort Listen mode (has to be set together with RF69_LISTEN_OFF)
#define RADIOLIB_RF69_SLEEP 0b00000000 // 4 2 sleep
#define RADIOLIB_RF69_STANDBY 0b00000100 // 4 2 standby
#define RADIOLIB_RF69_FS 0b00001000 // 4 2 frequency synthesis
#define RADIOLIB_RF69_TX 0b00001100 // 4 2 transmit
#define RADIOLIB_RF69_RX 0b00010000 // 4 2 receive
// RF69_REG_DATA_MODUL
#define RADIOLIB_RF69_PACKET_MODE 0b00000000 // 6 5 packet mode (default)
#define RADIOLIB_RF69_CONTINUOUS_MODE_WITH_SYNC 0b01000000 // 6 5 continuous mode with bit synchronizer
#define RADIOLIB_RF69_CONTINUOUS_MODE 0b01100000 // 6 5 continuous mode without bit synchronizer
#define RADIOLIB_RF69_FSK 0b00000000 // 4 3 modulation: FSK (default)
#define RADIOLIB_RF69_OOK 0b00001000 // 4 3 OOK
#define RADIOLIB_RF69_NO_SHAPING 0b00000000 // 1 0 modulation shaping: no shaping (default)
#define RADIOLIB_RF69_FSK_GAUSSIAN_1_0 0b00000001 // 1 0 FSK modulation Gaussian filter, BT = 1.0
#define RADIOLIB_RF69_FSK_GAUSSIAN_0_5 0b00000010 // 1 0 FSK modulation Gaussian filter, BT = 0.5
#define RADIOLIB_RF69_FSK_GAUSSIAN_0_3 0b00000011 // 1 0 FSK modulation Gaussian filter, BT = 0.3
#define RADIOLIB_RF69_OOK_FILTER_BR 0b00000001 // 1 0 OOK modulation filter, f_cutoff = BR
#define RADIOLIB_RF69_OOK_FILTER_2BR 0b00000010 // 1 0 OOK modulation filter, f_cutoff = 2*BR
// RF69_REG_BITRATE_MSB + REG_BITRATE_LSB
#define RADIOLIB_RF69_BITRATE_MSB 0x1A // 7 0 bit rate setting: rate = F(XOSC) / BITRATE
#define RADIOLIB_RF69_BITRATE_LSB 0x0B // 7 0 default value: 4.8 kbps 0x40 // 7 0
// RF69_REG_FDEV_MSB + REG_FDEV_LSB
#define RADIOLIB_RF69_FDEV_MSB 0x00 // 5 0 frequency deviation: f_dev = f_step * FDEV
#define RADIOLIB_RF69_FDEV_LSB 0x52 // 7 0 default value: 5 kHz
// RF69_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB
#define RADIOLIB_RF69_FRF_MSB 0xE4 // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
#define RADIOLIB_RF69_FRF_MID 0xC0 // 7 0 where F(XOSC) = 32 MHz
#define RADIOLIB_RF69_FRF_LSB 0x00 // 7 0 default value: 915 MHz
// RF69_REG_OSC_1
#define RADIOLIB_RF69_RC_CAL_START 0b10000000 // 7 7 force RC oscillator calibration
#define RADIOLIB_RF69_RC_CAL_RUNNING 0b00000000 // 6 6 RC oscillator calibration is still running
#define RADIOLIB_RF69_RC_CAL_DONE 0b00000000 // 5 5 RC oscillator calibration has finished
// RF69_REG_AFC_CTRL
#define RADIOLIB_RF69_AFC_LOW_BETA_OFF 0b00000000 // 5 5 standard AFC routine
#define RADIOLIB_RF69_AFC_LOW_BETA_ON 0b00100000 // 5 5 improved AFC routine for signals with modulation index less than 2
// RF69_REG_LISTEN_1
#define RADIOLIB_RF69_LISTEN_RES_IDLE_64_US 0b01000000 // 7 6 resolution of Listen mode idle time: 64 us
#define RADIOLIB_RF69_LISTEN_RES_IDLE_4_1_MS 0b10000000 // 7 6 4.1 ms (default)
#define RADIOLIB_RF69_LISTEN_RES_IDLE_262_MS 0b11000000 // 7 6 262 ms
#define RADIOLIB_RF69_LISTEN_RES_RX_64_US 0b00010000 // 5 4 resolution of Listen mode rx time: 64 us (default)
#define RADIOLIB_RF69_LISTEN_RES_RX_4_1_MS 0b00100000 // 5 4 4.1 ms
#define RADIOLIB_RF69_LISTEN_RES_RX_262_MS 0b00110000 // 5 4 262 ms
#define RADIOLIB_RF69_LISTEN_ACCEPT_ABOVE_RSSI_THRESH 0b00000000 // 3 3 packet acceptance criteria: RSSI above threshold
#define RADIOLIB_RF69_LISTEN_ACCEPT_MATCH_SYNC_ADDRESS 0b00001000 // 3 3 RSSI above threshold AND sync address matched
#define RADIOLIB_RF69_LISTEN_END_KEEP_RX 0b00000000 // 2 1 action after packet acceptance: stay in Rx mode
#define RADIOLIB_RF69_LISTEN_END_KEEP_RX_TIMEOUT 0b00000010 // 2 1 stay in Rx mode until timeout (default)
#define RADIOLIB_RF69_LISTEN_END_KEEP_RX_TIMEOUT_RESUME 0b00000100 // 2 1 stay in Rx mode until timeout, Listen mode will resume
// RF69_REG_LISTEN_2
#define RADIOLIB_RF69_LISTEN_COEF_IDLE 0xF5 // 7 0 duration of idle phase in Listen mode
// RF69_REG_LISTEN_3
#define RADIOLIB_RF69_LISTEN_COEF_RX 0x20 // 7 0 duration of Rx phase in Listen mode
// RF69_REG_VERSION
#define RADIOLIB_RF69_CHIP_VERSION 0x24 // 7 0
// RF69_REG_PA_LEVEL
#define RADIOLIB_RF69_PA0_OFF 0b00000000 // 7 7 PA0 disabled
#define RADIOLIB_RF69_PA0_ON 0b10000000 // 7 7 PA0 enabled (default)
#define RADIOLIB_RF69_PA1_OFF 0b00000000 // 6 6 PA1 disabled (default)
#define RADIOLIB_RF69_PA1_ON 0b01000000 // 6 6 PA1 enabled
#define RADIOLIB_RF69_PA2_OFF 0b00000000 // 5 5 PA2 disabled (default)
#define RADIOLIB_RF69_PA2_ON 0b00100000 // 5 5 PA2 enabled
#define RADIOLIB_RF69_OUTPUT_POWER 0b00011111 // 4 0 output power: P_out = -18 + OUTPUT_POWER
// RF69_REG_PA_RAMP
#define RADIOLIB_RF69_PA_RAMP_3_4_MS 0b00000000 // 3 0 PA ramp rise/fall time: 3.4 ms
#define RADIOLIB_RF69_PA_RAMP_2_MS 0b00000001 // 3 0 2 ms
#define RADIOLIB_RF69_PA_RAMP_1_MS 0b00000010 // 3 0 1 ms
#define RADIOLIB_RF69_PA_RAMP_500_US 0b00000011 // 3 0 500 us
#define RADIOLIB_RF69_PA_RAMP_250_US 0b00000100 // 3 0 250 us
#define RADIOLIB_RF69_PA_RAMP_125_US 0b00000101 // 3 0 125 us
#define RADIOLIB_RF69_PA_RAMP_100_US 0b00000110 // 3 0 100 us
#define RADIOLIB_RF69_PA_RAMP_62_US 0b00000111 // 3 0 62 us
#define RADIOLIB_RF69_PA_RAMP_50_US 0b00001000 // 3 0 50 us
#define RADIOLIB_RF69_PA_RAMP_40_US 0b00001001 // 3 0 40 us (default)
#define RADIOLIB_RF69_PA_RAMP_31_US 0b00001010 // 3 0 31 us
#define RADIOLIB_RF69_PA_RAMP_25_US 0b00001011 // 3 0 25 us
#define RADIOLIB_RF69_PA_RAMP_20_US 0b00001100 // 3 0 20 us
#define RADIOLIB_RF69_PA_RAMP_15_US 0b00001101 // 3 0 15 us
#define RADIOLIB_RF69_PA_RAMP_12_US 0b00001110 // 3 0 12 us
#define RADIOLIB_RF69_PA_RAMP_10_US 0b00001111 // 3 0 10 us
// RF69_REG_OCP
#define RADIOLIB_RF69_OCP_OFF 0b00000000 // 4 4 PA overload current protection disabled
#define RADIOLIB_RF69_OCP_ON 0b00010000 // 4 4 PA overload current protection enabled
#define RADIOLIB_RF69_OCP_TRIM 0b00001010 // 3 0 OCP current: I_max(OCP_TRIM = 0b1010) = 95 mA
// RF69_REG_LNA
#define RADIOLIB_RF69_LNA_Z_IN_50_OHM 0b00000000 // 7 7 LNA input impedance: 50 ohm
#define RADIOLIB_RF69_LNA_Z_IN_200_OHM 0b10000000 // 7 7 200 ohm
#define RADIOLIB_RF69_LNA_CURRENT_GAIN 0b00001000 // 5 3 manually set LNA current gain
#define RADIOLIB_RF69_LNA_GAIN_AUTO 0b00000000 // 2 0 LNA gain setting: set automatically by AGC
#define RADIOLIB_RF69_LNA_GAIN_MAX 0b00000001 // 2 0 max gain
#define RADIOLIB_RF69_LNA_GAIN_MAX_6_DB 0b00000010 // 2 0 max gain - 6 dB
#define RADIOLIB_RF69_LNA_GAIN_MAX_12_DB 0b00000011 // 2 0 max gain - 12 dB
#define RADIOLIB_RF69_LNA_GAIN_MAX_24_DB 0b00000100 // 2 0 max gain - 24 dB
#define RADIOLIB_RF69_LNA_GAIN_MAX_36_DB 0b00000101 // 2 0 max gain - 36 dB
#define RADIOLIB_RF69_LNA_GAIN_MAX_48_DB 0b00000110 // 2 0 max gain - 48 dB
// RF69_REG_RX_BW
#define RADIOLIB_RF69_DCC_FREQ 0b01000000 // 7 5 DC offset canceller cutoff frequency (4% Rx BW by default)
#define RADIOLIB_RF69_RX_BW_MANT_16 0b00000000 // 4 3 Channel filter bandwidth FSK: RxBw = F(XOSC)/(RxBwMant * 2^(RxBwExp + 2))
#define RADIOLIB_RF69_RX_BW_MANT_20 0b00001000 // 4 3 OOK: RxBw = F(XOSC)/(RxBwMant * 2^(RxBwExp + 3))
#define RADIOLIB_RF69_RX_BW_MANT_24 0b00010000 // 4 3
#define RADIOLIB_RF69_RX_BW_EXP 0b00000101 // 2 0 default RxBwExp value = 5
// RF69_REG_AFC_BW
#define RADIOLIB_RF69_DCC_FREQ_AFC 0b10000000 // 7 5 default DccFreq parameter for AFC
#define RADIOLIB_RF69_DCC_RX_BW_MANT_AFC 0b00001000 // 4 3 default RxBwMant parameter for AFC
#define RADIOLIB_RF69_DCC_RX_BW_EXP_AFC 0b00000011 // 2 0 default RxBwExp parameter for AFC
// RF69_REG_OOK_PEAK
#define RADIOLIB_RF69_OOK_THRESH_FIXED 0b00000000 // 7 6 OOK threshold type: fixed
#define RADIOLIB_RF69_OOK_THRESH_PEAK 0b01000000 // 7 6 peak (default)
#define RADIOLIB_RF69_OOK_THRESH_AVERAGE 0b10000000 // 7 6 average
#define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_0_5_DB 0b00000000 // 5 3 OOK demodulator step size: 0.5 dB (default)
#define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_1_0_DB 0b00001000 // 5 3 1.0 dB
#define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_1_5_DB 0b00010000 // 5 3 1.5 dB
#define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_2_0_DB 0b00011000 // 5 3 2.0 dB
#define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_3_0_DB 0b00100000 // 5 3 3.0 dB
#define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_4_0_DB 0b00101000 // 5 3 4.0 dB
#define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_5_0_DB 0b00110000 // 5 3 5.0 dB
#define RADIOLIB_RF69_OOK_PEAK_THRESH_STEP_6_0_DB 0b00111000 // 5 3 6.0 dB
#define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_1_1_CHIP 0b00000000 // 2 0 OOK demodulator step period: once per chip (default)
#define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_1_2_CHIP 0b00000001 // 2 0 once every 2 chips
#define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_1_4_CHIP 0b00000010 // 2 0 once every 4 chips
#define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_1_8_CHIP 0b00000011 // 2 0 once every 8 chips
#define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_2_1_CHIP 0b00000100 // 2 0 2 times per chip
#define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_4_1_CHIP 0b00000101 // 2 0 4 times per chip
#define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_8_1_CHIP 0b00000110 // 2 0 8 times per chip
#define RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_16_1_CHIP 0b00000111 // 2 0 16 times per chip
// RF69_REG_OOK_AVG
#define RADIOLIB_RF69_OOK_AVG_THRESH_FILT_32_PI 0b00000000 // 7 6 OOK average filter coefficient: chip rate / 32*pi
#define RADIOLIB_RF69_OOK_AVG_THRESH_FILT_8_PI 0b01000000 // 7 6 chip rate / 8*pi
#define RADIOLIB_RF69_OOK_AVG_THRESH_FILT_4_PI 0b10000000 // 7 6 chip rate / 4*pi (default)
#define RADIOLIB_RF69_OOK_AVG_THRESH_FILT_2_PI 0b11000000 // 7 6 chip rate / 2*pi
// RF69_REG_OOK_FIX
#define RADIOLIB_RF69_OOK_FIXED_THRESH 0b00000110 // 7 0 default OOK fixed threshold (6 dB)
// RF69_REG_AFC_FEI
#define RADIOLIB_RF69_FEI_RUNNING 0b00000000 // 6 6 FEI status: on-going
#define RADIOLIB_RF69_FEI_DONE 0b01000000 // 6 6 done
#define RADIOLIB_RF69_FEI_START 0b00100000 // 5 5 force new FEI measurement
#define RADIOLIB_RF69_AFC_RUNNING 0b00000000 // 4 4 AFC status: on-going
#define RADIOLIB_RF69_AFC_DONE 0b00010000 // 4 4 done
#define RADIOLIB_RF69_AFC_AUTOCLEAR_OFF 0b00000000 // 3 3 AFC register autoclear disabled
#define RADIOLIB_RF69_AFC_AUTOCLEAR_ON 0b00001000 // 3 3 AFC register autoclear enabled
#define RADIOLIB_RF69_AFC_AUTO_OFF 0b00000000 // 2 2 perform AFC only manually
#define RADIOLIB_RF69_AFC_AUTO_ON 0b00000100 // 2 2 perform AFC each time Rx mode is started
#define RADIOLIB_RF69_AFC_CLEAR 0b00000010 // 1 1 clear AFC register
#define RADIOLIB_RF69_AFC_START 0b00000001 // 0 0 start AFC
// RF69_REG_RSSI_CONFIG
#define RADIOLIB_RF69_RSSI_RUNNING 0b00000000 // 1 1 RSSI status: on-going
#define RADIOLIB_RF69_RSSI_DONE 0b00000010 // 1 1 done
#define RADIOLIB_RF69_RSSI_START 0b00000001 // 0 0 start RSSI measurement
// RF69_REG_DIO_MAPPING_1
#define RADIOLIB_RF69_DIO0_CONT_MODE_READY 0b11000000 // 7 6
#define RADIOLIB_RF69_DIO0_CONT_PLL_LOCK 0b00000000 // 7 6
#define RADIOLIB_RF69_DIO0_CONT_SYNC_ADDRESS 0b00000000 // 7 6
#define RADIOLIB_RF69_DIO0_CONT_TIMEOUT 0b01000000 // 7 6
#define RADIOLIB_RF69_DIO0_CONT_RSSI 0b10000000 // 7 6
#define RADIOLIB_RF69_DIO0_CONT_TX_READY 0b01000000 // 7 6
#define RADIOLIB_RF69_DIO0_PACK_PLL_LOCK 0b11000000 // 7 6
#define RADIOLIB_RF69_DIO0_PACK_CRC_OK 0b00000000 // 7 6
#define RADIOLIB_RF69_DIO0_PACK_PAYLOAD_READY 0b01000000 // 7 6
#define RADIOLIB_RF69_DIO0_PACK_SYNC_ADDRESS 0b10000000 // 7 6
#define RADIOLIB_RF69_DIO0_PACK_RSSI 0b11000000 // 7 6
#define RADIOLIB_RF69_DIO0_PACK_PACKET_SENT 0b00000000 // 7 6
#define RADIOLIB_RF69_DIO0_PACK_TX_READY 0b01000000 // 7 6
#define RADIOLIB_RF69_DIO1_CONT_PLL_LOCK 0b00110000 // 5 4
#define RADIOLIB_RF69_DIO1_CONT_DCLK 0b00000000 // 5 4
#define RADIOLIB_RF69_DIO1_CONT_RX_READY 0b00010000 // 5 4
#define RADIOLIB_RF69_DIO1_CONT_SYNC_ADDRESS 0b00110000 // 5 4
#define RADIOLIB_RF69_DIO1_CONT_TX_READY 0b00010000 // 5 4
#define RADIOLIB_RF69_DIO1_PACK_FIFO_LEVEL 0b00000000 // 5 4
#define RADIOLIB_RF69_DIO1_PACK_FIFO_FULL 0b00010000 // 5 4
#define RADIOLIB_RF69_DIO1_PACK_FIFO_NOT_EMPTY 0b00100000 // 5 4
#define RADIOLIB_RF69_DIO1_PACK_PLL_LOCK 0b00110000 // 5 4
#define RADIOLIB_RF69_DIO1_PACK_TIMEOUT 0b00110000 // 5 4
#define RADIOLIB_RF69_DIO2_CONT_DATA 0b00000000 // 3 2
// RF69_REG_DIO_MAPPING_2
#define RADIOLIB_RF69_CLK_OUT_FXOSC 0b00000000 // 2 0 ClkOut frequency: F(XOSC)
#define RADIOLIB_RF69_CLK_OUT_FXOSC_2 0b00000001 // 2 0 F(XOSC) / 2
#define RADIOLIB_RF69_CLK_OUT_FXOSC_4 0b00000010 // 2 0 F(XOSC) / 4
#define RADIOLIB_RF69_CLK_OUT_FXOSC_8 0b00000011 // 2 0 F(XOSC) / 8
#define RADIOLIB_RF69_CLK_OUT_FXOSC_16 0b00000100 // 2 0 F(XOSC) / 16
#define RADIOLIB_RF69_CLK_OUT_FXOSC_32 0b00000101 // 2 0 F(XOSC) / 31
#define RADIOLIB_RF69_CLK_OUT_RC 0b00000110 // 2 0 RC
#define RADIOLIB_RF69_CLK_OUT_OFF 0b00000111 // 2 0 disabled (default)
// RF69_REG_IRQ_FLAGS_1
#define RADIOLIB_RF69_IRQ_MODE_READY 0b10000000 // 7 7 requested mode was set
#define RADIOLIB_RF69_IRQ_RX_READY 0b01000000 // 6 6 Rx mode ready
#define RADIOLIB_RF69_IRQ_TX_READY 0b00100000 // 5 5 Tx mode ready
#define RADIOLIB_RF69_IRQ_PLL_LOCK 0b00010000 // 4 4 PLL is locked
#define RADIOLIB_RF69_IRQ_RSSI 0b00001000 // 3 3 RSSI value exceeded RssiThreshold
#define RADIOLIB_RF69_IRQ_TIMEOUT 0b00000100 // 2 2 timeout occurred
#define RADIOLIB_RF69_IRQ_AUTO_MODE 0b00000010 // 1 1 entered intermediate mode
#define RADIOLIB_RF69_SYNC_ADDRESS_MATCH 0b00000001 // 0 0 sync address detected
// RF69_REG_IRQ_FLAGS_2
#define RADIOLIB_RF69_IRQ_FIFO_FULL 0b10000000 // 7 7 FIFO is full
#define RADIOLIB_RF69_IRQ_FIFO_NOT_EMPTY 0b01000000 // 6 6 FIFO contains at least 1 byte
#define RADIOLIB_RF69_IRQ_FIFO_LEVEL 0b00100000 // 5 5 FIFO contains more than FifoThreshold bytes
#define RADIOLIB_RF69_IRQ_FIFO_OVERRUN 0b00010000 // 4 4 FIFO overrun occurred
#define RADIOLIB_RF69_IRQ_PACKET_SENT 0b00001000 // 3 3 packet was sent
#define RADIOLIB_RF69_IRQ_PAYLOAD_READY 0b00000100 // 2 2 last payload byte received and CRC check passed
#define RADIOLIB_RF69_IRQ_CRC_OK 0b00000010 // 1 1 CRC check passed
// RF69_REG_RSSI_THRESH
#define RADIOLIB_RF69_RSSI_THRESHOLD 0xE4 // 7 0 RSSI threshold level (2 dB by default)
// RF69_REG_RX_TIMEOUT_1
#define RADIOLIB_RF69_TIMEOUT_RX_START_OFF 0x00 // 7 0 RSSI interrupt timeout disabled (default)
#define RADIOLIB_RF69_TIMEOUT_RX_START 0xFF // 7 0 timeout will occur if RSSI interrupt is not received
// RF69_REG_RX_TIMEOUT_2
#define RADIOLIB_RF69_TIMEOUT_RSSI_THRESH_OFF 0x00 // 7 0 PayloadReady interrupt timeout disabled (default)
#define RADIOLIB_RF69_TIMEOUT_RSSI_THRESH 0xFF // 7 0 timeout will occur if PayloadReady interrupt is not received
// RF69_REG_PREAMBLE_MSB + REG_PREAMBLE_MSB
#define RADIOLIB_RF69_PREAMBLE_MSB 0x00 // 7 0 2-byte preamble size value
#define RADIOLIB_RF69_PREAMBLE_LSB 0x03 // 7 0
// RF69_REG_SYNC_CONFIG
#define RADIOLIB_RF69_SYNC_OFF 0b00000000 // 7 7 sync word detection off
#define RADIOLIB_RF69_SYNC_ON 0b10000000 // 7 7 sync word detection on (default)
#define RADIOLIB_RF69_FIFO_FILL_CONDITION_SYNC 0b00000000 // 6 6 FIFO fill condition: on SyncAddress interrupt (default)
#define RADIOLIB_RF69_FIFO_FILL_CONDITION 0b01000000 // 6 6 as long as the bit is set
#define RADIOLIB_RF69_SYNC_SIZE 0b00001000 // 5 3 size of sync word: SyncSize + 1 bytes
#define RADIOLIB_RF69_SYNC_TOL 0b00000000 // 2 0 number of tolerated errors in sync word
// RF69_REG_SYNC_VALUE_1 - SYNC_VALUE_8
#define RADIOLIB_RF69_SYNC_BYTE_1 0x01 // 7 0 sync word: 1st byte (MSB)
#define RADIOLIB_RF69_SYNC_BYTE_2 0x01 // 7 0 2nd byte
#define RADIOLIB_RF69_SYNC_BYTE_3 0x01 // 7 0 3rd byte
#define RADIOLIB_RF69_SYNC_BYTE_4 0x01 // 7 0 4th byte
#define RADIOLIB_RF69_SYNC_BYTE_5 0x01 // 7 0 5th byte
#define RADIOLIB_RF69_SYNC_BYTE_6 0x01 // 7 0 6th byte
#define RADIOLIB_RF69_SYNC_BYTE_7 0x01 // 7 0 7th byte
#define RADIOLIB_RF69_SYNC_BYTE_8 0x01 // 7 0 8th byte (LSB)
// RF69_REG_PACKET_CONFIG_1
#define RADIOLIB_RF69_PACKET_FORMAT_FIXED 0b00000000 // 7 7 fixed packet length (default)
#define RADIOLIB_RF69_PACKET_FORMAT_VARIABLE 0b10000000 // 7 7 variable packet length
#define RADIOLIB_RF69_DC_FREE_NONE 0b00000000 // 6 5 DC-free encoding: none (default)
#define RADIOLIB_RF69_DC_FREE_MANCHESTER 0b00100000 // 6 5 Manchester
#define RADIOLIB_RF69_DC_FREE_WHITENING 0b01000000 // 6 5 Whitening
#define RADIOLIB_RF69_CRC_OFF 0b00000000 // 4 4 CRC disabled
#define RADIOLIB_RF69_CRC_ON 0b00010000 // 4 4 CRC enabled (default)
#define RADIOLIB_RF69_CRC_AUTOCLEAR_ON 0b00000000 // 3 3 discard packet when CRC check fails (default)
#define RADIOLIB_RF69_CRC_AUTOCLEAR_OFF 0b00001000 // 3 3 keep packet when CRC check fails
#define RADIOLIB_RF69_ADDRESS_FILTERING_OFF 0b00000000 // 2 1 address filtering: none (default)
#define RADIOLIB_RF69_ADDRESS_FILTERING_NODE 0b00000010 // 2 1 node
#define RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST 0b00000100 // 2 1 node or broadcast
// RF69_REG_PAYLOAD_LENGTH
#define RADIOLIB_RF69_PAYLOAD_LENGTH 0xFF // 7 0 payload length
// RF69_REG_AUTO_MODES
#define RADIOLIB_RF69_ENTER_COND_NONE 0b00000000 // 7 5 condition for entering intermediate mode: none, AutoModes disabled (default)
#define RADIOLIB_RF69_ENTER_COND_FIFO_NOT_EMPTY 0b00100000 // 7 5 FifoNotEmpty rising edge
#define RADIOLIB_RF69_ENTER_COND_FIFO_LEVEL 0b01000000 // 7 5 FifoLevel rising edge
#define RADIOLIB_RF69_ENTER_COND_CRC_OK 0b01100000 // 7 5 CrcOk rising edge
#define RADIOLIB_RF69_ENTER_COND_PAYLOAD_READY 0b10000000 // 7 5 PayloadReady rising edge
#define RADIOLIB_RF69_ENTER_COND_SYNC_ADDRESS 0b10100000 // 7 5 SyncAddress rising edge
#define RADIOLIB_RF69_ENTER_COND_PACKET_SENT 0b11000000 // 7 5 PacketSent rising edge
#define RADIOLIB_RF69_ENTER_COND_FIFO_EMPTY 0b11100000 // 7 5 FifoNotEmpty falling edge
#define RADIOLIB_RF69_EXIT_COND_NONE 0b00000000 // 4 2 condition for exiting intermediate mode: none, AutoModes disabled (default)
#define RADIOLIB_RF69_EXIT_COND_FIFO_EMPTY 0b00100000 // 4 2 FifoNotEmpty falling edge
#define RADIOLIB_RF69_EXIT_COND_FIFO_LEVEL 0b01000000 // 4 2 FifoLevel rising edge
#define RADIOLIB_RF69_EXIT_COND_CRC_OK 0b01100000 // 4 2 CrcOk rising edge
#define RADIOLIB_RF69_EXIT_COND_PAYLOAD_READY 0b10000000 // 4 2 PayloadReady rising edge
#define RADIOLIB_RF69_EXIT_COND_SYNC_ADDRESS 0b10100000 // 4 2 SyncAddress rising edge
#define RADIOLIB_RF69_EXIT_COND_PACKET_SENT 0b11000000 // 4 2 PacketSent rising edge
#define RADIOLIB_RF69_EXIT_COND_TIMEOUT 0b11100000 // 4 2 timeout rising edge
#define RADIOLIB_RF69_INTER_MODE_SLEEP 0b00000000 // 1 0 intermediate mode: sleep (default)
#define RADIOLIB_RF69_INTER_MODE_STANDBY 0b00000001 // 1 0 standby
#define RADIOLIB_RF69_INTER_MODE_RX 0b00000010 // 1 0 Rx
#define RADIOLIB_RF69_INTER_MODE_TX 0b00000011 // 1 0 Tx
// RF69_REG_FIFO_THRESH
#define RADIOLIB_RF69_TX_START_CONDITION_FIFO_LEVEL 0b00000000 // 7 7 packet transmission start condition: FifoLevel
#define RADIOLIB_RF69_TX_START_CONDITION_FIFO_NOT_EMPTY 0b10000000 // 7 7 FifoNotEmpty (default)
#define RADIOLIB_RF69_FIFO_THRESHOLD 0b00001111 // 6 0 default threshold to trigger FifoLevel interrupt
// RF69_REG_PACKET_CONFIG_2
#define RADIOLIB_RF69_INTER_PACKET_RX_DELAY 0b00000000 // 7 4 delay between FIFO empty and start of new RSSI phase
#define RADIOLIB_RF69_RESTART_RX 0b00000100 // 2 2 force receiver into wait mode
#define RADIOLIB_RF69_AUTO_RX_RESTART_OFF 0b00000000 // 1 1 auto Rx restart disabled
#define RADIOLIB_RF69_AUTO_RX_RESTART_ON 0b00000010 // 1 1 auto Rx restart enabled (default)
#define RADIOLIB_RF69_AES_OFF 0b00000000 // 0 0 AES encryption disabled (default)
#define RADIOLIB_RF69_AES_ON 0b00000001 // 0 0 AES encryption enabled, payload size limited to 66 bytes
// RF69_REG_TEST_LNA
#define RADIOLIB_RF69_TEST_LNA_BOOST_NORMAL 0x1B // 7 0
#define RADIOLIB_RF69_TEST_LNA_BOOST_HIGH 0x2D // 7 0
// RF69_REG_TEMP_1
#define RADIOLIB_RF69_TEMP_MEAS_START 0b00001000 // 3 3 trigger temperature measurement
#define RADIOLIB_RF69_TEMP_MEAS_RUNNING 0b00000100 // 2 2 temperature measurement status: on-going
#define RADIOLIB_RF69_TEMP_MEAS_DONE 0b00000000 // 2 2 done
// RF69_REG_TEST_DAGC
#define RADIOLIB_RF69_CONTINUOUS_DAGC_NORMAL 0x00 // 7 0 fading margin improvement: normal mode
#define RADIOLIB_RF69_CONTINUOUS_DAGC_LOW_BETA_ON 0x20 // 7 0 improved mode for AfcLowBetaOn
#define RADIOLIB_RF69_CONTINUOUS_DAGC_LOW_BETA_OFF 0x30 // 7 0 improved mode for AfcLowBetaOff (default)
// RF69_REG_TEST_PA1
#define RADIOLIB_RF69_PA1_NORMAL 0x55 // 7 0 PA_BOOST: none
#define RADIOLIB_RF69_PA1_20_DBM 0x5D // 7 0 +20 dBm
// RF69_REG_TEST_PA2
#define RADIOLIB_RF69_PA2_NORMAL 0x70 // 7 0 PA_BOOST: none
#define RADIOLIB_RF69_PA2_20_DBM 0x7C // 7 0 +20 dBm
/*!
\class RF69
\brief Control class for %RF69 module. Also serves as base class for SX1231.
*/
class RF69: public PhysicalLayer {
public:
// introduce PhysicalLayer overloads
using PhysicalLayer::transmit;
using PhysicalLayer::receive;
using PhysicalLayer::startTransmit;
using PhysicalLayer::readData;
/*!
\brief Default constructor.
\param mod Instance of Module that will be used to communicate with the radio.
*/
RF69(Module* module);
Module* getMod();
// basic methods
/*!
\brief Initialization method.
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
\param br Bit rate to be used in kbps. Defaults to 48.0 kbps.
\param freqDev Frequency deviation from carrier frequency in kHz Defaults to 50.0 kHz.
\param rxBw Receiver bandwidth in kHz. Defaults to 125.0 kHz.
\param power Output power in dBm. Defaults to 10 dBm.
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
\returns \ref status_codes
*/
int16_t begin(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16);
/*!
\brief Reset method. Will reset the chip to the default state using RST pin.
*/
void reset();
/*!
\brief Blocking binary transmit method.
Overloads for string-based transmissions are implemented in PhysicalLayer.
\param data Binary data to be sent.
\param len Number of bytes to send.
\param addr Address to send the data to. Will only be added if address filtering was enabled.
\returns \ref status_codes
*/
int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
/*!
\brief Blocking binary receive method.
Overloads for string-based transmissions are implemented in PhysicalLayer.
\param data Binary data to be sent.
\param len Number of bytes to send.
\returns \ref status_codes
*/
int16_t receive(uint8_t* data, size_t len) override;
/*!
\brief Sets the module to sleep mode.
\returns \ref status_codes
*/
int16_t sleep();
/*!
\brief Sets the module to standby mode.
\returns \ref status_codes
*/
int16_t standby() override;
/*!
\brief Starts direct mode transmission.
\param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY.
\returns \ref status_codes
*/
int16_t transmitDirect(uint32_t frf = 0) override;
/*!
\brief Starts direct mode reception.
\returns \ref status_codes
*/
int16_t receiveDirect() override;
/*!
\brief Stops direct mode. It is required to call this method to switch from direct transmissions to packet-based transmissions.
*/
int16_t packetMode();
// hardware AES support
/*!
\brief Sets AES key.
\param Key to be used for AES encryption. Must be exactly 16 bytes long.
*/
void setAESKey(uint8_t* key);
/*!
\brief Enables AES encryption.
\returns \ref status_codes
*/
int16_t enableAES();
/*!
\brief Disables AES encryption.
\returns \ref status_codes
*/
int16_t disableAES();
// interrupt methods
/*!
\brief Sets interrupt service routine to call when DIO0 activates.
\param func ISR to call.
*/
void setDio0Action(void (*func)(void));
/*!
\brief Clears interrupt service routine to call when DIO0 activates.
*/
void clearDio0Action();
/*!
\brief Sets interrupt service routine to call when DIO1 activates.
\param func ISR to call.
*/
void setDio1Action(void (*func)(void));
/*!
\brief Clears interrupt service routine to call when DIO1 activates.
*/
void clearDio1Action();
/*!
\brief Interrupt-driven binary transmit method.
Overloads for string-based transmissions are implemented in PhysicalLayer.
\param data Binary data to be sent.
\param len Number of bytes to send.
\param addr Address to send the data to. Will only be added if address filtering was enabled.
\returns \ref status_codes
*/
int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0) override;
/*!
\brief Interrupt-driven receive method. GDO0 will be activated when full packet is received.
\returns \ref status_codes
*/
int16_t startReceive();
/*!
\brief Reads data received after calling startReceive method.
\param data Pointer to array to save the received binary data.
\param len Number of bytes that will be read. When set to 0, the packet length will be retreived automatically.
When more bytes than received are requested, only the number of bytes requested will be returned.
\returns \ref status_codes
*/
int16_t readData(uint8_t* data, size_t len) override;
// configuration methods
/*!
\brief Sets carrier frequency. Allowed values are in bands 290.0 to 340.0 MHz, 431.0 to 510.0 MHz and 862.0 to 1020.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
/*!
\brief Sets bit rate. Allowed values range from 1.2 to 300.0 kbps.
\param br Bit rate to be set in kbps.
\returns \ref status_codes
*/
int16_t setBitRate(float br);
/*!
\brief Sets receiver bandwidth. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25.0, 31.3, 41.7, 50.0, 62.5, 83.3, 100.0, 125.0, 166.7, 200.0, 250.0, 333.3, 400.0 and 500.0 kHz.
\param rxBw Receiver bandwidth to be set in kHz.
\returns \ref status_codes
*/
int16_t setRxBandwidth(float rxBw);
/*!
\brief Sets frequency deviation.
\param freqDev Frequency deviation to be set in kHz.
\returns \ref status_codes
*/
int16_t setFrequencyDeviation(float freqDev) override;
/*!
\brief Sets output power. Allowed values range from -18 to 13 dBm for low power modules (RF69C/CW) or -2 to 20 dBm (RF69H/HC/HCW).
\param power Output power to be set in dBm.
\param highPower Set to true when using modules high power port (RF69H/HC/HCW). Defaults to false (models without high power port - RF69C/CW).
\returns \ref status_codes
*/
int16_t setOutputPower(int8_t power, bool highPower = false);
/*!
\brief Sets sync word. Up to 8 bytes can be set as sync word.
\param syncWord Pointer to the array of sync word bytes.
\param len Sync word length in bytes.
\param maxErrBits Maximum allowed number of bit errors in received sync word. Defaults to 0.
*/
int16_t setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits = 0);
/*!
\brief Sets preamble length.
\param preambleLen Preamble length to be set (in bits), allowed values: 16, 24, 32, 48, 64, 96, 128 and 192.
\returns \ref status_codes
*/
int16_t setPreambleLength(uint8_t preambleLen);
/*!
\brief Sets node address. Calling this method will also enable address filtering for node address only.
\param nodeAddr Node address to be set.
\returns \ref status_codes
*/
int16_t setNodeAddress(uint8_t nodeAddr);
/*!
\brief Sets broadcast address. Calling this method will also enable address filtering for node and broadcast address.
\param broadAddr Node address to be set.
\returns \ref status_codes
*/
int16_t setBroadcastAddress(uint8_t broadAddr);
/*!
\brief Disables address filtering. Calling this method will also erase previously set addresses.
\returns \ref status_codes
*/
int16_t disableAddressFiltering();
// measurement methods
/*!
\brief Sets ambient temperature. Required to correct values from on-board temperature sensor.
\param tempAmbient Ambient temperature in degrees Celsius.
*/
void setAmbientTemperature(int16_t tempAmbient);
/*!
\brief Measures temperature.
\returns Measured temperature in degrees Celsius.
*/
int16_t getTemperature();
/*!
\brief Query modem for the packet length of received payload.
\param update Update received packet length. Will return cached value when set to false.
\returns Length of last received packet in bytes.
*/
size_t getPacketLength(bool update = true) override;
/*!
\brief Enables/disables OOK modulation instead of FSK.
\param enableOOK Enable (true) or disable (false) OOK.
\returns \ref status_codes
*/
int16_t setOOK(bool enableOOK);
/*!
\brief Selects the type of threshold in the OOK data slicer
\param type Threshold type: RADIOLIB_RF69_OOK_THRESH_PEAK(default), RADIOLIB_RF69_OOK_THRESH_FIXED or RADIOLIB_RF69_OOK_THRESH_AVERAGE
\returns \ref status_codes
*/
int16_t setOokThresholdType(uint8_t type);
/*!
\brief Fixed threshold for the Data Slicer in OOK mode or floor threshold for the Data Slicer in OOK when Peak mode is used.
\param value Fixed threshold value (in dB) in the OOK demodulator. Used when OokThresType = RADIOLIB_RF69_OOK_THRESH_FIXED.
\returns \ref status_codes
*/
int16_t setOokFixedThreshold(uint8_t value);
/*!
\brief Period of decrement of the RSSI threshold in the OOK demodulator.
\param value Use defines RADIOLIB_RF69_OOK_PEAK_THRESH_DEC_X_X_CHIP
\returns \ref status_codes
*/
int16_t setOokPeakThresholdDecrement(uint8_t value);
/*!
\brief Set modem in fixed packet length mode.
\param len Packet length.
\returns \ref status_codes
*/
int16_t fixedPacketLengthMode(uint8_t len = RADIOLIB_RF69_MAX_PACKET_LENGTH);
/*!
\brief Set modem in variable packet length mode.
\param len Maximum packet length.
\returns \ref status_codes
*/
int16_t variablePacketLengthMode(uint8_t maxLen = RADIOLIB_RF69_MAX_PACKET_LENGTH);
/*!
\brief Enable sync word filtering and generation.
\param numBits Sync word length in bits.
\returns \ref status_codes
*/
int16_t enableSyncWordFiltering(uint8_t maxErrBits = 0);
/*!
\brief Disable preamble and sync word filtering and generation.
\returns \ref status_codes
*/
int16_t disableSyncWordFiltering();
/*!
\brief Enable Bit synchronization in continuous mode.
\returns \ref status_codes
*/
int16_t enableContinuousModeBitSync();
/*!
\brief Disable Bit synchronization in continuous mode.
\returns \ref status_codes
*/
int16_t disableContinuousModeBitSync();
/*!
\brief Enable CRC filtering and generation.
\param crcOn Set or unset CRC filtering.
\returns \ref status_codes
*/
int16_t setCrcFiltering(bool crcOn = true);
/*!
\brief Set modem in "sniff" mode: no packet filtering (e.g., no preamble, sync word, address, CRC).
\param promiscuous Set or unset promiscuous mode.
\returns \ref status_codes
*/
int16_t setPromiscuousMode(bool promiscuous = true);
/*!
\brief Sets Gaussian filter bandwidth-time product that will be used for data shaping.
Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.
\param sh Gaussian shaping bandwidth-time product that will be used for data shaping
\returns \ref status_codes
*/
int16_t setDataShaping(uint8_t sh) override;
/*!
\brief Sets transmission encoding.
Allowed values are RADIOLIB_ENCODING_NRZ, RADIOLIB_ENCODING_MANCHESTER and RADIOLIB_ENCODING_WHITENING.
\param encoding Encoding to be used.
\returns \ref status_codes
*/
int16_t setEncoding(uint8_t encoding) override;
/*!
\brief Enable/disable LNA Boost mode (disabled by default).
\param value True to enable, false to disable.
\returns \ref status_codes
*/
int16_t setLnaTestBoost(bool value);
/*!
\brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
\returns Last packet RSSI in dBm.
*/
float getRSSI();
/*!
\brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state.
When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch!
\param rxEn RX enable pin.
\param txEn TX enable pin.
*/
void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn);
/*!
\brief Get one truly random byte from RSSI noise.
\returns TRNG byte.
*/
uint8_t randomByte();
/*!
\brief Read version SPI register. Should return RF69_CHIP_VERSION (0x24) if SX127x is connected and working.
\returns Version register contents or \ref status_codes
*/
int16_t getChipVersion();
/*!
\brief Set interrupt service routine function to call when data bit is receveid in direct mode.
\param func Pointer to interrupt service routine.
*/
void setDirectAction(void (*func)(void));
/*!
\brief Function to read and process data bit in direct reception mode.
\param pin Pin on which to read.
*/
void readBit(RADIOLIB_PIN_TYPE pin);
#if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
protected:
#endif
Module* _mod;
#if !defined(RADIOLIB_GODMODE)
protected:
#endif
float _freq = 0;
float _br = 0;
float _rxBw = 0;
bool _ook = false;
int16_t _tempOffset = 0;
int8_t _power = 0;
size_t _packetLength = 0;
bool _packetLengthQueried = false;
uint8_t _packetLengthConfig = RADIOLIB_RF69_PACKET_FORMAT_VARIABLE;
bool _promiscuous = false;
uint8_t _syncWordLength = 2;
int16_t config();
int16_t directMode();
int16_t setPacketMode(uint8_t mode, uint8_t len);
#if !defined(RADIOLIB_GODMODE)
private:
#endif
int16_t setMode(uint8_t mode);
void clearIRQFlags();
void clearFIFO(size_t count);
};
#endif
#endif

View File

@ -0,0 +1,21 @@
#if !defined(_RADIOLIB_RFM22_H)
#define _RADIOLIB_RFM22_H
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_RFM2X)
#include "../../Module.h"
#include "../Si443x/Si443x.h"
#include "../Si443x/Si4432.h"
/*!
\class RFM22
\brief Only exists as alias for Si4432, since there seems to be no difference between %RFM22 and %Si4432 modules.
*/
RADIOLIB_TYPE_ALIAS(Si4432, RFM22);
#endif
#endif

View File

@ -0,0 +1,21 @@
#if !defined(_RADIOLIB_RFM23_H)
#define _RADIOLIB_RFM23_H
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_RFM2X)
#include "../../Module.h"
#include "../Si443x/Si443x.h"
#include "../Si443x/Si4431.h"
/*!
\class RFM23
\brief Only exists as alias for Si4431, since there seems to be no difference between %RFM23 and %Si4431 modules.
*/
RADIOLIB_TYPE_ALIAS(Si4431, RFM23);
#endif
#endif

View File

@ -0,0 +1,54 @@
#include "RFM95.h"
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
RFM95::RFM95(Module* mod) : SX1278(mod) {
}
int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
// execute common part
int16_t state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength);
if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
// SX127X_REG_VERSION might be set 0x12
state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength);
RADIOLIB_ASSERT(state);
} else if(state != RADIOLIB_ERR_NONE) {
// some other error
return(state);
}
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
RADIOLIB_DEBUG_PRINTLN(F("M\tRFM95"));
// configure publicly accessible settings
state = setBandwidth(bw);
RADIOLIB_ASSERT(state);
state = setFrequency(freq);
RADIOLIB_ASSERT(state);
state = setSpreadingFactor(sf);
RADIOLIB_ASSERT(state);
state = setCodingRate(cr);
RADIOLIB_ASSERT(state);
state = setOutputPower(power);
RADIOLIB_ASSERT(state);
state = setGain(gain);
return(state);
}
int16_t RFM95::setFrequency(float freq) {
RADIOLIB_CHECK_RANGE(freq, 862.0, 1020.0, RADIOLIB_ERR_INVALID_FREQUENCY);
// set frequency and if successful, save the new setting
int16_t state = SX127x::setFrequencyRaw(freq);
if(state == RADIOLIB_ERR_NONE) {
SX127x::_freq = freq;
}
return(state);
}
#endif

View File

@ -0,0 +1,79 @@
#if !defined(_RADIOLIB_RFM95_H)
#define _RADIOLIB_RFM95_H
#include "../../TypeDef.h"
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
#include "../../Module.h"
#include "../SX127x/SX127x.h"
#include "../SX127x/SX1278.h"
// SX127X_REG_VERSION
#define RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL 0x11
#define RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12
/*!
\class RFM95
\brief Derived class for %RFM95 modules. Overrides some methods from SX1278 due to different parameter ranges.
*/
class RFM95: public SX1278 {
public:
// constructor
/*!
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
*/
RFM95(Module* mod);
// basic methods
/*!
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
\param freq Carrier frequency in MHz. Allowed values range from 868.0 MHz to 915.0 MHz.
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
Allowed values range from 6 to 65535.
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
Set to 0 to enable automatic gain control (recommended).
\returns \ref status_codes
*/
int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
// configuration methods
/*!
\brief Sets carrier frequency. Allowed values range from 868.0 MHz to 915.0 MHz.
\param freq Carrier frequency to be set in MHz.
\returns \ref status_codes
*/
int16_t setFrequency(float freq);
#if !defined(RADIOLIB_GODMODE)
private:
#endif
};
#endif
#endif

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