Skip to content
systemcoding.dev
Embedded Linux

Drive a GPIO line high with gpioset -c chip line=1

Set a GPIO output with gpioset from libgpiod 2.x, selecting the chip with -c, and keep the process alive because the line reverts when it exits.

1 min read
Summarize in AI

Shell scripts that toggled /sys/class/gpio stopped working once the sysfs interface was deprecated. The replacement is the character device, and gpioset from libgpiod 2.x drives it.

Shell
gpioset -c gpiochip0 17=1

In libgpiod 2 the chip comes from -c and each line is offset=value. The behaviour that surprises people from v1 is that the line is held only while gpioset runs, because the kernel releases a requested line when its file descriptor closes, and the pin returns to its default. In v2 the command stays in the foreground until you press Ctrl-C, which is exactly why the LED stays lit. To leave it running in the background use --daemonize, and to pulse it use --toggle:

Shell
gpioset -c gpiochip0 --daemonize 17=1
gpioset -c gpiochip0 --toggle 500ms,500ms,0 17=1
Text
$ gpioinfo -c gpiochip0 17
line  17: "GPIO17"  "gpioset"  output  active-high  [used]

The second command blinks the line once at 500 ms intervals and then leaves it inactive; the final 0 ends the sequence. The gpioinfo layout shown is representative, and the consumer name gpioset appears only while the line is held. Line names and the number of lines depend on the board's device tree. See the libgpiod tools documentation. The v1 syntax, gpioset gpiochip0 17=1, is rejected by v2.

Also inHardware
Share

More snippets

Kernels

Get a GPIO descriptor with devm_gpiod_get

devm_gpiod_get() looks up a named GPIO from the device tree, sets its direction and initial level, and releases it on unbind; use it instead of gpio numbers.

1 min read
Embedded Linux

Choose the hardware target with MIX_TARGET

Set MIX_TARGET to a Nerves target such as rpi4 before running mix commands, so dependencies and the firmware are built for the board and not the host.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.