Troubleshooting LoRa RFM95W Not receiving data

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.

This is my code for the transmitter:

#include <SPI.h>
#include <LoRa.h>

int counter = 0;

void setup() {
  delay(1000);
  Serial.begin(9600);

  Serial.println("LoRa Sender");

  LoRa.setPins(5, 34, 2);

  if (!LoRa.begin(915E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  } else {
    Serial.println("LoRa initialized");
  }
}

void loop() {
  Serial.print("Sending packet: ");
  Serial.println(counter);

  // send packet
  if(LoRa.beginPacket()){
    LoRa.print("hello ");
    LoRa.print(counter);
    bool success = LoRa.endPacket();
    if(!success){
      Serial.println("Error sending the packet");
    }
  } else {
    Serial.println("Error accessing LoRa Module");
  }
  

  counter++;

  delay(2000);
}

And this is the code for the receiver:

#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?

Did the raw, as you found them, programs work properly before you made some minor changes?

Not enough information in your post. Please see the "How to get the best out of this forum" for advice.

That certainly can be a problem, as pins are used differently by different manufacturers.

How did you arrive at the choice of pins below?

  LoRa.setPins(5, 34, 2);

Do you have antennas on the radio modules? Please post wiring diagrams and a photo of your setup.

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.

No, because I'm not using the default configuration.

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.

Post links.

Perhaps you should try it.

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:54.477 -> Sending packet: 1
08:37:56.506 -> Sending packet: 2
08:37:58.523 -> Sending packet: 3
08:38:00.555 -> Sending packet: 4
08:38:02.580 -> Sending packet: 5
08:38:04.588 -> Sending packet: 6
08:38:06.617 -> Sending packet: 7
08:38:08.669 -> Sending packet: 8

receiver

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.

RESET on the LoRa device is an input pin and needs to be connected to an output pin on the ESP32.

Pin 34 is input only on the ESP32.

RFM95W connected to a ESP32

// ESP32 connected to a RFM95W LoRa module

#include <SPI.h>
#include <LoRa.h>

// ESP32 connections
// ESP32 SCK pin GPIO18  to RFM95_pin SCK
// ESP32 MISO pin GPIO19  to RFM95_pin MISO
// ESP32 MOSI pin GPIO23  to RFM95_pin MOSI
// ESP32 pin GPIO 5   to RFM95 SS
// ESP32 pin GPIO4   to RFM95 Reset
// RFM95 DIO0 not connected

void setup() {
  Serial.begin(115200);
  delay(2000);
  Serial.println("\n\nESP32 LoRa RFM95W Receiver");
  // void setPins(int ss = LORA_DEFAULT_SS_PIN, int reset = LORA_DEFAULT_RESET_PIN, int dio0 = LORA_DEFAULT_DIO0_PIN);
  //LoRa.setPins(8, 4, 7);  // for Lora 32u4
  LoRa.setPins(5, 4, 2);  // for ESP32
  if (!LoRa.begin(866E6)) {
    Serial.println("Starting LoRa failed!");
    while (1)    ;
  }
  Serial.println("Starting LoRa OK!");
}

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());
  }
}

ESP32 serial output

10:09:42.692 -> ESP32 LoRa RFM95W Receiver
10:09:42.740 -> Starting LoRa OK!
10:09:43.562 -> Received packet 'hello 373' with RSSI -65
10:09:45.596 -> Received packet 'hello 374' with RSSI -66
10:09:47.665 -> Received packet 'hello 375' with RSSI -66
10:09:49.698 -> Received packet 'hello 376' with RSSI -65
10:09:51.699 -> Received packet 'hello 377' with RSSI -66
10:09:53.733 -> Received packet 'hello 378' with RSSI -65
10:09:55.768 -> Received packet 'hello 379' with RSSI -65

transmitter is a Feather 32u4 LoRa as in post 8

I didn't know pin 34 was input only. Thanks for that info. I changed it to pin 14 but it still doesn't work.

changed ESP32 code of post 11 to use pin 14

  LoRa.setPins(5, 14, 2);  // for ESP32

and it worked OK

what particular RFM95W module are you using? give a link?

It's this module:

[Datasheet for RFM95W-915S2 RF Solutions RF Receivers, Transceivers | Octopart]


Connection diagram

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;
}

running the test program of post 16 from @srnet on an ESP32 with a RFM95 the serial monitor displays

11:15:45.666 -> 85_SX127X_LoRa_Device_Check Starting
11:15:45.698 -> LoRa Device found
11:15:45.698 -> Device version 0x12
11:15:45.698 -> Frequency 866000000
11:15:45.698 -> 
11:15:45.698 -> Registers 
11:15:45.698 -> Reg    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
11:15:45.698 -> 0x00  6F 81 1A 0B 00 52 D8 80 00 8F 09 2B 23 0C 00 00 

the RFM95 module connected to the ESP32 is a Raspberry Pi LoRa HAT

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?

Try it and see.

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?