Skip to content

Manual GPIO control

Note

The script to manually control GPIOs is only there for test and development purposes. Applications are not using these scripts to control GPIOs.

The GPIO control script is available at /srv/gpio.sh.

Display GPIO list

The GPIO control script can be used to display the GPIO list. The names from this list should be used to manually control the GPIO in the following sections.

$ /srv/gpio.sh list

GPIO set

The GPIO control script can be used to set a value to an output channel

Usage:

$ /srv/gpio.sh set IO_NAME [VALUE]

For digital output, the value can either be 0 or 1 (default 1).
For a PWM channel, value is the duty cycle in % (default 100).
For a LED, the value is the brightness (default max_brightness).

GPIO reset

The GPIO control script can be used to reset the value of an output channel (typically turns off)

Usage:

$ /srv/gpio.sh reset IO_NAME

GPIO get

The GPIO control script can be used to read the value of an input channel

Usage:

$ /srv/gpio.sh get IO_NAME

GPIO watch

The GPIO control script can be used to Read the value of an input channel in an infinite loop

Usage:

$ /srv/gpio.sh watch IO_NAME [REFRESH_DELAY]

GPIO control in your application

The GPIO hardware is exposed in the file system under /sys/class/gpio

The following documentation can help: GPIO Sysfs Interface for Userspace

Note that the GPIO IDs are available in the file /srv/io.map

You can use Path from pathlib package in Python to access the files.