From Fedora Project Wiki

Revision as of 21:38, 20 August 2018 by Alciregi (talk | contribs) (Created page with "= Using the GPIO = == GPIO sysfs deprecation == GPIO sysfs interface is deprecated upstream: https://www.kernel.org/doc/Documentation/gpio/sysfs.txt so the Fedora is compile...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Using the GPIO

GPIO sysfs deprecation

GPIO sysfs interface is deprecated upstream: https://www.kernel.org/doc/Documentation/gpio/sysfs.txt so the Fedora is compiled without such option.
As a consequence, many examples you will find on internet are not working on Fedora.
To use this device we can't use ordinary commands line tools (echo, cat, etc), but you have to go through some library or cli tools.

gpiod

To use the GPIO we need to interact with the character devices named /dev/gpiochipN
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/tree/README

To interact with the GPIO we can use the command line interfaces provided by the libgpiod-utils package or the python3-libgpiod Python library.

sudo dnf install libgpiod-utils python3-libgpiod

libgpiod CLI examples

List all gpiochips present on the system, their names, labels and number of GPIO line.

sudo gpiodetect

List all lines of specified gpiochips, their names, consumers, direction, active state and additional flags.
Names should be provided by the DTB, but at least in the RPi3 there are no names. However, at least on the RPi3, the line number matches the BCM number.

sudo gpioinfo

Set to high (i.e. turn on an LED) the value of BCM#21, then exit immediately.

sudo gpioset gpiochip0 21=1

Set to high the value of BCM#21, then wait for 4 seconds.

sudo gpioset -s 4 --mode=time gpiochip0 21=1

Read the value of a GPIO line (BCM#20).

sudo gpioget gpiochip0 20

Monitor the events (rising of falling edges, i.e. a button) of BCM#20

sudo gpiomon 0 20

Python

https://github.com/brgl/libgpiod/tree/master/bindings/python/examples