Transclusion: Debian: GPIO

From Compulab Mediawiki
Jump to: navigation, search

Linux provides simple and convenient GPIO access via sysfs interface. A GPIO should be exported using /sys/class/gpio/export. After the GPIO is exported it is possible to change its direction and value using /sys/class/gpio/gpioX/direction and /sys/class/gpio/gpioX/value attributes.

Example

The following example demonstrates how to configure GPIO 140 as output and set value to high:

root@cl-rootfs:~# echo 140 > /sys/class/gpio/export
root@cl-rootfs:~# echo out > /sys/class/gpio/gpio140/direction
root@cl-rootfs:~# echo 1 > /sys/class/gpio/gpio140/value
Admolition note.png The above example assumes that the pinmux configuration of the corresponding pin is set to GPIO mode and the GPIO 140 is not requested in the Linux kernel.