[SX126x] Updated examples
This commit is contained in:
parent
076b111e6c
commit
98f60dd092
7 changed files with 126 additions and 46 deletions
examples/SX126x
SX126x_Channel_Activity_Detection
SX126x_FSK_Modem
SX126x_Receive
SX126x_Receive_Interrupt
SX126x_Settings
SX126x_Transmit
SX126x_Transmit_Interrupt
|
@ -8,13 +8,24 @@
|
||||||
receiving a message.
|
receiving a message.
|
||||||
|
|
||||||
Other modules from SX126x family can also be used.
|
Other modules from SX126x family can also be used.
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// SX1262 module is in slot A on the shield
|
// SX1262 has the following connections:
|
||||||
SX1262 lora = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO1 pin: 2
|
||||||
|
// DIO2 pin: 3
|
||||||
|
// BUSY pin: 9
|
||||||
|
SX1262 lora = new Module(10, 2, 3, 9);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//SX1262 lora = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
|
@ -8,13 +8,24 @@
|
||||||
Instead, modify the other examples to use FSK
|
Instead, modify the other examples to use FSK
|
||||||
modem and use the appropriate configuration
|
modem and use the appropriate configuration
|
||||||
methods.
|
methods.
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// SX1262 module is in slot A on the shield
|
// SX1262 has the following connections:
|
||||||
SX1262 fsk = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO1 pin: 2
|
||||||
|
// DIO2 pin: 3
|
||||||
|
// BUSY pin: 9
|
||||||
|
SX1262 fsk = new Module(10, 2, 3, 9);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//SX1262 fsk = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
|
@ -12,13 +12,24 @@
|
||||||
- preamble length
|
- preamble length
|
||||||
|
|
||||||
Other modules from SX126x family can also be used.
|
Other modules from SX126x family can also be used.
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// SX1262 module is in slot A on the shield
|
// SX1262 has the following connections:
|
||||||
SX1262 lora = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO1 pin: 2
|
||||||
|
// DIO2 pin: 3
|
||||||
|
// BUSY pin: 9
|
||||||
|
SX1262 lora = new Module(10, 2, 3, 9);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//SX1262 lora = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -88,5 +99,10 @@ void loop() {
|
||||||
// packet was received, but is malformed
|
// packet was received, but is malformed
|
||||||
Serial.println(F("CRC error!"));
|
Serial.println(F("CRC error!"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// some other error occurred
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,24 @@
|
||||||
- sync word
|
- sync word
|
||||||
|
|
||||||
Other modules from SX126x/RFM9x family can also be used.
|
Other modules from SX126x/RFM9x family can also be used.
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// SX1262 module is in slot A on the shield
|
// SX1262 has the following connections:
|
||||||
SX1262 lora = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO1 pin: 2
|
||||||
|
// DIO2 pin: 3
|
||||||
|
// BUSY pin: 9
|
||||||
|
SX1262 lora = new Module(10, 2, 3, 9);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//SX1262 lora = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -131,6 +142,11 @@ void loop() {
|
||||||
// packet was received, but is malformed
|
// packet was received, but is malformed
|
||||||
Serial.println(F("CRC error!"));
|
Serial.println(F("CRC error!"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// some other error occurred
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// we're ready to receive more packets,
|
// we're ready to receive more packets,
|
||||||
|
|
|
@ -15,27 +15,30 @@
|
||||||
- TCXO voltage
|
- TCXO voltage
|
||||||
|
|
||||||
Other modules from SX126x family can also be used.
|
Other modules from SX126x family can also be used.
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// SX1268 module is in slot A on the shield
|
// SX1262 has the following connections:
|
||||||
SX1268 loraSX1268 = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO1 pin: 2
|
||||||
|
// DIO2 pin: 3
|
||||||
|
// BUSY pin: 9
|
||||||
|
SX1262 loraSX1262 = new Module(10, 2, 3, 9);
|
||||||
|
|
||||||
// if you're not using RadioShield, you can specify
|
// or using RadioShield
|
||||||
// the connection yourself
|
// https://github.com/jgromes/RadioShield
|
||||||
// NSS pin: 6
|
SX1268 loraSX1268 = RadioShield.ModuleB;
|
||||||
// DIO1 pin: 4
|
|
||||||
// DIO2 pin: 5
|
|
||||||
// BUSY pin: 7
|
|
||||||
SX1262 loraSX1262 = new Module(6, 4, 5, 7);
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// initialize SX1268 with default settings
|
// initialize SX1268 with default settings
|
||||||
Serial.print(F("[SX1268] Initializing ... "));
|
Serial.print(F("[SX1262] Initializing ... "));
|
||||||
// carrier frequency: 434.0 MHz
|
// carrier frequency: 434.0 MHz
|
||||||
// bandwidth: 125.0 kHz
|
// bandwidth: 125.0 kHz
|
||||||
// spreading factor: 9
|
// spreading factor: 9
|
||||||
|
@ -45,7 +48,7 @@ void setup() {
|
||||||
// current limit: 60 mA
|
// current limit: 60 mA
|
||||||
// preamble length: 8 symbols
|
// preamble length: 8 symbols
|
||||||
// CRC: enabled
|
// CRC: enabled
|
||||||
int state = loraSX1268.begin();
|
int state = loraSX1262.begin();
|
||||||
if (state == ERR_NONE) {
|
if (state == ERR_NONE) {
|
||||||
Serial.println(F("success!"));
|
Serial.println(F("success!"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -58,7 +61,7 @@ void setup() {
|
||||||
// non-default settings
|
// non-default settings
|
||||||
// this LoRa link will have high data rate,
|
// this LoRa link will have high data rate,
|
||||||
// but lower range
|
// but lower range
|
||||||
Serial.print(F("[SX1262] Initializing ... "));
|
Serial.print(F("[SX1268] Initializing ... "));
|
||||||
// carrier frequency: 915.0 MHz
|
// carrier frequency: 915.0 MHz
|
||||||
// bandwidth: 500.0 kHz
|
// bandwidth: 500.0 kHz
|
||||||
// spreading factor: 6
|
// spreading factor: 6
|
||||||
|
@ -68,7 +71,7 @@ void setup() {
|
||||||
// current limit: 50 mA
|
// current limit: 50 mA
|
||||||
// preamble length: 20 symbols
|
// preamble length: 20 symbols
|
||||||
// CRC: enabled
|
// CRC: enabled
|
||||||
state = loraSX1262.begin(915.0, 500.0, 6, 5, 0x3444, 50, 20);
|
state = loraSX1268.begin(915.0, 500.0, 6, 5, 0x3444, 50, 20);
|
||||||
if (state == ERR_NONE) {
|
if (state == ERR_NONE) {
|
||||||
Serial.println(F("success!"));
|
Serial.println(F("success!"));
|
||||||
} else {
|
} else {
|
||||||
|
@ -81,64 +84,64 @@ void setup() {
|
||||||
// and check if the configuration was changed successfully
|
// and check if the configuration was changed successfully
|
||||||
|
|
||||||
// set carrier frequency to 433.5 MHz
|
// set carrier frequency to 433.5 MHz
|
||||||
if (loraSX1268.setFrequency(433.5) == ERR_INVALID_FREQUENCY) {
|
if (loraSX1262.setFrequency(433.5) == ERR_INVALID_FREQUENCY) {
|
||||||
Serial.println(F("Selected frequency is invalid for this module!"));
|
Serial.println(F("Selected frequency is invalid for this module!"));
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set bandwidth to 250 kHz
|
// set bandwidth to 250 kHz
|
||||||
if (loraSX1268.setBandwidth(250.0) == ERR_INVALID_BANDWIDTH) {
|
if (loraSX1262.setBandwidth(250.0) == ERR_INVALID_BANDWIDTH) {
|
||||||
Serial.println(F("Selected bandwidth is invalid for this module!"));
|
Serial.println(F("Selected bandwidth is invalid for this module!"));
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set spreading factor to 10
|
// set spreading factor to 10
|
||||||
if (loraSX1268.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) {
|
if (loraSX1262.setSpreadingFactor(10) == ERR_INVALID_SPREADING_FACTOR) {
|
||||||
Serial.println(F("Selected spreading factor is invalid for this module!"));
|
Serial.println(F("Selected spreading factor is invalid for this module!"));
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set coding rate to 6
|
// set coding rate to 6
|
||||||
if (loraSX1268.setCodingRate(6) == ERR_INVALID_CODING_RATE) {
|
if (loraSX1262.setCodingRate(6) == ERR_INVALID_CODING_RATE) {
|
||||||
Serial.println(F("Selected coding rate is invalid for this module!"));
|
Serial.println(F("Selected coding rate is invalid for this module!"));
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set LoRa sync word to 0x1234
|
// set LoRa sync word to 0x1234
|
||||||
if (loraSX1268.setSyncWord(0x1234) != ERR_NONE) {
|
if (loraSX1262.setSyncWord(0x1234) != ERR_NONE) {
|
||||||
Serial.println(F("Unable to set sync word!"));
|
Serial.println(F("Unable to set sync word!"));
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set output power to 10 dBm (accepted range is -17 - 22 dBm)
|
// set output power to 10 dBm (accepted range is -17 - 22 dBm)
|
||||||
if (loraSX1268.setOutputPower(10) == ERR_INVALID_OUTPUT_POWER) {
|
if (loraSX1262.setOutputPower(10) == ERR_INVALID_OUTPUT_POWER) {
|
||||||
Serial.println(F("Selected output power is invalid for this module!"));
|
Serial.println(F("Selected output power is invalid for this module!"));
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set over current protection limit to 80 mA (accepted range is 45 - 240 mA)
|
// set over current protection limit to 80 mA (accepted range is 45 - 240 mA)
|
||||||
// NOTE: set value to 0 to disable overcurrent protection
|
// NOTE: set value to 0 to disable overcurrent protection
|
||||||
if (loraSX1268.setCurrentLimit(80) == ERR_INVALID_CURRENT_LIMIT) {
|
if (loraSX1262.setCurrentLimit(80) == ERR_INVALID_CURRENT_LIMIT) {
|
||||||
Serial.println(F("Selected current limit is invalid for this module!"));
|
Serial.println(F("Selected current limit is invalid for this module!"));
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set LoRa preamble length to 15 symbols (accepted range is 0 - 65535)
|
// set LoRa preamble length to 15 symbols (accepted range is 0 - 65535)
|
||||||
if (loraSX1268.setPreambleLength(15) == ERR_INVALID_PREAMBLE_LENGTH) {
|
if (loraSX1262.setPreambleLength(15) == ERR_INVALID_PREAMBLE_LENGTH) {
|
||||||
Serial.println(F("Selected preamble length is invalid for this module!"));
|
Serial.println(F("Selected preamble length is invalid for this module!"));
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable CRC
|
// disable CRC
|
||||||
if (loraSX1268.setCRC(false) == ERR_INVALID_CRC_CONFIGURATION) {
|
if (loraSX1262.setCRC(false) == ERR_INVALID_CRC_CONFIGURATION) {
|
||||||
Serial.println(F("Selected CRC is invalid for this module!"));
|
Serial.println(F("Selected CRC is invalid for this module!"));
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some SX126x have TCXO (temperature compensated crystal
|
// Some SX126x modules have TCXO (temperature compensated crystal
|
||||||
// oscillator). To configure TCXO reference voltage,
|
// oscillator). To configure TCXO reference voltage,
|
||||||
// the following method can be used.
|
// the following method can be used.
|
||||||
if (loraSX1268.setTCXO(2.4) == ERR_INVALID_TCXO_VOLTAGE) {
|
if (loraSX1262.setTCXO(2.4) == ERR_INVALID_TCXO_VOLTAGE) {
|
||||||
Serial.println(F("Selected TCXO voltage is invalid for this module!"));
|
Serial.println(F("Selected TCXO voltage is invalid for this module!"));
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,24 @@
|
||||||
- arbitrary binary data (byte array)
|
- arbitrary binary data (byte array)
|
||||||
|
|
||||||
Other modules from SX126x family can also be used.
|
Other modules from SX126x family can also be used.
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// SX1262 module is in slot A on the shield
|
// SX1262 has the following connections:
|
||||||
SX1262 lora = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO1 pin: 2
|
||||||
|
// DIO2 pin: 3
|
||||||
|
// BUSY pin: 9
|
||||||
|
SX1262 lora = new Module(10, 2, 3, 9);
|
||||||
|
|
||||||
|
// or using RadioShield
|
||||||
|
// https://github.com/jgromes/RadioShield
|
||||||
|
//SX1262 lora = RadioShield.ModuleA;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -94,6 +105,11 @@ void loop() {
|
||||||
// timeout occured while transmitting packet
|
// timeout occured while transmitting packet
|
||||||
Serial.println(F(" timeout!"));
|
Serial.println(F(" timeout!"));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// some other error occurred
|
||||||
|
Serial.print(F("failed, code "));
|
||||||
|
Serial.println(state);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for a second before transmitting again
|
// wait for a second before transmitting again
|
||||||
|
|
|
@ -9,13 +9,20 @@
|
||||||
- arbitrary binary data (byte array)
|
- arbitrary binary data (byte array)
|
||||||
|
|
||||||
Other modules from SX126x family can also be used.
|
Other modules from SX126x family can also be used.
|
||||||
|
|
||||||
|
For full API reference, see the GitHub Pages
|
||||||
|
https://jgromes.github.io/RadioLib/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// include the library
|
// include the library
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
// SX1262 module is in slot A on the shield
|
// SX1262 has the following connections:
|
||||||
SX1262 lora = RadioShield.ModuleA;
|
// NSS pin: 10
|
||||||
|
// DIO1 pin: 2
|
||||||
|
// DIO2 pin: 3
|
||||||
|
// BUSY pin: 9
|
||||||
|
SX1262 lora = new Module(10, 2, 3, 9);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
Loading…
Add table
Reference in a new issue