LoRa

With regard to the processor modules discussed on this site, the Heltec WiFi LoRa nodes, Wireless Stick and Wireless Stick Lite, and the Elecrow ESP32S modules are all ESP32-based and so very similar at a software level. There are some minor differences between these and the earlier ESP8266 processor, and there are further minor differences between all of these and the Arduino Pro Mini ATMega processor.
The Heltec CubeCell modules are based on a different, integrated core architecture [ASR605x] with an on-board [LoRa/LoRaWAN] radio.
All of these processors, however, together with the HopeRF RFM95W module or their native radio as applicable, use one variant or another of the Semtech SX12xx series LoRa transceivers (generally the SX1276 or SX1262).
I am assuming that the reader has the Arduino IDE installed with all the software and libraries required for basic support of the processor boards that are being used. Over time, I have used several LoRa libraries on various hardware configurations. The library I originally used, the Sandeep Mistry LoRa library available through the Arduino IDE, was fine while it supported the radio modules I was using, essentially configurations of the SX1276. More recently, however, Heltec development boards, the CubeCell boards and the V3 & V4 versions of the WiFi LoRa 32, have used the SX1262 radio, which is not supported by this library.
With the introduction of the SX1262 radio, initially on the CubeCell platform, Heltec released their own LoRa/LoRaWAN support library, LoRaWan_APP. While I have used this latter library now quite extensively, it has proven problematic from time to time, primarily because Heltec's quality assurance testing seems to assume that users will always be using Heltec libraries when they are available. The issue here is all too frequent conflicts between Heltec and third party libraries when they should really have nothing to do with each other.
As a result, I tend to avoid using Heltec libraries where ever an alternative exists. To this end, I have just started using the RadioLib library for LoRa applications. Unfortunately, using a third party library comes with its own little challenges, highlighted by the release of the WiFi LoRa 32 V4 module, which includes an integrated RF power amplifier that must be managed independently of the radio. Heltec handles the relevant software details invisibly within its library, but the use of a third party library that is not aware of this hardware introduces some additional software management overheads. None of this is a real problem, the requirement simply needs to be recognised and addressed as discussed below.
Radio Configuration
Because this seems to be the most confusing part of getting different modules to communicate, I've extracted the relevant configuration paramaters for the different libraries I am currently using—the Sandeep Mistry LoRa library used with SX127x-based radios (Hope RFM95W and earlier Heltec ESP32 modules), the Heltec LoRa_APP or LoRaWan_APP library used for SX1262-based radios (Heltec ASR605x and ESP32-S3 modules) and, more recently, the RadioLib library, which can be used with any of the configurations described herein—and included them in a single header file LoRa915.h) that can be loaded with any sketch to provide a compatibile set of configuration parameters. These are simply the settings that I use in my current application, but they should provide a starting point for anyone trying to get different modules, which may not be using the same software libraries, communicating.
Note that, in some cases, libraries use different mechanisms to specify the same parameter. The Sandeep Mistry library, for example, identifies the signal bandwidth by its actual frequency, while the Heltec library identifies it by an index. In some cases frequency is specified in Hz and others as either KHz or MHz. Where this situation exists, both parameters are included—if either is modified, the other should also be to maintain compatibility.
#define Frequency 915E6 // Hz
#define FrequencyMHz 915.0 // MHz
#define SignalBandwidth 125E3 // Hz
#define SignalBandwidthKHz 125.0 // KHz
#define SignalBandwidthIndex 0 // 0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved
#define SpreadingFactor 8 // SF7..SF12
#define CodingRate 1 // 1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8
#define CodingRateDenominator 5
#define PreambleLength 8 // Same for Tx and Rx
#define SyncWord 0x12
#define OutputPower 14 // dBm
#define SymbolTimeout 0 // Symbols
#define FixedLengthPayload false
#define IQInversion false
Sandeep Mistry LoRa Parameter Usage
Load the Sandeep Mistry LoRa library through the Arduino IDE Library Manager and include the following in the relevant sketch:
#include <LoRa.h>
#include <LoRa915.h>
// Include definitions for the processor pins being used
// for the SPI/RFM95 interface (SCK, MISO, MOSI, NSS, RST, DI0)
void setup() {
// Initialise the RFM95 radio
SPI.begin(SCK, MISO, MOSI, NSS);
LoRa.setPins(NSS, RST, DI0);
Serial.println("[setup] Activate LoRa Sender");
if (!LoRa.begin(Frequency)) {
Serial.println("[setup] Starting LoRa failed!");
while (true);
}
Serial.print("[setup] LoRa Frequency: ");
Serial.println(Frequency);
LoRa.begin(Frequency);
LoRa.setSpreadingFactor(SpreadingFactor);
LoRa.setSignalBandwidth(SignalBandwidth);
LoRa.setPreambleLength(PreambleLength);
LoRa.setCodingRate4(CodingRateDenominator);
LoRa.setSyncWord(SyncWord);
LoRa.disableCrc();
Serial.println("[setup] LoRa initialisation complete");
}
Heltec LoRa Parameter Usage
The Heltec [LoRa_APP/LoRaWan_APP] library supports the Semtech SX1262 LoRa node chip, which is used in the Heltec CubeCell series and the ESP32-S3-based development boards (WiFi LoRa 32 V3 and Wireless Stick [Lite] V3). Download the Heltec hardware support libraries from GitHub and include the following in the relevant sketch:
#include <LoRaWan_APP.h>
#include <LoRa915.h>
// I used to use <LoRa_APP.h> but that subset of the LoRaWAN_APP library
// only seems to be available for the CubeCell boards and not the ESP32-S3
static RadioEvents_t RadioEvents;
void onTxDone(void) {
Serial.println("[onTxDone] TX done!");
// Add whatever code needs to be executed when transmission is complete
}
void onTxTimeout(void) {
Serial.println("[onTxTimeout] TX Timeout...");
// Add whatever code needs to be executed on transmission timeout
}
void OnRxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) {
Serial.println("[onRxDone] RX done!");
Radio.Sleep();
// Add code to process the payload
}
void setup() {
// Initialise the radio
RadioEvents.TxDone = onTxDone;
RadioEvents.TxTimeout = onTxTimeout;
RadioEvents.RxDone = OnRxDone;
Radio.Init(&RadioEvents);
Radio.SetChannel(Frequency);
Radio.SetTxConfig(MODEM_LORA, OutputPower, 0, SignalBandwidthIndex,
SpreadingFactor, CodingRate,
PreambleLength, FixedLengthPayload,
true, 0, 0, IQInversion, 3000);
Radio.SetRxConfig(MODEM_LORA, SignalBandwidthIndex, SpreadingFactor,
CodingRate, 0, PreambleLength,
SymbolTimeout, FixedLengthPayload,
0, true, 0, 0, IQInversion, true);
Serial.println("[setup] LoRa initialisation complete");
}
The main compatibility issue that seems to arise when attempting to interoperate between devices using these two different LoRa libraries is in the setting of the SyncWord. The SyncWord setting in the Heltec LoRa library is defined in the LoRaMac.h file as:
|
There does not appear to be any way to change this other than by modification of the #define statement in the LoRaMac.h file. It is therefore important to be sure to set the SyncWord [usually to 0x12] when using any other library in a communicating node.
The reader will need to download actual sketches (see elsewhere on this site) if a deeper understanding of the context of the above code is required. As I work through refining the various software sketches, I will include more comprehensive documentation on other code elements.
RadioLib LoRa Parameter Usage
The RadioLib library supports both of the Semtech LoRa node chips, the SX1262 and SX1276, used in the various hardware configurations that I have used, although, to date, I've only actually used it on the WiFi LoRa 32 V3 and V4 (SX1262) modules. Note, however, the additional steps required to use the GC1109 power amplifier on the WiFI LoRa 32 V4 module (these steps are effectively hidden from the user when using the Heltec library). On the upside, the fact that the three additional pins used in this case, GPIO2, GPIO7 and GPIO46, would not be available for other purposes, is now quite clear from the need to explicitly define and assign them to their respective functions.
To use this library, download the RadioLib library from GitHub and include the following in the relevant sketch:
#include <RadioLib.h>
#include <LoRa915.h>
#if defined(HELTEC_WIFI_LORA_32_V4)
#define LORA_PA_POWER 7
#define LORA_PA_EN 2
#define LORA_PA_TX_EN 46
#endif
// For WiFi LoRa 32 V3 & V4 SX1262
#define NSS 8
#define DIO1 14
#define RST 12
#define BUSY 13
SX1262 radio = new Module(NSS, DIO1, RST, BUSY);
void setup() {
#if defined(HELTEC_WIFI_LORA_32_V4)
// Enable the power amplifier
pinMode(LORA_PA_POWER,OUTPUT);
digitalWrite(LORA_PA_POWER,HIGH);
pinMode(LORA_PA_EN,OUTPUT);
digitalWrite(LORA_PA_EN,HIGH);
pinMode(LORA_PA_TX_EN,OUTPUT);
digitalWrite(LORA_PA_TX_EN,HIGH);
delay(2);
#endif
Serial.print("[setup] SX1262 initializing ... ");
int radioState = radio.begin(FrequencyMHz, SignalBandwidthKHz, SpreadingFactor, CodingRateDenominator, SyncWord, OutputPower, PreambleLength);
if (radioState == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(radioState);
while (true) { delay(10); }
}
Serial.println("[setup] LoRa initialisation complete");
Serial.println();
}
