sx127x.py lib #11515
Replies: 5 comments 82 replies
-
For a LoRa TX module that I put into deepsleep I had to do a power-on reset. I use a circuit that that pulls the EN line for a short period. I have contacted the author of the LoRa code that I am using to see if he can make any suggests re CAD or similar. |
Beta Was this translation helpful? Give feedback.
-
Here are my test scripts to stop the crash: LoRaReceiver.py from machine import Pin
import utime
red_led = Pin(19, Pin.OUT) # red LED
def receive(lora):
print("LoRa Receiver")
while True:
if lora.received_packet():
print('something here')
utime.sleep_ms(10)
payload = lora.read_payload()
red_led.on()
print(payload)
utime.sleep_ms(10)
utime.sleep(1)
red_led.off() main.py import LoRaReceiver
from config import *
from machine import Pin, SPI
from sx127x import SX127x
import utime
red_led = Pin(19, Pin.OUT) # red LED
device_spi = SPI(baudrate = 10000000,
polarity = 0, phase = 0, bits = 8, firstbit = SPI.MSB,
sck = Pin(device_config['sck'], Pin.OUT, Pin.PULL_DOWN),
mosi = Pin(device_config['mosi'], Pin.OUT, Pin.PULL_UP),
miso = Pin(device_config['miso'], Pin.IN, Pin.PULL_UP))
reset_pin = Pin(device_config['reset'], Pin.OUT)
# reset the RFM96W after a re-boot or when coming out of deepsleep()
reset_pin.off()
utime.sleep_ms(50)
reset_pin.on()
utime.sleep_ms(50)
lora = SX127x(device_spi, pins=device_config, parameters=lora_parameters)
if __name__ == '__main__':
LoRaReceiver.receive(lora) and your config.py |
Beta Was this translation helpful? Give feedback.
-
No progress on CAD until I understand why my setup doesn't work. When you come out of deepsleep could you skip the chip initialisation? |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Spent a few fruit-less hours comparing onReceive() and handleOnReceive() in various distributions. So, I thought I'd take your wake on RxDone example and just change the import esp32
import utime
from machine import Pin, SoftSPI
from sx127x import SX127x
import machine
cnfg = {'miso':12, 'mosi':13, 'ss':15, 'sck':14, 'dio_0':5, 'reset':4}
loracnfg = {'frequency':433E6, 'tx_power_level':17, 'signal_bandwidth':125E3, 'spreading_factor': 8, 'coding_rate':5, 'preamble_length':8, 'implicit_header':0, 'sync_word':0x12, 'enable_CRC':0, 'invert_IQ':0} # sync_word: 0x34=public, 0x12=private
spi = SoftSPI(baudrate = 10000000, polarity = 0, phase = 0, bits = 8, firstbit = SoftSPI.MSB, sck = Pin(cnfg['sck'],Pin.OUT,Pin.PULL_DOWN), mosi = Pin(cnfg['mosi'],Pin.OUT,Pin.PULL_UP), miso = Pin(cnfg['miso'],Pin.IN,Pin.PULL_UP))
red_led = Pin(21, Pin.OUT) # red LED
reset_pin = Pin(cnfg['reset'], Pin.OUT)
rxDone_interrupt = False
red_led.off()
reset_pin.off()
# reset the RFM96W after a re-boot
utime.sleep_ms(50)
reset_pin.on() # needs to stay high until reset
lora = SX127x(spi, pins = cnfg, parameters = loracnfg)
lora.receive()
def handle_interrupt(xyz): # needs something in the brackets
global rxDone_interrupt
rxDone_interrupt = True
# GPIO connected to DIO0 for rxDone high.
pir = Pin(26, Pin.IN, Pin.PULL_DOWN)
pir.irq(trigger=Pin.IRQ_RISING, handler=handle_interrupt)
def process_rx_msg():
global rxDone_interrupt
global lora
if (rxDone_interrupt == True):
rxDone_interrupt = False
# process the received message
msg = b'xyz'
red_led.on()
Rx = lora.read_payload()
if Rx:
try:
msg,rssi,snr = Rx,lora.packet_rssi(),lora.packet_snr()
print('msg', msg, ' rssi', rssi, ' snr', int(snr))
utime.sleep_ms(10)
# process msg
utime.sleep_ms(500)
red_led.off()
# re-init every loop
lora = SX127x(spi, pins = cnfg, parameters = loracnfg)
lora.receive()
# blink the Red LED
red_led.on()
utime.sleep_ms(250)
red_led.off()
print('you have 2 seconds to do a CTRL-C')
utime.sleep(2)
while True:
process_rx_msg()
if not process_rx_msg():
# blink the Red LED to show there is no rx_msg
red_led.on()
utime.sleep_ms(250)
red_led.off()
utime.sleep_ms(250) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Just wondering if anyone has experience of the sx127x.py lora lib behaviour after an esp32 deepsleep? I'm getting a lot of
after the esp32 wakes up, often the invalid version is 252 instead of 80. I took a look around the offending line in the lib
it appears that a version register is supposed to change from 0x42 to 0x12 but isn't? I'm trying to get the sx1276 module to listen for lora packets while the esp32 is in deepsleep but I need to fix this problem first because I can't see what's been going on with the lora during deepsleep if there is a persistent crash after deepsleep.
Beta Was this translation helpful? Give feedback.
All reactions