Difference between revisions of "Transclusion: Debian: GPIO"
(New page: Linux provides simple and convenient GPIO access via {{filename|sysfs}} interface. A GPIO should be exported using {{filename|/sys/class/gpio/export}}. After the GPIO is exported it is pos...) |
(→Example) |
||
Line 5: | Line 5: | ||
The following example demonstrates how to configure GPIO 140 as output and set value to high: | The following example demonstrates how to configure GPIO 140 as output and set value to high: | ||
<pre> | <pre> | ||
− | # echo 140 > /sys/class/gpio/export | + | root@cl-rootfs:~# echo 140 > /sys/class/gpio/export |
− | # echo out > /sys/class/gpio/gpio140/direction | + | root@cl-rootfs:~# echo out > /sys/class/gpio/gpio140/direction |
− | # echo 1 > /sys/class/gpio/gpio140/value | + | root@cl-rootfs:~# echo 1 > /sys/class/gpio/gpio140/value |
</pre> | </pre> | ||
{{Note|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.}} | {{Note|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.}} |
Latest revision as of 08:31, 23 April 2017
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
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. |