Package: numato-gpio
Python API for Numato GPIO ExpandersThis Python API can be used to controlNumato USB
GPIO expanders.Configure ports as input or output portWrite to output portsRead from input portsRead integer values from ADC input ports (1 - 7)Register a callback for input port events (edge detection)See thechangelogfor details on the releases.InstallationInstall latest development version:pip install --user git+https://github.com/clssn/numato-gpio.gitInstall latest release:pip install --user numato-gpioUsage CLITest whether your devices can be found running the command-line interface likepython3 -m numato_gpio. Remember to have your user in thedialoutgroup,
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 | ports: 32 | eol: '\r\n' | iodir: 0xffffffff | iomask: 0x00000000 | state: 0x00000000
dev: /dev/ttyACM1 | id: 1 | ver: 9 | ports: 32 | eol: '\r\n' | iodir: 0xffffffff | iomask: 0x00000000 | state: 0x00000000Usage APIThe API can be used like:importnumato_gpioasgpio# You can instantiate the device directly from its OS identifier, for instance# "/dev/ttyACM0" on Linux or "COM5" on Windows.dev=gpio.NumatoUsbGpio("/dev/ttyACM0")# Alternatively, you can use the discovery function, but it is limited to# Linux' /dev/ttyACM* devices. This is because discovery will open and try to# interact with any device. This can lead to errors in unrelated devices.# Under windows the naming scheme is entirely flat (COMx) increasing the error# potential, so no discovery here.# my_device_id = 0# gpio.discover()# dev = gpio.devices[my_device_id]# Configure port 4 as output and set it to highdev.setup(4,gpio.OUT)dev.write(4,1)# Configure port 27 as input and print its logic leveldev.setup(27,gpio.IN)print(dev.read(27))# Configure port 2 as input and print its ADC valuedev.setup(2,gpio.IN)print(dev.adc_read(2))# Configure port 14 as input and setup notification on logic level changesdev.setup(14,gpio.IN)defcallback(port,level):print("{edge:7s}edge detected on port{port}""-> new logic level is{level}".format(edge="Rising"iflevelelse"Falling",port=port,level="high"iflevelelse"low"))dev.add_event_detect(14,callback,gpio.BOTH)dev.notify=TrueRelease VersionsSeechangelog.TroubleshootingIn case your device can't be discovered or you even get an error message or
stacktrace, please follow thetroubleshooting guide.Known IssuesThough the code works well in aHome Assistantintegration since 2018, there are quite some aspects to improve. The following
issues are only the ones the author is aware of:Some docstrings are hard to understandDevice discovery/registry as module-global dict is sub-optimalOnly/dev/ACMxdevices are scanned which were mapped on the author's LinuxNo async API availableSystem TestsUnit tests in thetestsdirectory are using a device mockup which mimicks
a Numato device's responses as far as known at the state of development.System tests in thesys_testsfolder are meant to be run using a real device
and will just fail, if no device is connected. They are an important complement
to unit tests, because they arethe real thingand might behave differently
than the mockup device for the unit tests.If you consider to run system tests you should be aware that it may be dangerous
running them.WARNINGOnly run the system tests withgpio ports disconnected! You otherwise risk
a short circuit which may lead to damage or destruction of your device or
even fire.