I'm using two RFM95W LoRa modules with ESP32 and Sandeep Mistry's LoRa library. I'm using different ESP32 boards for each module. I've loaded the example code that comes with the library for transmitting data, with a few modifications to check if the module is indeed transmitting data or if there's a failure in the process. As for the receiver, once again, I've loaded the example code for receiving data, with a few modifications to adapt it to my case, but it doesn't seem to be receiving any data.
#include <SPI.h>
#include <LoRa.h>
void setup() {
Serial.begin(9600);
Serial.println("LoRa Receiver");
LoRa.setPins(5, 34, 2);
if (!LoRa.begin(915E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
Serial.print((char)LoRa.read());
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
}
In the transmitter, I print messages if there are any failures in the process of accessing the LoRa module and sending a packet. However, when the code is running, everything is working correctly, there are no error messages. Despite this, my receiver is not printing anything. Even when I disconnect the power from the LoRa module, the code continues to print 'Sending packet ...' periodically. So, if even with no module, the code doesn't print my error messages, how can I confirm if the module is actually transmitting data? And if it is, why is my receiver not functioning?
I'm sorry, I think I didn't express myself clearly... I meant that I'm using two separate ESP32 boards, but both are identical. I based on the following diagram for the connections:
I only changed the pin to which I connect the 'reset' to pin 34 because it's closer, and I use the GND from the bottom right corner instead of the one next to the antenna because my colleague handed me the module with a wire already soldered to that pin. Also, I do have an antenna connected to the modules.
The radio power supply could well be inadequate. You still have not provided enough information, like the identify of the ESP32 boards and the radio modules, and an actually useful schematic diagram, with pins and connections clearly labeled.
if I run your code of post 1 on a couple of Feather 32u4 loRa RFM95W boards changing the setpins() and frequency to suit the hardware itworks
transmitter serial output
08:37:52.495 -> Received packet 'hello 0' with RSSI -107
08:37:54.477 -> Received packet 'hello 1' with RSSI -107
08:37:56.552 -> Received packet 'hello 2' with RSSI -106
08:37:58.555 -> Received packet 'hello 3' with RSSI -107
08:38:00.587 -> Received packet 'hello 4' with RSSI -107
08:38:02.627 -> Received packet 'hello 5' with RSSI -107
Disconnecting the power from the LoRa module is not the same as no LoRa module. The LoRa module could be getting power via phantom power via the digital pins still connected.
Here is a simple test program that should print out the default LoRa frequency and some registers, its a stand alone program no library is needed;
/*******************************************************************************************************
Program Operation - This program is stand alone, it is not necessary to install a LoRa library to use
it. This test program is for the SX127X LoRa devices.
The program checks that a LoRa device can be accessed by doing a test register write and read.
If there is no device found a message is printed on the serial monitor. The contents of the registers
from 0x00 to 0x0F are then printed.
The Arduino pin number that NSS on the LoRa device is connected to must be specified in #define NSS
line below. The DIO0 pin is not needed and you can leave the NRESET not connected as well.
Typical printout;
85_SX127X_LoRa_Device_Check Starting
LoRa Device found
Device version 0x12
Frequency 434000000
Registers
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00 00 09 1A 0B 00 52 6C 80 00 4F 09 2B 20 08 02 0A
Note: An SX1272 will report as version 0x22 and the frequency at power up is 915000000hz.
ESP32
-----
For an ESP32 microcontroller you can specify the SCK, MOSI and MOSI pins used by the SPI interface by
adding these defines;
#define SCK 18
#define MISO 19
#define MOSI 23
Then begin the SPI interface like this;
SPI.begin(SCK, MISO, MOSI);
Serial monitor baud rate is set at 115200.
*******************************************************************************************************/
const uint8_t REG_FRMSB = 0x06; //register number for setting and reading frequency, high byte
const uint8_t REG_FRMID = 0x07; //register number for setting and reading frequency, mid byte
const uint8_t REG_FRLSB = 0x08; //register number for setting and reading frequency, low byte
const uint8_t REG_VERSION = 0x42; //register containg version number of device
//********* Setup hardware pin definition here ! **************
#define NSS 5 //LoRa device select
#define NRESET 4 //can be left not connected for this test program
#define SCK 18 //for ESP32
#define MISO 19 //for ESP32
#define MOSI 23 //for ESP32
//**************************************************************/
#include <SPI.h>
uint32_t frequency;
void setup()
{
Serial.begin(115200);
Serial.println(F("85_SX127X_LoRa_Device_Check Starting"));
SPI.begin(SCK, MISO, MOSI); //for ESP32
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
//The begin function setups the hardware pins used by device and then checks if device is found
if (begin(NSS, NRESET))
{
Serial.println(F("LoRa Device found"));
}
else
{
Serial.println(F("No device responding"));
}
Serial.print(F("Device version 0x"));
uint8_t deviceversion = readRegister(REG_VERSION);
if (deviceversion < 0x10)
{
Serial.print(F("0"));
}
Serial.println(deviceversion, HEX);
frequency = getFreqInt(); //read the default set frequency following a powerup
Serial.print(F("Frequency "));
Serial.println(frequency);
Serial.println();
Serial.println(F("Registers ")); //show registers
printRegisters(0x00, 0x0F);
}
void loop()
{
}
uint8_t readRegister(uint8_t address)
{
uint8_t regdata;
digitalWrite(NSS, LOW); //set NSS low
SPI.transfer(address & 0x7F); //mask address for read
regdata = SPI.transfer(0); //read the byte
digitalWrite(NSS, HIGH); //set NSS high
return regdata;
}
void writeRegister(uint8_t address, uint8_t value)
{
digitalWrite(NSS, LOW); //set NSS low
SPI.transfer(address | 0x80); //mask address for write
SPI.transfer(value); //write the byte
digitalWrite(NSS, HIGH); //set NSS high
}
void printRegisters(uint16_t Start, uint16_t End)
{
//prints the contents of lora device registers to serial monitor
uint16_t Loopv1, Loopv2, RegData;
Serial.print(F("Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F"));
Serial.println();
for (Loopv1 = Start; Loopv1 <= End;)
{
Serial.print(F("0x"));
if (Loopv1 < 0x10)
{
Serial.print(F("0"));
}
Serial.print((Loopv1), HEX);
Serial.print(F(" "));
for (Loopv2 = 0; Loopv2 <= 15; Loopv2++)
{
RegData = readRegister(Loopv1);
if (RegData < 0x10)
{
Serial.print(F("0"));
}
Serial.print(RegData, HEX);
Serial.print(F(" "));
Loopv1++;
}
Serial.println();
}
}
bool begin(int8_t pinNSS, int8_t pinNRESET)
{
pinMode(pinNSS, OUTPUT);
digitalWrite(pinNSS, HIGH);
pinMode(pinNRESET, OUTPUT);
digitalWrite(pinNRESET, HIGH);
delay(10);
digitalWrite(pinNRESET, LOW);
delay(10);
digitalWrite(pinNRESET, HIGH);
if (checkDevice())
{
return true;
}
return false;
}
bool checkDevice()
{
//check there is a device out there, writes a register and reads back
uint8_t Regdata1, Regdata2;
Regdata1 = readRegister(REG_FRMID); //low byte of frequency setting
writeRegister(REG_FRMID, (Regdata1 + 1));
Regdata2 = readRegister(REG_FRMID); //read changed value back
writeRegister(REG_FRMID, Regdata1); //restore register to original value
if (Regdata2 == (Regdata1 + 1))
{
return true;
}
else
{
return false;
}
}
uint32_t getFreqInt()
{
//get the current set LoRa device frequency, return as long integer
uint8_t Msb, Mid, Lsb;
uint32_t uinttemp;
float floattemp;
Msb = readRegister(REG_FRMSB);
Mid = readRegister(REG_FRMID);
Lsb = readRegister(REG_FRLSB);
floattemp = ((Msb * 0x10000ul) + (Mid * 0x100ul) + Lsb);
floattemp = ((floattemp * 61.03515625) / 1000000ul);
uinttemp = (uint32_t)(floattemp * 1000000);
return uinttemp;
}
Does the module work only with the frequency that this program says? I tried it and it worked showing this:
85_SX127X_LoRa_Device_Check Starting
LoRa Device found
Device version 0x12
Frequency 434000000
Registers
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00 00 09 1A 0B 00 52 6C 80 00 4F 09 2B 20 08 02 0A
Frequency says '434000000' but my LoRa boards have the '915 MHz' frequency marked and I've been initializing the modules first with 868 MHz and then with 915 MHz. Do I need to use 434 MHz?
I tested the code in the other circuit and it showed this:
85_SX127X_LoRa_Device_Check Starting
LoRa Device found
Device version 0x12
Frequency 0
Registers
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00 00 00 00 00 00 00 00 00 00 08 00 08 20 08 00 00
If I switch the LoRa module with other I have, it shows this:
85_SX127X_LoRa_Device_Check Starting
LoRa Device found
Device version 0x12
Frequency 0
Registers
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00 00 00 00 0B 00 52 6C 80 00 4F 09 2B 20 08 02 0A
If I switch ESP32 boards, one circuit still shows strange data while the other one have good lectures. If I switch the modules on the good circuit and put the first module tested above, it shows this:
85_SX127X_LoRa_Device_Check Starting
LoRa Device found
Device version 0x12
Frequency 434000000
Registers
Reg 0 1 2 3 4 5 6 7 8 9 A B C D E F
0x00 00 09 1A 0B 00 52 6C 80 00 4F 09 2B 20 08 02 0A
So ESP32 boards and LoRa modules seem to be working fine, maybe there is a problem with the protoboard I'm using with one of the circuits?