Update LoRaLib examples

This commit is contained in:
lewisxhe 2024-08-03 14:19:31 +08:00
commit b7b4d0e944
2 changed files with 68 additions and 2 deletions

View file

@ -2,6 +2,21 @@
#include <LoRa.h>
#include "LoRaBoards.h"
#ifndef CONFIG_RADIO_FREQ
#define CONFIG_RADIO_FREQ 868.0
#endif
#ifndef CONFIG_RADIO_OUTPUT_POWER
#define CONFIG_RADIO_OUTPUT_POWER 17
#endif
#ifndef CONFIG_RADIO_BW
#define CONFIG_RADIO_BW 125.0
#endif
#if !defined(USING_SX1276) && !defined(USING_SX1278)
#error "LoRa example is only allowed to run SX1276/78. For other RF models, please run examples/RadioLibExamples
#endif
void setup()
{
setupBoards();
@ -16,10 +31,30 @@ void setup()
#endif
LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DIO0_PIN);
if (!LoRa.begin(LORA_FREQ_CONFIG)) {
if (!LoRa.begin(CONFIG_RADIO_FREQ * 1000000)) {
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setTxPower(CONFIG_RADIO_OUTPUT_POWER);
LoRa.setSignalBandwidth(CONFIG_RADIO_BW * 1000);
LoRa.setSpreadingFactor(10);
LoRa.setPreambleLength(16);
LoRa.setSyncWord(0xAB);
LoRa.disableCrc();
LoRa.disableInvertIQ();
LoRa.setCodingRate4(7);
// put the radio into receive mode
LoRa.receive();
}
void loop()

View file

@ -2,6 +2,21 @@
#include <LoRa.h>
#include "LoRaBoards.h"
#ifndef CONFIG_RADIO_FREQ
#define CONFIG_RADIO_FREQ 868.0
#endif
#ifndef CONFIG_RADIO_OUTPUT_POWER
#define CONFIG_RADIO_OUTPUT_POWER 17
#endif
#ifndef CONFIG_RADIO_BW
#define CONFIG_RADIO_BW 125.0
#endif
#if !defined(USING_SX1276) && !defined(USING_SX1278)
#error "LoRa example is only allowed to run SX1276/78. For other RF models, please run examples/RadioLibExamples
#endif
int counter = 0;
void setup()
@ -17,10 +32,26 @@ void setup()
Serial.println("LoRa Sender");
LoRa.setPins(RADIO_CS_PIN, RADIO_RST_PIN, RADIO_DIO0_PIN);
if (!LoRa.begin(LORA_FREQ_CONFIG)) {
if (!LoRa.begin(CONFIG_RADIO_FREQ * 1000000)) {
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setTxPower(CONFIG_RADIO_OUTPUT_POWER);
LoRa.setSignalBandwidth(CONFIG_RADIO_BW * 1000);
LoRa.setSpreadingFactor(10);
LoRa.setPreambleLength(16);
LoRa.setSyncWord(0xAB);
LoRa.disableCrc();
LoRa.disableInvertIQ();
LoRa.setCodingRate4(7);
}
void loop()