https://github.com/timokoethe/sx1278
MicroPython driver for the SX1278 LoRa module over SPI, built for Raspberry Pi Pico and Pico 2.
https://github.com/timokoethe/sx1278
embedded iot long-range lora micropython ra-01 raspberry-pi-pico rp2040 rp2350 spi sx1278 wireless
Last synced: about 2 months ago
JSON representation
MicroPython driver for the SX1278 LoRa module over SPI, built for Raspberry Pi Pico and Pico 2.
- Host: GitHub
- URL: https://github.com/timokoethe/sx1278
- Owner: timokoethe
- License: mit
- Created: 2025-04-02T11:31:41.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2026-04-06T12:19:58.000Z (about 2 months ago)
- Last Synced: 2026-04-06T13:32:37.149Z (about 2 months ago)
- Topics: embedded, iot, long-range, lora, micropython, ra-01, raspberry-pi-pico, rp2040, rp2350, spi, sx1278, wireless
- Language: Python
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MicroPython library for the SX1278
[](https://micropython.org/)
[](https://opensource.org/license/mit)
This repository provides a lightweight [MicroPython](https://micropython.org/) library for the Ra-01 LoRa module, based on the SX1278 chipset, designed for use with the Raspberry Pi Pico (RP2040) or the Raspberry Pi Pico 2 (RP2350). The library supports communication via SPI.
## Installation
Copy the file ```sx1278.py``` to the root directory of your microcontroller.
Then, import the module using ```from sx1278 import Lora```.
Ensure you are using the correct frequency for your region.
You can adjust this at the top of the library file by modifying the relevant variable.
## Setup
First connect and setup SPI for the LoRa module:
```python
# Setup SPI
spi = SPI(0, baudrate=10000000,
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()
```
Next, setup the module. Make sure to connect cs, rx and rst pins correctly.
```python
# Setup the lora module
lr = Lora(spi,
cs=Pin(CS, Pin.OUT),
rx=Pin(RX, Pin.IN),
rs=Pin(RS, Pin.OUT))
```
## Sending Data
This method blocks until the sending is completed. The maximum package length is 255 bytes.
```python
lr.send('Hello World!')
```
## Receiving Data
The module operates in receiving mode to receive data. When a message is received, a handler is executed.
To keep the program running, use a loop where any necessary break conditions can be implemented.
```python
# Handles incoming messages
def handler(message):
print(message)
# Puts module back in receiving mode
lr.recv()
# Sets handler
lr.on_recv(handler)
# Puts module in receiving mode
lr.recv()
# Prevents the program from stopping
while True:
pass
```