RFM95W Lora radio cannot receive

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
jaxandra
 
Posts: 13
Joined: Fri Apr 21, 2023 12:38 pm

RFM95W Lora radio cannot receive

Post by jaxandra »

I am trying out the following test with two RFM95W boards on Raspberry Pis.

https://learn.adafruit.com/adafruit-rad ... lora-radio

The board is detected by the Pi, and instead of the button press, I have a send program that sends packets every 2 seconds and the receiver listens continuously. Only a handful of packets, if any, are received by the receiver. What might be going on?

User avatar
jaxandra
 
Posts: 13
Joined: Fri Apr 21, 2023 12:38 pm

Re: RFM95W Lora radio cannot receive

Post by jaxandra »

This is from sending around 1000 packets.
Lora.jpg
Lora.jpg (90.29 KiB) Viewed 202 times

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: RFM95W Lora radio cannot receive

Post by jerryn »

It would be helpful to see the code you are actually using for both the transmit and receive systems.

User avatar
jaxandra
 
Posts: 13
Joined: Fri Apr 21, 2023 12:38 pm

Re: RFM95W Lora radio cannot receive

Post by jaxandra »

Sender Code

Code: Select all

# Configure LoRa Radio
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0)
rfm9x.tx_power = 23
prev_packet = None
count = 0

while True:
    count = count + 1
    # draw a box to clear the image
    display.fill(0)
    send_data = bytes(str(count), "utf-8")

    status = rfm9x.send(send_data)
    print("sending " + str(count) + ", status " + str(status))

    display.text(str(count), 25, 15, 1)
    display.show()
    time.sleep(2)

User avatar
jaxandra
 
Posts: 13
Joined: Fri Apr 21, 2023 12:38 pm

Re: RFM95W Lora radio cannot receive

Post by jaxandra »

Receiver code

Code: Select all

spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0)
rfm9x.tx_power = 23
rfm9x.receive_timeout = 0.5
prev_packet = None

while True:
    packet = None
    # draw a box to clear the image
    display.fill(0)
    display.text('RasPi LoRa', 35, 0, 1)
    #print("Timeout " + str(rfm9x.receive_timeout))

    # check for packet rx
    packet = rfm9x.receive()

    if packet is None:
        display.text('- Waiting for PKT -', 15, 20, 1)
        display.show()

        #print("CRC Error " + str(rfm9x.crc_error()))
    else:
        # Display the packet text and rssi
        display.fill(0)
        prev_packet = packet
        packet_text = str(prev_packet, "utf-8")
        display.text('RX: ', 0, 0, 1)
        display.text(packet_text, 25, 0, 1)
        print("Received " + packet_text)
        display.show()
    time.sleep(0.1)

User avatar
jaxandra
 
Posts: 13
Joined: Fri Apr 21, 2023 12:38 pm

Re: RFM95W Lora radio cannot receive

Post by jaxandra »

Both these are pretty much the programs from https://learn.adafruit.com/lora-and-lor ... y-pi-setup>.

Code indentation is not shown properly due to the editor.

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: RFM95W Lora radio cannot receive

Post by jerryn »

I tried your code -- using a pizero2w for the receiver and a pi400 for the transmitter -- I get much better results

Code: Select all

pi@gjnpirfm9xswitch:~ $ python receive.py 
Received 1
Received 1
Received 2
Received 4
Received 5
Received 7
Received 8
Received 9
Received 10
Received 11
Received 12
Received 14
Received 16
Received 17
Received 18


There are some misses but that is not uncommon. Switching to the "reliable datagram" mode would likely improve that.
Here is the code I ran (note -- using the "code" tags from the menubar preserves formatting.
transmit

Code: Select all

import time
import busio
from digitalio import DigitalInOut, Direction, Pull
import board
# Import the SSD1306 module.
import adafruit_ssd1306
# Import the RFM9x radio module.
import adafruit_rfm9x

# Button A
btnA = DigitalInOut(board.D5)
btnA.direction = Direction.INPUT
btnA.pull = Pull.UP

# Button B
btnB = DigitalInOut(board.D6)
btnB.direction = Direction.INPUT
btnB.pull = Pull.UP

# Button C
btnC = DigitalInOut(board.D12)
btnC.direction = Direction.INPUT
btnC.pull = Pull.UP

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# 128x32 OLED Display
reset_pin = DigitalInOut(board.D4)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin)
# Clear the display.
display.fill(0)
display.show()
width = display.width
height = display.height

