Python API for Numato GPIO Expanders
Project description
Python API for Numato GPIO Expanders
This Python API can be used to control Numato 32 Port USB GPIO expanders.
- Configure ports as input or output port
- Write to output ports
- Read from input ports
- Read integer values from ADC input ports (1 - 7)
- Register a callback for input port events (edge detection)
See the changelog for details on the releases.
Installation
Install latest development version:
pip install --user git+https://github.com/clssn/numato-gpio.git
Install latest release:
pip install --user numato-gpio
Usage CLI
Test whether your devices can be found running the command-line interface like
python3 -m numato_gpio
. Remember to have your user in the dialout
group,
since the devices are registered as /dev/ttyACMx (i.e. modem devices).
Expected output:
❯ python3 -m numato_gpio
dev: /dev/ttyACM0 | id: 0 | ver: 9 | iodir: 0xffffffff | iomask: 0x00000000 | state: 0x00000000
dev: /dev/ttyACM1 | id: 1 | ver: 9 | iodir: 0xffffffff | iomask: 0x00000000 | state: 0x00000000
Usage API
The API can be used like:
import numato_gpio as gpio
my_device_id = 0
gpio.discover()
dev = gpio.devices[my_device_id]
# configure port 4 as output and set it to high
dev.setup(4, gpio.OUT)
dev.write(4, 1)
# configure port 27 as input and print its logic level
dev.setup(27, gpio.IN)
print(dev.read(27))
# configure port 2 as input and print its ADC value
dev.setup(2, gpio.IN)
print(dev.adc_read(2))
# configure port 14 as input and setup notification on logic level changes
dev.setup(14, gpio.IN)
def callback(port, level):
print("{edge:7s} edge detected on port {port} "
"-> new logic level is {level}".format(
edge="Rising" if level else "Falling",
port=port,
level="high" if level else "low")
)
dev.add_event_detect(14, callback, gpio.BOTH)
dev.notify = True
Release Versions
See changelog.
Troubleshooting
In case your device can't be discovered or you even get an error message or stacktrace, please follow the troubleshooting guide.
Known Issues
Though the code works well in a Home Assistant integration since 2018, there are quite some aspects to improve. The following issues are only the ones the author is aware of:
- No unit tests
- Some docstrings are hard to understand
- Device discovery/registry as module-global dict is sub-optimal
- Only
/dev/ACMx
devices are scanned which were mapped on the author's Linux
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for numato_gpio-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 118e39b3dc31cc11ed9371ec89262b51d9cd620fe3b1dac48b6a4ec7d3011916 |
|
MD5 | df8980964861c8f0df319d7e55ebb1d7 |
|
BLAKE2b-256 | 2b2eb2562c11b1737396eaea64350690c7c17ff66cdbc6000c97d60b8de12858 |