the example code of post 5 used a grove-E5 LoRa module as a receiver and a Heltec ESP32 LoRa (V2) SX1278 transmitter
the following uses a grove-E5 LoRa module connected to an ESP32 using the LoRaE5 library as a transmitter
// grove-E5 LoRa module connected to an ESP32 using the LoRaE5 library transmitter
// library https://github.com/idreamsi/LoRaE5/tree/main
// example p2p_rtx.ino from https://github.com/idreamsi/LoRaE5
#include <LoRaE5.h>
unsigned char buffer[128] = {0xef, 0xff, 0x55, 3, 4, 5, 6, 7, 8, 9,};
#define GROVE_TX 15//21
#define GROVE_RX 16//20
void setup(void)
{
SerialUSB.begin(115200);
lora.init(GROVE_RX, GROVE_TX);
lora.init();
char id[200]={0};
char version[50]={0};
lora.getVersion(version, 50);
Serial.printf("Version = %s \n",version);
lora.getId(id, 200);
Serial.printf("ID = %s\n", id);
// lora.initP2PMode(866, SF7, BW125, 12, 8, 8);
lora.initP2PMode(866, SF7, BW125, 8, 8);
// lora.initP2PMode(866, SF12, BW125, 12, 15, 14);
}
void loop(void)
{
lora.transferPacketP2PMode("Hello World!");
SerialUSB.println("Send string.");
delay(3000);
lora.transferPacketP2PMode(buffer, 10);
SerialUSB.println("Send hex.");
delay(3000);
}
Heltec ESP32S3 LoRa (V3) SX1262 receiver code
// Heltec ESP32S3 LoRa (V3) SX1262 receiver
/*******************************************************************************************************
Programs for Arduino - Copyright of the author Stuart Robinson - 04/04/20
This program is supplied as is, it is up to the user of the program to decide if the program is
suitable for the intended purpose and free from errors.
*******************************************************************************************************/
/*******************************************************************************************************
Program Operation - This is a program that demonstrates the detailed setup of a LoRa test receiver.
The program listens for incoming packets using the LoRa settings in the 'Settings.h' file. The pins
to access the lora device need to be defined in the 'Settings.h' file also.
There is a printout on the Arduino IDE Serial Monitor of the valid packets received, the packet is
assumed to be in ASCII printable text, if it's not ASCII text characters from 0x20 to 0x7F, expect
weird things to happen on the Serial Monitor. The LED will flash for each packet received and the
buzzer will sound, if fitted.
Sample serial monitor output;
7s Hello World 1234567890*,CRC,DAAB,RSSI,-52dBm,SNR,9dB,Length,23,Packets,5,Errors,0,IRQreg,50
If there is a packet error it might look like this, which is showing a CRC error,
968s PacketError,RSSI,-87dBm,SNR,-11dB,Length,23,Packets,613,Errors,2,IRQreg,70,IRQ_HEADER_VALID,IRQ_CRC_ERROR,IRQ_RX_DONE
Serial monitor baud rate is set at 9600.
*******************************************************************************************************/
#include <SPI.h> //the lora device is SPI based so load the SPI library
#include <SX126XLT.h> //include the appropriate library
#include "Settings.h" //include the setiings file, frequencies, LoRa settings etc
SX126XLT LT; //create a library class instance called LT
uint32_t RXpacketCount;
uint32_t errors;
uint8_t RXBUFFER[RXBUFFER_SIZE]; //create the buffer that received packets are copied into
uint8_t RXPacketL; //stores length of packet received
int8_t PacketRSSI; //stores RSSI of received packet
int8_t PacketSNR; //stores signal to noise ratio (SNR) of received packet
void loop()
{
RXPacketL = LT.receive(RXBUFFER, RXBUFFER_SIZE, 60000, WAIT_RX); //wait for a packet to arrive with 60seconds (60000mS) timeout
digitalWrite(LED1, HIGH); //something has happened
PacketRSSI = LT.readPacketRSSI(); //read the recived RSSI value
PacketSNR = LT.readPacketSNR(); //read the received SNR value
if (RXPacketL == 0) //if the LT.receive() function detects an error, RXpacketL is 0
{
packet_is_Error();
}
else
{
packet_is_OK();
}
digitalWrite(LED1, LOW); //LED off
Serial.println();
}
void packet_is_OK()
{
uint16_t IRQStatus, localCRC;
IRQStatus = LT.readIrqStatus(); //read the LoRa device IRQ status register
RXpacketCount++;
printElapsedTime(); //print elapsed time to Serial Monitor
Serial.print(F(" "));
LT.printASCIIPacket(RXBUFFER, RXPacketL); //print the packet as ASCII characters
localCRC = LT.CRCCCITT(RXBUFFER, RXPacketL, 0xFFFF); //calculate the CRC, this is the external CRC calculation of the RXBUFFER
Serial.print(F(",CRC,")); //contents, not the LoRa device internal CRC
Serial.print(localCRC, HEX);
Serial.print(F(",RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB,Length,"));
Serial.print(RXPacketL);
Serial.print(F(",Packets,"));
Serial.print(RXpacketCount);
Serial.print(F(",Errors,"));
Serial.print(errors);
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX);
}
void packet_is_Error()
{
uint16_t IRQStatus;
IRQStatus = LT.readIrqStatus(); //read the LoRa device IRQ status register
printElapsedTime(); //print elapsed time to Serial Monitor
if (IRQStatus & IRQ_RX_TIMEOUT) //check for an RX timeout
{
Serial.print(F(" RXTimeout"));
}
else
{
errors++;
Serial.print(F(" PacketError"));
Serial.print(F(",RSSI,"));
Serial.print(PacketRSSI);
Serial.print(F("dBm,SNR,"));
Serial.print(PacketSNR);
Serial.print(F("dB,Length,"));
Serial.print(LT.readRXPacketL()); //get the device packet length
Serial.print(F(",Packets,"));
Serial.print(RXpacketCount);
Serial.print(F(",Errors,"));
Serial.print(errors);
Serial.print(F(",IRQreg,"));
Serial.print(IRQStatus, HEX);
LT.printIrqStatus(); //print the names of the IRQ registers set
}
delay(250); //gives a longer buzzer and LED flash for error
}
void printElapsedTime()
{
float seconds;
seconds = millis() / 1000;
Serial.print(seconds, 0);
Serial.print(F("s"));
}
void led_Flash(uint16_t flashes, uint16_t delaymS)
{
uint16_t index;
for (index = 1; index <= flashes; index++)
{
digitalWrite(LED1, HIGH);
delay(delaymS);
digitalWrite(LED1, LOW);
delay(delaymS);
}
}
void setup()
{
pinMode(LED1, OUTPUT); //setup pin as output for indicator LED
led_Flash(2, 125); //two quick LED flashes to indicate program start
Serial.begin(115200);
delay(3000);
Serial.println();
Serial.println(F("104_LoRa_Receiver_Detailed_Setup_ESP32 Starting"));
Serial.println();
SPI.begin();
//SPI.begin(SCK, MISO, MOSI); //this will work too, allows you to move SPI pins
//SPI beginTranscation is normally part of library routines, but if it is disabled in the library
//a single instance is needed here, so uncomment the program line below
//SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
//setup hardware pins used by device, then check if device is found
if (LT.begin(NSS, NRESET, RFBUSY, DIO1, LORA_DEVICE))
{
Serial.println(F("LoRa Device found"));
led_Flash(2, 125);
delay(1000);
}
else
{
Serial.println(F("No device responding"));
while (1)
{
led_Flash(50, 50); //long fast speed LED flash indicates device error
}
}
//The function call list below shows the complete setup for the LoRa device using the information defined in the
//Settings.h file.
//The 'Setup LoRa device' list below can be replaced with a single function call;
//LT.setupLoRa(Frequency, Offset, SpreadingFactor, Bandwidth, CodeRate, Optimisation);
//***************************************************************************************************
//Setup LoRa device
//***************************************************************************************************
LT.setMode(MODE_STDBY_RC);
LT.setRegulatorMode(USE_DCDC);
LT.setPaConfig(0x04, PAAUTO, LORA_DEVICE);
LT.setDIO3AsTCXOCtrl(TCXO_CTRL_3_3V);
LT.calibrateDevice(ALLDevices); //is required after setting TCXO
LT.calibrateImage(Frequency);
LT.setDIO2AsRfSwitchCtrl();
LT.setPacketType(PACKET_TYPE_LORA);
LT.setRfFrequency(Frequency, Offset);
LT.setModulationParams(SpreadingFactor, Bandwidth, CodeRate, Optimisation);
LT.setBufferBaseAddress(0, 0);
LT.setPacketParams(8, LORA_PACKET_VARIABLE_LENGTH, 255, LORA_CRC_ON, LORA_IQ_NORMAL);
LT.setDioIrqParams(IRQ_RADIO_ALL, (IRQ_RX_DONE + IRQ_RX_TX_TIMEOUT), 0, 0); //set for IRQ on TX done and timeout on DIO1
LT.setHighSensitivity(); //set for maximum gain
LT.setSyncWord(LORA_MAC_PRIVATE_SYNCWORD);
//***************************************************************************************************
Serial.println();
LT.printModemSettings(); //reads and prints the configured LoRa settings, useful check
Serial.println();
LT.printOperatingSettings(); //reads and prints the configured operting settings, useful check
Serial.println();
Serial.println();
LT.printRegisters(0x900, 0x9FF); //print contents of device registers, normally 0x00 to 0x4F
Serial.println();
Serial.println();
Serial.print(F("Receiver ready - RXBUFFER_SIZE "));
Serial.println(RXBUFFER_SIZE);
Serial.println();
}
E5 transmitter serial output
Version =
ID = +ID: DevAddr, 42:00:33:26
+ID: DevEui, 2C:F7:F1:20:42:00:33:26
+ID: AppEui, 80:00:00:00:00:00:00:06
Send string.
Send hex.
Send string.
Send hex.
Send string.
Send hex.
Send string.
Send hex.
Send string.
Send hex.
Heltec ESP32S3 LoRa (V3) receiver serial output
Heltek LoRa V3 receiver
104_LoRa_Receiver_Detailed_Setup_ESP32 Starting
LoRa Device found
SX1262,866000000hz,SF7,BW125000,CR4:5,LDRO_Off,SyncWord_0x1424,IQNormal,Preamble_8
SX1262,PacketMode_LoRa,Explicit,LNAgain_Boosted
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x900 30 00 00 00 00 64 00 00 00 00 00 00 24 04 47 04
0x910 00 2F 00 00 00 03 0A 00 15 35 09 00 02 2A 6F 08
0x920 07 04 05 00 00 00 00 00 00 00 00 00 00 00 00 00
0x930 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x940 00 07 00 03 02 00 10 00 0A 00 03 04 00 14 0C 00
0x950 00 00 00 06 00 00 00 00 00 00 00 00 00 00 00 00
0x960 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x970 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x980 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x990 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x9A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x9B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x9C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x9D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x9E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x9F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
330s Hello World!,CRC,882A,RSSI,-35dBm,SNR,12dB,Length,12,Packets,14,Errors,0,IRQreg,16
333s ��Ua ,CRC,50B1,RSSI,-34dBm,SNR,12dB,Length,10,Packets,15,Errors,0,IRQreg,16
336s Hello World!,CRC,882A,RSSI,-36dBm,SNR,12dB,Length,12,Packets,16,Errors,0,IRQreg,16
339s ��Ua ,CRC,50B1,RSSI,-35dBm,SNR,12dB,Length,10,Packets,17,Errors,0,IRQreg,16
342s Hello World!,CRC,882A,RSSI,-33dBm,SNR,12dB,Length,12,Packets,18,Errors,0,IRQreg,16
345s ��Ua ,CRC,50B1,RSSI,-26dBm,SNR,12dB,Length,10,Packets,19,Errors,0,IRQreg,16
348s Hello World!,CRC,882A,RSSI,-33dBm,SNR,12dB,Length,12,Packets,20,Errors,0,IRQreg,16
351s ��Ua ,CRC,50B1,RSSI,-24dBm,SNR,12dB,Length,10,Packets,21,Errors,0,IRQreg,16
354s Hello World!,CRC,882A,RSSI,-25dBm,SNR,12dB,Length,12,Packets,22,Errors,0,IRQreg,16
357s ��Ua ,CRC,50B1,RSSI,-25dBm,SNR,13dB,Length,10,Packets,23,Errors,0,IRQreg,16
360s Hello World!,CRC,882A,RSSI,-24dBm,SNR,12dB,Length,12,Packets,24,Errors,0,IRQreg,16
it is unlikely that anyone has you exact configuration so only examples using similar devices can be provided to give you ideas of suitable libraries etc
always start projects using communications by testing the communication between devices using the simplest example code (usually provided by the libraries)
even then if the LoRa modules and /or host microcontrollers are different it can be difficult to setup the different libraries etc for reliable communication