Communication problem Between rpi zero W and arduino nano RFM9X LoRA

Hello everybody!

This is my first post. I'm working on an altimeter for a model rocket using an arduino nano. The idea is to get altitude information and send it to my ground station using RFM9X LoRA modules.

In the ground station i'm using a raspberry pi zero W in baremetal with CircuitPython.

I'm having trouble receiving and sending packages through LoRA between both boards. As a summary:

  • Ground station: Rapsberry pi zero W with CircuitPython - Adafruit RFM9X library 5V pin SPI
  • Flight computer: Arduino Nano with RadioHead library 5V pin SPI

I checked that both LoRA's worked fine (wiring and initialization), but they don't exchange information!

Here's the example code for arduino nano (extracted from an example posted in another forum):

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

#define RFM95_CS 4
#define RFM95_RST 2
#define RFM95_INT 2


// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 868.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);



void setup() 
{
      
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);

  while (!Serial);
  Serial.begin(115200);
  delay(100);

  Serial.println("Feather LoRa RX Test!");
  
  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    while (1);
  }
  Serial.println("LoRa radio init OK!");
  rf95.setPromiscuous(true);
  rf95.setModemConfig(RH_RF95::Bw125Cr45Sf128); // Usa configuración estándar
  rf95.setPreambleLength(8); // Coincidir con CircuitPython

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);

  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 
  // you can set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(23, false);
}

void loop()
{
  if (rf95.available())
  {
    // Should be a message for us now 
    Serial.println("Message received!"); 
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]={0};
    uint8_t len = sizeof(buf);
    
    
    if (rf95.recv(buf, &len))
    {
      
      RH_RF95::printBuffer("Received: ", buf, len);
      Serial.print("Got: ");
      Serial.print((char*)buf);
       Serial.print(" RSSI: ");
      Serial.println(rf95.lastRssi(), DEC);
      delay(10);
      // Send a reply
      //delay(200); // may or may not be needed
      static int count=0;
      uint8_t data[50]={0};
      sprintf(data, "And hello back to you %d", count++);
      Serial.print("sending reply: ");
      Serial.println((char *)data);
      rf95.send(data, sizeof(data));
      rf95.waitPacketSent();
      
    }
    else
    {
      Serial.println("Receive failed");
    }
  }
  else
  {
    delay(5000);
    Serial.println("No messages");
  }
}

This is the output:


Feather LoRa RX Test!

LoRa radio init OK!

Set Freq to: 868.00

No messages

No messages

and the code for the rpi circuitpython:

import time
import board
import busio
import digitalio
import adafruit_rfm9x

# Define radio parameters
RADIO_FREQ_MHZ = 868.0  # Frequency of the radio in MHz. 868.0 MHz in Europe, 915.0 MHz in North America.
CS = digitalio.DigitalInOut(board.CE0) 
RESET = digitalio.DigitalInOut(board.D25)
print("LoRA test")
adafruit_rfm9x.enable_crc = True
adafruit_rfm9x.signal_bandwidth = 125000  # Debe coincidir con Arduino
adafruit_rfm9x.coding_rate = 5  # CR 4/5 (igual a Bw125Cr45Sf128 en RadioHead)
adafruit_rfm9x.spreading_factor = 7  # SF7 (igual a Bw125Cr45Sf128 en RadioHead)
adafruit_rfm9x.preamble_length = 8

# Initialize SPI bus
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
#spi = busio.SPI(board.D11, MOSI=board.D10, MISO=board.D9)
# Initialize RFM9x radio
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, RADIO_FREQ_MHZ)
count=0
while True:
        text='Hello world '+ str(count)
        rfm9x.send(str.encode(text))
        print('Sent: {0}'.format(text))
        count=count+1
        packet = rfm9x.receive()  # Wait for a packet to be received (up to 0.5 seconds)
        if packet is not None:
            packet_text = str(packet, 'ascii')
            print('Received: {0}'.format(packet_text))
        else:
            print('Received nothing!')
        time.sleep(5)  # Wait for some time before sending the next command

obtaining this output:

LoRA test
Sent: Hello world 0
Received nothing!
Sent: Hello world 1
Received nothing!
Sent: Hello world 2
Received nothing!

with the example I'm trying to test sending and receiving strings in both boards. Hope anyone knows what's happening and help me to fix it. Both libraries are supposed to be compatible.

Are you using the same syncwords for both LoRa libraries ?

Are you using logic level conversion circuits for the RFM95 module on the Arduino Nano ?

Thanks for answering, I checked and it's supposed both libraries uses 0x12 as syncword, but not really sure how to check. I'm not using any logic level conversion for the RFM95, but I'm a little bit lost about it since it's my first project with arduino

I would suggest for a start dropping Python and using the same RadioHead library on the RPi Pico as you use on the Nano - once you know communication works you can try python
as recommended by @srnet you should use level converters to convert the Nano 5V logic to the RFM95 3.3Vlogic - or even better use a micro that uses 3.3V logic

As a first project what your trying to do is a major challenge even for someone with a significant amount of Arduino and LoRa experience.

Different LoRa libraries for different hardware platforms are not written to be compatible with each other in the way the LoRa module is configured and used. However, there are several LoRa defaults that must match for TX and RX comms to work. If the TX and RX nodes use the same hardware platform and library, as is normal practice, this is not a problem.

I would start a project such as this by proving that I had a pair of Arduinos working with the chosen library using simple transmit and receive functions. Then do the same for a pair of rpi zero W and LoRa modules. Then you would be sure you have both hardware platforms and libraries working for TX and RX.

In addition do connect the modules correctly so you can be sure your not creating further problems. The Arduino Nano is 5V logic level and the RFM95 is 3.3V Logic level so you cannot assume they are working correctly if you wire them up directly. Much easier to swap the Nano for a 3.3V logic level Arduino or other Micro controller.

Not sure the RadioHead library would be my choice for compatibility, some of the settings are odd; the RFM95\SX127x is not capable of 23dBm for instance, according to the datasheet.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.