# Configure LoRa Radio
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0)
rfm9x.tx_power = 23
prev_packet = None
count = 0

while True:
    count = count + 1
    # draw a box to clear the image
    display.fill(0)
    send_data = bytes(str(count), "utf-8")

    status = rfm9x.send(send_data)
    print("sending " + str(count) + ", status " + str(status))

    display.text(str(count), 25, 15, 1)
    display.show()
    time.sleep(2)
receive

Code: Select all

import time
import busio
from digitalio import DigitalInOut, Direction, Pull
import board
# Import the SSD1306 module.
import adafruit_ssd1306
# Import the RFM9x radio module.
import adafruit_rfm9x

# Button A
btnA = DigitalInOut(board.D5)
btnA.direction = Direction.INPUT
btnA.pull = Pull.UP

# Button B
btnB = DigitalInOut(board.D6)
btnB.direction = Direction.INPUT
btnB.pull = Pull.UP

# Button C
btnC = DigitalInOut(board.D12)
btnC.direction = Direction.INPUT
btnC.pull = Pull.UP

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# 128x32 OLED Display
reset_pin = DigitalInOut(board.D4)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin)
# Clear the display.
display.fill(0)
display.show()
width = display.width
height = display.height


# Configure RFM9x LoRa Radio
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0)
rfm9x.tx_power = 23
rfm9x.receive_timeout = 0.5
prev_packet = None

while True:
    packet = None
    # draw a box to clear the image
    display.fill(0)
    display.text('RasPi LoRa', 35, 0, 1)
    #print("Timeout " + str(rfm9x.receive_timeout))

    # check for packet rx
    packet = rfm9x.receive()

    if packet is None:
        display.text('- Waiting for PKT -', 15, 20, 1)
        display.show()

        #print("CRC Error " + str(rfm9x.crc_error()))
    else:
        # Display the packet text and rssi
        display.fill(0)
        prev_packet = packet
        packet_text = str(prev_packet, "utf-8")
        display.text('RX: ', 0, 0, 1)
        display.text(packet_text, 25, 0, 1)
        print("Received " + packet_text)
        display.show()
        time.sleep(0.1)
edited to add --
If I swap transmit and receive so I am receiving on the pi400 then I am not missing any packets. This is like because the pi400 process the screen updates so much faster so there is much less "dead" time before it starts listening again.

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: RFM95W Lora radio cannot receive

Post by jerryn »

I modified the examples to use "reliable datagram" and node addressing so each packet sent is acknowledged.
This eliminated missed messages.

Code: Select all


pi@gjnpirfm9xswitch:~ $ python receive_ack.py 
Received 1
Received 2
Received 3
Received 4
Received 5
Received 6
Received 7
Received 8
Received 9
Received 10
Received 11
Received 12
Received 13
Received 14
Received 15
Received 16
Received 17
Received 18
Received 19
Received 20
Received 21
Received 22
Received 23
Received 24
Received 25
here is the new code -- I removed the extraneous stuff for the buttons.

transmit with ack:

Code: Select all

import time
import busio
from digitalio import DigitalInOut
import board
# Import the SSD1306 module.
import adafruit_ssd1306
# Import the RFM9x radio module.
import adafruit_rfm9x


# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# 128x32 OLED Display
reset_pin = DigitalInOut(board.D4)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin)
# Clear the display.
display.fill(0)
display.show()
width = display.width
height = display.height

# Configure LoRa Radio
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0)
rfm9x.tx_power = 23


# set delay before sending ACK
rfm9x.ack_delay = 0.1
# set node addresses
rfm9x.node = 1
rfm9x.destination = 2


prev_packet = None
count = 0

while True:
    count = count + 1
    # draw a box to clear the image
    display.fill(0)
    send_data = bytes(str(count), "utf-8")
    status = rfm9x.send_with_ack(send_data)
    print("sending " + str(count) + ", status " + str(status))
    display.text(str(count), 25, 15, 1)
    display.show()
    time.sleep(2)

receive with ack

Code: Select all

import time
import busio
import board
from  digitalio import DigitalInOut
# Import the SSD1306 module.
import adafruit_ssd1306
# Import the RFM9x radio module.
import adafruit_rfm9x


# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)

# 128x32 OLED Display
reset_pin = DigitalInOut(board.D4)
display = adafruit_ssd1306.SSD1306_I2C(128, 32, i2c, reset=reset_pin)
# Clear the display.
display.fill(0)
display.show()
width = display.width
height = display.height


