Lora Module
The LoRa433_V1.1 Module is part of the M5Stack stackable module series. It is a LoRa communication module that operates at a 433MHz frequency and utilizes the Ra-02 module (SX1278 chip) solution.
Support the following products:
Micropython Example:
import os, sys, io
import M5
from M5 import *
from module import LoraModule
lora = LoraModule(pin_irq=35, pin_rst=13) # basic
lora = LoraModule(pin_irq=35, pin_rst=25) # core2
lora = LoraModule(pin_irq=10, pin_rst=5) # cores3
lora.send("Hello, LoRa!")
print(lora.recv())
def callback(received_data):
global lora
print(received_data)
lora.start_recv()
lora.set_irq_callback(callback)
lora.start_recv()
UIFLOW2 Example:
cores3_lora433_rx_example.m5f2
cores3_lora433_tx_example.m5f2
cores3_lora868_rx_example.m5f2
cores3_lora868_tx_example.m5f2
class LoraModule
Constructors
- class LoraModule(pin_cs, pin_irq, pin_rst, freq_band, sf, bw, coding_rate, preamble_len, output_power)
Initialize the LoRa module.
- Parameters:
pin_cs (int) – Chip select pin
pin_irq (int) – Interrupt pin
pin_rst (int) – Reset pin
freq_band – LoRa RF frequency in kHz.
sf (int) – Spreading factor, Higher spreading factors allow reception of weaker signals but have slower data rate.
bw (str) – Bandwidth value in kHz. Must be exactly one of BANDWIDTHS
coding_rate (int) – Forward Error Correction (FEC) coding rate is expressed as a ratio, `4/N`.
preamble_len (int) – Length of the preamble sequence, in units of symbols.
output_power (int) – Output power in dBm.
UIFLOW2:
Methods
- LoraModule.send(packet, tx_at_ms)
Send a data packet.
- Return (int):
The return value is the timestamp when transmission completed, as a`time.ticks_ms()` result. It will be more accurate if the modem was initialized to use interrupts.
- Parameters:
packet – The data packet to send.
tx_at_ms – Time to transmit the packet in milliseconds. For precise timing of sent packets, there is an optional `tx_at_ms` argument which is a timestamp (as a `time.ticks_ms()` value). If set, the packet will be sent as close as possible to this timestamp and the function will block until that time arrives
UIFLOW2:
- LoraModule.recv(timeout_ms, rx_length, rx_packet)
Receive a data packet.
- Return (RxPacket):
Returns None on timeout, or an `RxPacket` instance with the packet on success.
- Parameters:
timeout_ms – Optional, sets a receive timeout in milliseconds. If None (default value), then the function will block indefinitely until a packet is received.
rx_length (int) – Necessary to set if `implicit_header` is set to `True` (see above). This is the length of the packet to receive. Ignored in the default LoRa explicit header mode, where the received radio header includes the length.
rx_packet (RxPacket) – Optional, this can be an `RxPacket` object previously received from the modem. If the newly received packet has the same length, this object is reused and returned to save an allocation. If the newly received packet has a different length, a new `RxPacket` object is allocated and returned instead.
UIFLOW2:
- LoraModule.start_recv()
Start receiving data once, trigger an interrupt when data is received.
UIFLOW2:
- LoraModule.set_irq_callback(callback)
Set the IRQ callback function.
- Parameters:
callback – The callback function. The function should accept one argument, which is the received data.
UIFLOW2:
- LoraModule.standby()
Set the modem to standby mode.
UIFLOW2:
- LoraModule.sleep()
Set the modem to sleep mode.
UIFLOW2:
- LoraModule.irq_triggered()
Check if the IRQ has been triggered.
UIFLOW2:
Constants
- LoraModule.LORA_433
- LoraModule.LORA_868
Select the LoRa frequency band.
- LoraModule.BANDWIDTHS
Valid bandwidth