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 the LICENSE file for details.

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

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.1.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.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: numato_usb_gpio-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 eb90317fc672480a4a772028e82eccd3992093ac64cf033128b813d89d590ce2
MD5 0d7fe2f8d9b7bac10fea3d6c35806e53
BLAKE2b-256 1c9c021346b287aa422621d503c4427d247669829c9fd8e2dd0385b32295b32c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for numato_usb_gpio-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0781d94fe774aea07d4925f565f92d844e74d96a158f1a50d6f8d610eaeb11de
MD5 ef860b50ad0e8b6f1638da7115d4a67e
BLAKE2b-256 ce0d07bd79ed19b90ecbea1ae342924931c224a40fb0e0c858573827ed6a2af2

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