# Configure RFM9x LoRa Radio
CS = DigitalInOut(board.CE1)
RESET = DigitalInOut(board.D25)
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
rfm9x = adafruit_rfm9x.RFM9x(spi, CS, RESET, 915.0)
rfm9x.tx_power = 23
rfm9x.receive_timeout = 0.5

# set delay before transmitting ACK (seconds)
rfm9x.ack_delay = 0.1
# set node addresses
rfm9x.node = 2
rfm9x.destination = 1


prev_packet = None

while True:
    packet = None
    # draw a box to clear the image
    display.fill(0)
    display.text('RasPi LoRa', 35, 0, 1)
    #print("Timeout " + str(rfm9x.receive_timeout))

    # Look for a new packet: only accept if addresses to my_node
    packet = rfm9x.receive(with_ack=True)
    if packet is None:
        display.text('- Waiting for PKT -', 15, 20, 1)
        display.show()

        #print("CRC Error " + str(rfm9x.crc_error()))
    else:
        # Display the packet text and rssi
        display.fill(0)
        prev_packet = packet
        packet_text = str(prev_packet, "utf-8")
        display.text('RX: ', 0, 0, 1)
        display.text(packet_text, 25, 0, 1)
        print("Received " + packet_text)
        display.show()

User avatar
jaxandra
 
Posts: 13
Joined: Fri Apr 21, 2023 12:38 pm

Re: RFM95W Lora radio cannot receive

Post by jaxandra »

Thank you so much!

This is really interesting. The reliable send/receive does work better. I am using a Pi 3B+ for both the sender and receiver, so do you think the low speed I/O might be why the original programs don't work as well?

Another question - this might be another thread on its own. My ultimate goal is to get the board to send a Lorawan packet to TTN console. I have a RAK Lorawan gateway (https://store.rakwireless.com/products/ ... 2876102854) that will be forwarding packets to TTN. However, the gateway does not seem to pick up any packets when the board sends out Lora packets. Any ideas?

User avatar
jaxandra
 
Posts: 13
Joined: Fri Apr 21, 2023 12:38 pm

Re: RFM95W Lora radio cannot receive

Post by jaxandra »

Also, is there a way to use the CircuitPython library to print which channel the packet is received on? The API documentation does not list any methods.

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: RFM95W Lora radio cannot receive

Post by jerryn »

Sorry for the delayed response.
Regarding LoRaWAN, the Circuitpython adafruit_rfm9x library only supports LoRa (peer to peer) communication, not LoRaWAN. Your LoRaWAN gateway will not respond to packets generated by this library. Unfortunately, at this time, the is no support for LoRAWAN in Circuitpython. The deprecated adafruit_tinylora library does not work with the LoRaWAN The Things Network (TTN) V3.

edited to remove Arduino reference — I forgot you are using Raspberry Pi.

User avatar
jaxandra
 
Posts: 13
Joined: Fri Apr 21, 2023 12:38 pm

Re: RFM95W Lora radio cannot receive

Post by jaxandra »

Ouch. That is not good news. So essentially the board is unusable with LoRaWAN? Is there another library that can be used with the board?

User avatar
jaxandra
 
Posts: 13
Joined: Fri Apr 21, 2023 12:38 pm

Re: RFM95W Lora radio cannot receive

Post by jaxandra »

Also, I upgraded my Pi to a 4B from a 3 B+ and there are 4 I/O pins on the board that prevent the RFM95 board to be inserted into the GPIO slot. Is the board incompatible with 4B?

User avatar
jerryn
 
Posts: 1868
Joined: Sat Sep 14, 2013 9:05 am

Re: RFM95W Lora radio cannot receive

Post by jerryn »

I use the "riser" header" https://www.adafruit.com/product/4079 to get extra clearance on a Pi 4. It is compatible with the riser header.

As to using the Pi with LoraWAN, I don't know offhand of any libraries for the PI but I have not looked recently. Hopefully someone else can help. I'll try to take look as well in the next few days.

Good luck!
Note: I do not represent Adafruit. Just trying to help... sorry to bring bad news.

User avatar
jaxandra
 
Posts: 13
Joined: Fri Apr 21, 2023 12:38 pm

Re: RFM95W Lora radio cannot receive

Post by jaxandra »

Thank you! I appreciate the help. I figured you were representing adafruit.

Off topic: is there any official support for any of these boards through adafruit? It seems disingenuous that they are selling these with claim for Lorawan support.

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”