Skip to main content

A small USB GPIO example package

Project description

Python API for Numato USB GPIOs

This Python API can be used to control Numato USB GPIO expanders.

  • Configure GPIOs as input or output port
  • Write to output ports
  • Read from input ports
  • Read integer values from ADC input ports

numato-usb-gpio allows to control gpio modules (Set or Clear states). This module is compatible with all Numato USB GPIO series.

Requirement

The module requires the minimum configuration :

  • Windows-10(64 bits) and later
  • Linux 64-bits
  • Python3.6 and later

License

This API is licensed under the GNU Lesser General Public License v3.0. See LICENSE for full license text.

Installation

Install the latest release:

pip install numato_usb_gpio

Usage CLI

Linux :
Test whether your devices can be found running the command-line interface like python3 -m numato_usb_gpio.gpio. Remember to have your user in the dialout group, since the devices are registered as /dev/ttyACMx (i.e. modem devices). The default Baudrate is 921600.

Expected output:

❯ python3 -m numato_usb_gpio.gpio
Discovered devices:
dev: /dev/ttyACM0 | id: 00000000 | ver: 00000009 | ports: 32 | eol: '\r' | state: 0xFFFFFFFF
dev: /dev/ttyACM1 | id: 12345678 | ver: A0M10.01 | ports: 16 | eol: '\r' | state: 0xFFFF


Windows : Test whether your devices can be found running the command-line interface like python -m numato_usb_gpio.gpio.The default Baudrate is 921600. Expected output:

❯ python -m numato_usb_gpio.gpio
Discovered devices:
dev: COM27 | id: 00000000 | ver: 00000009 | ports: 32 | eol: '\r' | state: 0xFFFFFFFF
dev: COM5 | id: 12345678 | ver: A0M10.01 | ports: 16 | eol: '\r' | state: 0xFFFF

How to use it

The command line example:

Windows :

python -m numato_usb_gpio.gpio --gpios=8 --port=<port> --baudrate=<baudrate> 

Linux :

python3 -m numato_usb_gpio.gpio --gpios=8 --port=<port> --baudrate=<baudrate> 


Parameters are :

--gpios : the number of gpios to drive (default is 8)

--port : the port (default is /dev/ttyUSB1 or "COM1")

--baudrate : the baudrate (default is 921600)

--name : the type of Numato Usb gpio module name (default is "USB", change the name as "USBG" for NL-USBG-C usb gpio modules).

Note : For all CLI commands use python3 when using in Linux Systems and python in Windows Systems.

List of Functions

  1. ver()
  2. id_get()
  3. id_set("x")
  4. info()
  5. gpio_set("x")
  6. gpio_clear("x")
  7. gpio_read("x")
  8. gpio_iomask("x")
  9. gpio_iodir("x")
  10. gpio_writeall("x")
  11. gpio_readall()
  12. adc_read("x")
  13. notigy_get()
  14. notify_set("x")
  15. gpio_poweron("x","x")
  16. gpio_setup("x","x")

Note: "x" is the parameter to be passed in the functions, please refer the "sending commands" section in the user manual of each module for sending the right arguement and to understand the functioning of each command.

Usage API

The API can be used like:

from numato_usb_gpio.gpio import Gpio 

# Please change the number of Gpios, COM Port and name accordingly.
Device = Gpio(numberGpios=32, port="COM27", name="USB") 

# To get the version of the module
version=Device.ver()
print(version)

# To get the Device Id 
Device.id_get()

# To Set all the gpios
Device.gpio_writeall("ffffffff")

# To get the Power-On Status of the module
Device.info()

# To set a single Gpio & read the status
Device.gpio_set(0)
print(Device.gpio_read(0))

# To change the direction of any port
Device.gpio_setup([0],"OUT")       // [ ports ] and direction : IN/OUT 
Device.gpio_setup([1,3,8],"OUT")

# Setting the Gpio Power-On Direction & Value
Device.gpio_poweron("00000000","0000ffff")

# Enable notify
Device.notify_set(1)  // 0 - Disable and 1 - Enable notify feature

Release Revisions

  • 0.0.2 — Updated LICENSE url.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numato_usb_gpio-0.0.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numato_usb_gpio-0.0.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file numato_usb_gpio-0.0.2.tar.gz.

File metadata

  • Download URL: numato_usb_gpio-0.0.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for numato_usb_gpio-0.0.2.tar.gz
Algorithm Hash digest
SHA256 aea44c7d1681decbbbbeb09a662a36512d9c80b708617fe9e8d9d92152fd153c
MD5 277d3f019487ced5e28d35ad05b01e72
BLAKE2b-256 72d302074c2757013ab2f0edb8b6732ea805dd7582e7e6e638230e7f805fc7cc

See more details on using hashes here.

File details

Details for the file numato_usb_gpio-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for numato_usb_gpio-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c5172eac816c95921999623240b5cc1fcd58817b4396a38c4ffc1265025e116
MD5 32f854f5ef94476460eae5f9d7726bd6
BLAKE2b-256 6bc2fe6f1b513bf28207d54af0fd506ca10b2c8544fba4fe51d8b86a40cddb27

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page