gpio allows access to a specific GPIO pin. The interface is restricted because it provides privileged access to GPIO hardware.
snap interface gpio to see which gpio devices are available on the system:
$ snap interface gpio name: gpio summary: allows access to specifc GPIO pin slots: - pi:bcm-gpio-0 - pi:bcm-gpio-1 - pi:bcm-gpio-10 [...]
The pi-fancontrol snap provides simple fan control on a Raspberry Pi with a fan connected to GPIO 14 (pin 8). With the snap installed, the following command will connect the interface to the pin:
$ snap connect pi-fancontrol:gpio pi:bcm-gpio-14
number(slot): GPIO pin number to export and expose to consuming snaps
Unless the snap is expected to actually use a set of gpio pins that is not predefined, it is recommended to define distinct plugs for each used gpio pin, like:
plugs: activity-led: interface: gpio warning-led: interface: gpio
This has the advantage of being self-documenting and 1-1 connections like these are easier to track and setup with auto-connections, if the latter is needed.
When the interface is connected,
"echo (pin number) > /sys/class/gpio/export" is run internally to enable access to the GPIO pin.
Once connected, the consuming snap can use the device via
N is the pin number specified by the connected slot.
Finally, when the interface is disconnected,
"echo (pin number) > /sys/class/gpio/unexport" is run internally to disable access to the GPIO pin.
The hook and control scripts for pi-fancontrol can be found in the project’s GitHub repository: https://github.com/ogra1/pi-fancontrol-snap
The source code for the GPIO interface is in the snapd repository: https://github.com/snapcore/snapd/blob/master/interfaces/builtin/gpio.go.
Last updated 6 days ago. Help improve this document in the forum.