Digital I/O
Overview⚓︎
Digital I/O is handled by the Linux GPIO subsystem. This is a generic interface that organizes the GPIO pins by the hardware chips that input or output digital signals. The interface is generic and presents a large number of inputs and outputs in the system, mostly internal.
Platform specific⚓︎
Getting started⚓︎
Where possible, it is recommended to use the modern (since Linux v4.8) GPIO API. It is implemented by libgpiod, which also provides high-level bindings for C++, Python, GLib, and Rust.
The library comes with a set of command-line tools that can be used from shell scripts to inspect and control GPIO lines:
gpiodetect-- list all gpiochips present on the system, their names, labels, and number of GPIO linesgpioinfo-- list GPIO lines, their chip, offset, name, direction, and additional attributesgpioget-- read values of specified GPIO linesgpioset-- set values of specified GPIO linesgpiomon-- wait for edge events on GPIO linesgpionotify-- wait for line-info change events on GPIO lines
libgpiod v1.x⚓︎
In libgpiod v1.x, GPIO lines are typically addressed by gpiochip and line
offset. To work with named lines, gpiofind can be used to look up the chip
name and offset first.
Example:
libgpiod v2.x⚓︎
In libgpiod v2.x, gpiofind was removed. Its functionality was absorbed into
the other tools, which can resolve GPIO line names directly.
When using gpioset, note that the line state is only maintained while
the process is running. For scripts, this means that gpioset must be
kept alive long enough for the requested output to remain asserted.
See the libgpiod command-line tools documentation
for details.
Example:
Note: Only the HMX platform currently uses libgpiod v2.x.