Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions LoRaRF/SX127x.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,9 @@ def readRegister(self, address: int) -> int :
def _transfer(self, address: int, data: int) -> int :

buf = [address, data]
self._cs.output(LoRaGpio.LOW)
if self._cs is not None: self._cs.output(LoRaGpio.LOW)
feedback = self._spi.transfer(buf)
self._cs.output(LoRaGpio.HIGH)
if self._cs is not None: self._cs.output(LoRaGpio.HIGH)
if (len(feedback) == 2) :
return int(feedback[1])
return -1
54 changes: 31 additions & 23 deletions LoRaRF/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,44 @@ def __init__(self, chip: int, offset: int):
self.chip = "/dev/gpiochip" + str(chip)
self.offset = offset
self.seqno = 0
self.request = None

def output(self, value: Value):
with gpiod.request_lines(
self.chip,
consumer="LoRaGpio",
config={self.offset: gpiod.LineSettings(direction=Direction.OUTPUT)}
) as request:
request.set_value(self.offset, value)
if self.request is None:
self.request = gpiod.request_lines(
self.chip,
consumer="LoRaGpio",
config={self.offset: gpiod.LineSettings(direction=Direction.OUTPUT)}
)
self.request.set_value(self.offset, value)

def input(self):
with gpiod.request_lines(
self.chip,
consumer="LoRaGpio",
config={self.offset: gpiod.LineSettings(direction=Direction.INPUT)}
) as request:
return request.get_value(self.offset)
if self.request is None:
self.request = gpiod.request_lines(
self.chip,
consumer="LoRaGpio",
config={self.offset: gpiod.LineSettings(direction=Direction.INPUT)}
)
return self.request.get_value(self.offset)

def monitor(self, callback, timeout: float):
t = time.time()
with gpiod.request_lines(
self.chip,
consumer="LoRaGpio",
config={self.offset: gpiod.LineSettings(edge_detection=Edge.RISING)}
) as request:
while (time.time() - t) < timeout or timeout == 0:
for event in request.read_edge_events():
if event.line_seqno != self.seqno:
self.seqno = event.line_seqno
callback()
return
if self.request is None:
self.request = gpiod.request_lines(
self.chip,
consumer="LoRaGpio",
config={self.offset: gpiod.LineSettings(edge_detection=Edge.RISING)}
)
while (time.time() - t) < timeout or timeout == 0:
for event in self.request.read_edge_events():
if event.line_seqno != self.seqno:
self.seqno = event.line_seqno
callback()
return

def monitor_continuous(self, callback, timeout: float):
while True:
self.monitor(callback, timeout)


class BaseLoRa :
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This readme is written for quick start guide. Visit this [link](https://github.c

Theoritically all LoRa modules using SX126x series (SX1261, SX1262, SX1268), SX127x series (SX1272, SX1276, SX1277, SX1278, SX1279), or LLCC68 will compatible using this library. Some LoRa module which already tested and confirmed compatible are:
* Ebyte: E22-400M22S, E22-900M22S, E22-400M30S, E22-900M30S
* generic RFM 95

Currently only Raspberry pi zero, zero W, 3A, 3B, 3B+, 4A, and 4B supported as host controller. Support for other single board computer will be added in the future. The Linux distro already tested using this library are:
* Raspberry pi OS
Expand Down Expand Up @@ -51,16 +52,23 @@ pip install LoRaRF

## Initialization

To work with the library, first you must import `SX126x` or `SX127x` python module depending LoRa module you use. Then initialize the module by creating an object.
To work with the library, first you must import `SX126x` or `SX127x` depending LoRa module you use and the LoRaSpi and LoRaGpio. Before the module initialization, you need to create the SPI, RESET, CS pin objects. Then initialize the module by creating an object.

```python
from LoRaRF import LoRaSpi, LoRaGpio
spi = LoRaSpi(1, 0) # /dev/spidev1.0
cs = LoRaGpio(1, 8) # /dev/gpiochip1 line #8
reset = LoRaGpio(1, 2) # /dev/gpiochip1 line #2
...

# for SX126x series or LLCC68
from LoRaRF import SX126x
LoRa = SX126x()
busy = LoRaGpio(1,3)
LoRa = SX126x(spi, cs, reset, busy, irq: Optional[LoRaGpio]=None, txen: Optional[LoRaGpio]=None, rxen: Optional[LoRaGpio]=None)

# for SX127x series
from LoRaRF import SX127x
LoRa = SX127x()
LoRa = SX127x(spi, cs, reset, irq: Optional[LoRaGpio]=None, txen: Optional[LoRaGpio]=None, rxen: Optional[LoRaGpio]=None)
```

Before calling any configuration methods, doing transmit or receive operation you must call `begin()` method.
Expand Down Expand Up @@ -93,21 +101,16 @@ The default SPI port is using bus id 0 and cs id 0. The default GPIO pins used f

### SPI Port Configuration

To configure SPI port or SPI frequency call `setSPI()` method before `begin()` method.
To configure SPI port or SPI frequency call `setSPI()` method.
```python
# set to use SPI with bus id 0 and cs id 1 and speed 7.8 Mhz
LoRa.setSPI(0, 0, 7800000)
LoRa.begin()
# set to use SPI speed 7.8 Mhz
LoRa.setSPI(7800000)
```

### I/O Pins Configuration

To configure I/O pins (NSS, RESET, BUSY, IRQ, TXEN, RXEN pin) call `setPins()` before `begin()` method.
```python
# set RESET->22, BUSY->23, DIO1->26, TXEN->5, RXEN->25
LoRa.setPins(22, 23, 26, 5, 25)
LoRa.begin()
```
Other I/O pins (NSS, RESET, BUSY, IRQ, TXEN, RXEN pin) need to be created before the creation of the SX12xy object.


## Modem Configuration

Expand Down Expand Up @@ -201,5 +204,5 @@ See examples for [SX126x](https://github.com/chandrawi/LoRaRF-Python/tree/main/e

[Chandra Wijaya Sentosa](https://github.com/chandrawi) <<chandra.w.sentosa@gmail.com>>

### Upcoming features...
Base class will allow for python3-libgpiod package
### New features...
Base class supports python3-libgpiod package, no longer compatible to libgpiod < 2.0
Binary file removed dist/LoRaRF-1.4.0-py3-none-any.whl
Binary file not shown.
Binary file added dist/lorarf-2.0.0-py3-none-any.whl
Binary file not shown.
12 changes: 5 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
[metadata]
name = LoRaRF
version = 1.4.0
version = 2.0.0
author = Chandra Wijaya Sentosa
author_email = chandra.w.sentosa@gmail.com
description = Python library used for basic transmitting and receiving data using LoRa modem
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/chandrawi/LoRaRF-Python
project_urls =
Bug Tracker = https://github.com/chandrawi/LoRaRF-Python/issues
project_urls = Bug Tracker = https://github.com/chandrawi/LoRaRF-Python/issues
license = MIT
classifiers =
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
Operating System :: POSIX :: Linux
Topic :: System :: Hardware
Topic :: System :: Hardware :: Hardware Drivers
Expand All @@ -21,7 +19,7 @@ classifiers =
include_package_data = True
packages =
LoRaRF
python_requires = >=2.7
python_requires = >=3.9
install_requires =
spidev
RPi.GPIO
gpiod >=2.0.2