RFM9X LoRa + M0 Pro packet sending issue

Hello,

It seems to me my RFM9x is not sending a packet and I can not find a solution. It is getting stuck in my code during command - rf95.waitPacketSent();

If I remove this command then it goes on and when trying to send a second packet it gets stuck. I believe it does that because it is not able to send the first packet.

I have a arduino uno m0 pro and uno R4 Minima both equipped with adafruit RFM9x module. I got r4 minima working, but can not seem to do it with the M0 Pro.I have also tested minima code also with no success.

I have also switched the modules between boards to make sure the module is not broken. No change was seen.

Pinouts:

  • VIN - 3,3V
  • GND - GND
  • EN - N/A did not connected and used
  • G0 - D2
  • SCK - SPI 3
  • MISO - SPI 1
  • MOSI - SPI 4
  • CS - D10
  • RST - D9

SPI pinout refernce: https://docs.arduino.cc/resources/pinouts/ABX00003-full-pinout.pdf

#include <SPI.h>
#include <RH_RF95.h>

// Define LoRa module pins and frequency
#define RFM95_CS 10
#define RFM95_RST 9
#define RFM95_INT 2
#define RF95_FREQ 433.0
RH_RF95 rf95(RFM95_CS, RFM95_INT);
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);

void setupLoRa() {
  // Manual reset
  Serial.println("Performing manual reset...");
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  rf95.init();
  Serial.println("init done");

  if (!rf95.init()) {
    Serial.println("LoRa init failed!");
    while (1);  // Stay here if initialization fails
  }
  Serial.println("LoRa init OK!");

  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed!");
    while (1);  // Stay here if setting frequency fails
  }
  Serial.print("Set frequency to: ");
  Serial.println(RF95_FREQ);

  rf95.setTxPower(13, false); // Set transmission power (13 dBm)
}

struct Packet {
  int ECU;
  int Ser1;
  int Err;
  int PH1;
};

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

  setupLoRa(); // Call the setupLoRa function to initialize the LoRa module
}

void loop() {
  Serial.println("Debug1");
  Packet Send = {101, 202, 0, 999};
  Serial.println("Debug2");
  rf95.send((uint8_t *)&Send, sizeof(Send));
  Serial.println("Debug3");
  rf95.waitPacketSent();

  Serial.println("Packet sent");
}

Serial Monitor outputs:

  • Performing manual reset...
  • init done
  • LoRa init OK!
  • Set frequency to: 433.00
  • Debug1
  • Debug2
  • Debug3

I am using IDE 2.3.6

Thank you for looking into this!

I strongly recommend to start with the working examples built into the RadioHead library, to verify operation of the setup, before writing your own code.

See this very recent thread for a similar problem.

I dont use that specific LoRa library myself, but can you say where the code you posted came from, as in was\is it code that is known to work ?

As per the @jremington comment do the library provided examples work for your setup ?

Hi,

That’s frustrating! Since your RFM9x works on the R4 Minima but not the M0 Pro, it might be a board-specific issue. A few things to check:

  1. SPI Configuration: The M0 Pro’s SPI pins might differ. Double-check the SPI pinout for the M0 Pro (not just the R4’s doc) and ensure SCK, MISO, MOSI align.
  2. Power Supply: The M0 Pro’s 3.3V pin might not supply enough current for the RFM9x. Try an external 3.3V source.
  3. Library Version: Ensure you’re using the latest RadioHead library, as older versions had M0 quirks.

Could you share which RadioHead version you’re using? Also, does rf95.init() consistently pass on the M0 Pro, or does it ever fail?

Hope this helps!