Lightweight MicroPython driver for the Ra-01 LoRa module based on the SX1278 chipset, with a setup focused on the Raspberry Pi Pico (RP2040) and Raspberry Pi Pico 2 (RP2350).
The library communicates over SPI and provides a simple API for sending and receiving LoRa packets.
- MicroPython-first API with minimal setup
- Works with Raspberry Pi Pico and Pico 2
- Blocking packet transmission with
send() - Interrupt-driven packet reception with
on_recv() - Configurable frequency, bandwidth, spreading factor, coding rate, and CRC
Copy sx1278.py to the root of your MicroPython device, then import it in your script:
from sx1278 import LoraExample wiring used by the snippets below:
| SX1278 / Ra-01 | Raspberry Pi Pico | Used in code |
|---|---|---|
| MISO | GP0 | MISO = 0 |
| DIO0 | GP10 | RX = 10 |
| SCK | GP2 | SCK = 2 |
| MOSI | GP3 | MOSI = 3 |
| RST | GP16 | RST = 16 |
| NSS | GP1 | CS = 1 |
| GND | GND | power |
| 3V3 | 3V3(OUT) | power |
Set up SPI first:
from machine import Pin, SPI
from sx1278 import Lora
SCK = 2
MOSI = 3
MISO = 0
CS = 1
RX = 10
RST = 16
spi = SPI(
0,
baudrate=10_000_000,
sck=Pin(SCK, Pin.OUT, Pin.PULL_DOWN),
mosi=Pin(MOSI, Pin.OUT, Pin.PULL_UP),
miso=Pin(MISO, Pin.IN, Pin.PULL_UP),
)
spi.init()Then create the LoRa instance:
lr = Lora(
spi,
cs=Pin(CS, Pin.OUT),
rx=Pin(RX, Pin.IN),
rs=Pin(RST, Pin.OUT),
)send() blocks until transmission has finished. The maximum payload length is 255 bytes.
lr.send("Hello World!")Register a receive handler, put the module into receive mode, and keep the script running:
def handler(message):
print(message)
# Put the module back into receive mode after handling a packet.
lr.recv()
lr.on_recv(handler)
lr.recv()
while True:
passReady-to-run examples for the Raspberry Pi Pico are included in the example directory:
- Use a frequency that is legal for your region.
- The default frequency in
sx1278.pyis433.1MHz. - You can override the default by passing
frequency=when creatingLora, or by changing the module constant in the library.
This project is licensed under the MIT License. See LICENSE.