Skip to content

MicroPython library for controlling the SX1278 LoRa module over SPI.

License

Notifications You must be signed in to change notification settings

timokoethe/SX1278

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MicroPython library for the SX1278

MicroPython License: MIT

This repository provides a lightweight MicroPython 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:

# 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.

# 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.

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.

# 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

About

MicroPython library for controlling the SX1278 LoRa module over SPI.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages