I am trying to send messages from my arduino to my raspberry pi. But I don't understand why the pi isn't receiving the messages.

On the arduino side Im using an arduino UNO with a Dragino Lora/GPS shield, using the Radiohead library.

On the Pi side, the Upotronics LoRa hat for the pi zero and a pi zero, which is based on a RFM95 chip. And on the software side I'm using the Raspi Lora library.

I wrote a couple of simple programs just to test the connection, and I can send messages from the raspberry to the arduino, but not the other way around.

Am I making a mistake in the code on either sending the data from the arduino or receiving it on the raspberry that prevents this?

Code for the arduino: This one sends data it gets from serial port and awaits radio input when nothing is available.

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

RH_RF95 rf95;

void setup(){
  if (rf95.init()){
    Serial.println("Init Success");
  } else {
    Serial.println("Init Failed");
  if (rf95.setFrequency(868)) Serial.println("Freq set for 868Mhz");
  if (!rf95.setModemConfig(RH_RF95::Bw125Cr45Sf128)) Serial.println("Invalid modem");

  Serial.println("Send serial data to echo it through radio");

void loop(){
  uint8_t data[100];
  uint8_t len;
  if (Serial.available()){
    int i = 0;
    while (Serial.available() && i < sizeof(data)-1){
      data[i] = Serial.read();
      data[i] = 0;
      Serial.print("Message sent: ");
      Serial.println((char *) data);
    } else {
      Serial.println("Failure to send");

  if (rf95.available())
    if (rf95.recv((uint8_t *)data,&len)){
      Serial.println("Got it");
      Serial.println((char *)data);

Raspberry pi code: This one just initializes the lora instance, I run it on the interactive console and in theory it should print data, but as much as I tried I haven't managed to catch an IRQ on any of the pins when I send a message.

from raspi_lora import LoRa, ModemConfig

# This is our callback function that runs when a message is received
def on_recv(payload):
    print("From:", payload.header_from)
    print("Received:", payload.message)
    print("RSSI: {}; SNR: {}".format(payload.rssi, payload.snr))

lora = LoRa(0, 25, 2,freq=868, receive_all=True, modem_config=ModemConfig.Bw125Cr45Sf128)
lora.on_recv = on_recv


I figured it out. Turns out there was a bug in the raspi_lora library I used for my python code. It is so that, if you are not specifically sending to the device address or have receive_all=True , it will do nothing with the messages.

If you plan to use the raspi_lora library you should replace line 268 in the lora.py file with

if (self._this_address != header_to) and ((header_to != BROADCAST_ADDRESS) or (self._receive_all is False)):
| improve this answer | |
  • Wow, well done. Don't forget to mark the question as answered! – SeanJ Jul 26 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.