[SX126x] Updated examples
This commit is contained in:
parent
076b111e6c
commit
98f60dd092
7 changed files with 126 additions and 46 deletions
|
@ -1,20 +1,31 @@
|
||||||
/*
|
/*
|
||||||
RadioLib SX126x Channel Activity Detection Example
|
RadioLib SX126x Channel Activity Detection Example
|
||||||
|
|
||||||
This example scans the current LoRa channel and detects
|
This example scans the current LoRa channel and detects
|
||||||
valid LoRa preambles. Preamble is the first part of
|
valid LoRa preambles. Preamble is the first part of
|
||||||
LoRa transmission, so this can be used to check
|
LoRa transmission, so this can be used to check
|
||||||
if the LoRa channel is free, or if you should start
|
if the LoRa channel is free, or if you should start
|
||||||
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);
|
||||||
|
|
|
@ -2,19 +2,30 @@
|
||||||
RadioLib SX126x FSK Modem Example
|
RadioLib SX126x FSK Modem Example
|
||||||
|
|
||||||
This example shows how to use FSK modem in SX126x chips.
|
This example shows how to use FSK modem in SX126x chips.
|
||||||
|
|
||||||
NOTE: The sketch below is just a guide on how to use
|
NOTE: The sketch below is just a guide on how to use
|
||||||
FSK modem, so this code should not be run directly!
|
FSK modem, so this code should not be run directly!
|
||||||
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);
|
||||||
|
@ -45,7 +56,7 @@ void setup() {
|
||||||
// lora.begin() start LoRa mode (and disable FSK)
|
// lora.begin() start LoRa mode (and disable FSK)
|
||||||
// lora.beginFSK() start FSK mode (and disable LoRa)
|
// lora.beginFSK() start FSK mode (and disable LoRa)
|
||||||
|
|
||||||
// the following settings can also
|
// the following settings can also
|
||||||
// be modified at run-time
|
// be modified at run-time
|
||||||
state = fsk.setFrequency(433.5);
|
state = fsk.setFrequency(433.5);
|
||||||
state = fsk.setBitRate(100.0);
|
state = fsk.setBitRate(100.0);
|
||||||
|
@ -54,7 +65,7 @@ void setup() {
|
||||||
state = fsk.setOutputPower(10.0);
|
state = fsk.setOutputPower(10.0);
|
||||||
state = fsk.setCurrentLimit(100.0);
|
state = fsk.setCurrentLimit(100.0);
|
||||||
state = fsk.setDataShaping(1.0);
|
state = fsk.setDataShaping(1.0);
|
||||||
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67,
|
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67,
|
||||||
0x89, 0xAB, 0xCD, 0xEF};
|
0x89, 0xAB, 0xCD, 0xEF};
|
||||||
state = fsk.setSyncWord(syncWord, 8);
|
state = fsk.setSyncWord(syncWord, 8);
|
||||||
if (state != ERR_NONE) {
|
if (state != ERR_NONE) {
|
||||||
|
@ -75,7 +86,7 @@ void setup() {
|
||||||
void loop() {
|
void loop() {
|
||||||
// FSK modem can use the same transmit/receive methods
|
// FSK modem can use the same transmit/receive methods
|
||||||
// as the LoRa modem, even their interrupt-driven versions
|
// as the LoRa modem, even their interrupt-driven versions
|
||||||
|
|
||||||
// transmit FSK packet
|
// transmit FSK packet
|
||||||
int state = fsk.transmit("Hello World!");
|
int state = fsk.transmit("Hello World!");
|
||||||
/*
|
/*
|
||||||
|
@ -116,7 +127,7 @@ void loop() {
|
||||||
// it can be enabled by setting node address, broadcast
|
// it can be enabled by setting node address, broadcast
|
||||||
// address, or both
|
// address, or both
|
||||||
//
|
//
|
||||||
// to transmit packet to a particular address,
|
// to transmit packet to a particular address,
|
||||||
// use the following methods:
|
// use the following methods:
|
||||||
//
|
//
|
||||||
// fsk.transmit("Hello World!", address);
|
// fsk.transmit("Hello World!", address);
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -14,28 +14,31 @@
|
||||||
- preamble length
|
- preamble length
|
||||||
- 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