Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wybiral/micropython-lora
MicroPython library for controlling a Semtech SX127x LoRa module over SPI.
https://github.com/wybiral/micropython-lora
Last synced: 3 months ago
JSON representation
MicroPython library for controlling a Semtech SX127x LoRa module over SPI.
- Host: GitHub
- URL: https://github.com/wybiral/micropython-lora
- Owner: wybiral
- License: mit
- Created: 2020-08-24T20:20:59.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T16:11:14.000Z (over 1 year ago)
- Last Synced: 2024-04-29T11:33:12.398Z (6 months ago)
- Language: Python
- Size: 7.81 KB
- Stars: 30
- Watchers: 5
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-micropython - micropython-lora - MicroPython library for controlling a Semtech SX127x LoRa module over SPI. (Libraries / Communications)
README
# micropython-lora
MicroPython library for controlling a Semtech SX127x LoRa module over SPI.The logic for the code came from [this module](https://github.com/Wei1234c/SX127x_driver_for_MicroPython_on_ESP8266) but was streamlined and rewritten to be more MicroPython-friendly.
## Examples
### Initialize
The module requires an SPI bus connected to the SX127x, one pin to be `cs` (chip select), and one to be the `rx` (receive IRQ).
```
lora = LoRa(
spi,
cs=Pin(CS, Pin.OUT),
rx=Pin(RX, Pin.IN),
)
```### Sending
You can send bytes or a string (which will be encoded to bytes). A ValueError exception will be raised if the message exceeds the allowed payload length. Currently this method blocks until the message is sent.
```
lora.send('Hello world!')
```### Receiving
Receiving is done by attaching a handler using `on_recv` and then calling `recv` to put the device in receive mode. Receive mode is non-blocking so other code can run after calling `recv` but if you call `send` afterward you will need to put the device back into receive mode again.
```
def handler(x):
print(x)lora.on_recv(handler)
lora.recv()
```