Test: Linux GPIO from user space (libgpiod and pigpio)
Linux GPIO from User Space: libgpiod and pigpio
Who owns the pins: the kernel or your program
On Linux the kernel owns the GPIO hardware. A program asks for lines through the GPIO character device (/dev/gpiochip0 and its neighbours), using libgpiod or the gpio tools built on it. The kernel records who holds each line (the consumer), refuses a second request for a line in use, and releases a program’s lines when it exits or crashes. pigpio and pinctrl work differently: they map the GPIO registers into their own memory and write them directly, and the kernel is not told. The older sysfs interface (/sys/class/gpio) goes through the kernel but is deprecated. Start fan-ctl, which holds GPIO17 to run the fan, then let a second program try to switch the fan off.
Challenge: Show the kernel refusing a second owner, then switch the fan off without going through the kernel.
Character device
/dev/gpiochipN. A program requests lines by offset; the kernel records the consumer and allows one owner per line.
libgpiod, gpioset, gpioget, gpiomon, lgpio
Direct register access
Map the GPIO registers through /dev/mem or /dev/gpiomem and write them. The kernel is not involved and is not told.
pigpio, pinctrl, RPi.GPIO
sysfs (deprecated)
/sys/class/gpio: through the kernel, but global numbers, no bias or debounce, and lines stay exported after a crash.
GPIO17 = gpio529 here
$ gpioinfo GPIO17 gpiochip0 17 "GPIO17" input
Nothing has happened yet.
Owner (kernel)
none
GPIO17
0
Records agree?
yes
libgpiod v2’s gpioset keeps running to hold its line, because a released line’s level is not guaranteed. pinctrl is a debugging tool; it is useful for exactly this reason, and a hazard for the same one.
© 2026 Derek Molloy, Dublin City University. All rights reserved.
Spot an error, omission, or have a suggestion?
Submit an errata report here.