0

I am trying to run a LoRa receiver using python

from time import sleep
from SX127x.LoRa import *
from SX127x.board_config import BOARD
BOARD.setup()
class LoRaRcvCont(LoRa):
    def __init__(self, verbose=False):
        super(LoRaRcvCont, self).__init__(verbose)
        self.set_mode(MODE.SLEEP)
        self.set_dio_mapping([0] * 6)    
    def start(self):
        self.reset_ptr_rx()
        self.set_mode(MODE.RXCONT)
        while True:
            sleep(.5)
            rssi_value = self.get_rssi_value()
            status = self.get_modem_status()
            sys.stdout.flush()    
    def on_rx_done(self):
        print ("\nReceived: ")
        self.clear_irq_flags(RxDone=1)
        payload = self.read_payload(nocheck=True)        
        data = bytes(payload).decode("utf-8",'ignore')
        print (data)
        self.set_mode(MODE.SLEEP)
        self.reset_ptr_rx()
        self.set_mode(MODE.RXCONT) 
lora = LoRaRcvCont(verbose=False)
lora.set_mode(MODE.STDBY)

#  Medium Range  Defaults after init are 434.0MHz, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on 13 dBm
lora.set_pa_config(pa_select=1)
try:
    lora.start()
except KeyboardInterrupt:
    sys.stdout.flush()
    print ("")
    sys.stderr.write("KeyboardInterrupt\n")
finally:
    sys.stdout.flush()
    print ("")
    lora.set_mode(MODE.SLEEP)
    BOARD.teardown()

And it is giving the error: Failed to add edge detection.

I configured the access to SPI in Raspi-Config

Installed this packages

pip install spidev   
pip install pyLoRa
sudo apt-get install rpi.gpio
python-rpi.gpio
python3-rpi.gpio

I added in GPIO Group:

sudo groupadd -r gpio
sudo usermod -a -G gpio pi

I ran it as sudo but it continues giving error of: Failed to add edge detection.

Anyone could help me?

5
  • 1
    What is the exact error message - should give a file and line number?
    – CoderMike
    Oct 3 at 9:13
  • I don't see any code that would run. WHY have you tried to install RPI.GPIO which should already be present? It is unclear what you have actually done.
    – Milliways
    Oct 3 at 9:40
  • /home/pi/pySX127x/SX127x/board_config.py:61: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(BOARD.LED, GPIO.OUT) /home/pi/pySX127x/SX127x/board_config.py:62: RuntimeWarning: This channel is already in use, continuing anyway. Use GPIO.setwarnings(False) to disable warnings. GPIO.setup(BOARD.RST, GPIO.OUT) Traceback (most recent call last): File "/home/pi/pySX127x/./LORA_SERVER.py", line 98, in <module> lora = mylora(verbose=False) File "/home/pi/pySX127x/./LORA_SERVER.py", line 36, in init Oct 3 at 23:56
  • super(mylora, self).__init__(verbose) File "/home/pi/pySX127x/SX127x/LoRa.py", line 95, in init BOARD.add_events(self._dio0, self._dio1, self._dio2, self._dio3, self._dio4, self._dio5) File "/home/pi/pySX127x/SX127x/board_config.py", line 105, in add_events BOARD.add_event_detect(BOARD.DIO0, callback=cb_dio0) File "/home/pi/pySX127x/SX127x/board_config.py", line 101, in add_event_detect GPIO.add_event_detect(dio_number, GPIO.RISING, callback=callback) Oct 3 at 23:57
  • I understand that GPIO is used, but how i can release it for use Oct 3 at 23:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.