• ...
  • base images
  • SDK
  • ...
  • ...
  • tools
  • premade packages

Access GPIOs#

GPIOs can be accessed with libgpiod and its command line tooling

  • gpioset

  • gpioget

But it is not working for Intel SOMs.

libsimplecoreio#

To create a reliable mapping between libgpiod and the GPIO on the respective board, we provide libsimplecoreio.

libsimplecoreio is a small library can can be freely integrated into your code.

Usage in C#

A struct gpiod_line * pointer can be obtained using simplecoreio_get_gpio().

struct gpiod_chip *chip;
struct gpiod_line *line = simplecoreio_get_gpio("GPIO8", &chip);
gpiod_line_request_output(line, "mscio-lib2-test", 0);
gpiod_line_set_value(line, 1);
gpiod_chip_close(chip);

Usage in Python#

A gpiod.Line handle can be obtained using simplecoreio.get_gpio().

line = simplecoreio.get_gpio("GPIO8")
line.request("mscio-lib2-test", gpiod.LINE_REQ_DIR_OUT)
line.set_value(1)
line.release()

Usage from command line#

From command line you can call

simplecoreio-list
GPIO0    gpiochip0        11
GPIO1    gpiochip3        1
GPIO2    gpiochip3        2
GPIO3    gpiochip3        3
GPIO4    gpiochip3        29
GPIO5    gpiochip4        2
GPIO6    gpiochip3        18
GPIO7    gpiochip0        10
GPIO8    gpiochip3        20
GPIO9    gpiochip3        21
GPIO10   gpiochip3        22
GPIO11   gpiochip3        28
GPIO12   gpiochip3        19
GPIO13   gpiochip3        0

which lists all supported GPIOs and their libgpiod information.

It is also possible to get the value of a GPIO and set the value of a GPIO using simplecoreio-get and simplecoreio-set tools.

For example for GPIO0:

simplecoreio-set GPIO0 1
simplecoreio-get GPIO0
1

You could get the same result with gpioget and gpioset (except on Intel SOMs) using:

gpioset $(simplecoreio-list | grep GPIO0 | cut -d' ' -f2-)=1
gpioget $(simplecoreio-list | grep GPIO0 | cut -d' ' -f2-)

This means that simplecoreio-set sets the value of a GPIO as long as it is running. If you want the value to be persistent, you can take a look at GPIO Manager.

Important

Only one application can hold a GPIO (e.g. gpiod_line_request_output) at a time.

Another application can only access the same GPIO after the first application released it again (e.g. gpiod_line_release).

Appropriate error handling should be implemented into each application’s workflow.