进入目录/sys/class/gpio中,下面是执行命令的过程: [codesyntax lang="bash"]
root@raspberrypi:/sys/class/gpio# echo 20 > export
root@raspberrypi:/sys/class/gpio# l
total 0
drwxrwx--- 2 root gpio 0 Mar 18 17:00 .
drwxr-xr-x 46 root root 0 Mar 18 16:53 ..
-rwxrwx--- 1 root gpio 4.0K Mar 18 17:00 export
lrwxrwxrwx 1 root gpio 0 Mar 18 17:00 gpio20 -> ../../devices/soc/3f200000.gpio/gpio/gpio20
lrwxrwxrwx 1 root gpio 0 Jan 1 1970 gpiochip0 -> ../../devices/soc/3f200000.gpio/gpio/gpiochip0
-rwxrwx--- 1 root gpio 4.0K Jan 1 1970 unexport
root@raspberrypi:/sys/class/gpio# l gpio20
lrwxrwxrwx 1 root gpio 0 Mar 18 17:00 gpio20 -> ../../devices/soc/3f200000.gpio/gpio/gpio20
root@raspberrypi:/sys/class/gpio# cd gpio20
root@raspberrypi:/sys/class/gpio/gpio20# l
total 0
drwxrwx--- 3 root gpio 0 Mar 18 17:00 .
drwxrwx--- 4 root gpio 0 Mar 18 17:00 ..
-rwxrwx--- 1 root gpio 4.0K Mar 18 17:00 active_low
lrwxrwxrwx 1 root gpio 0 Mar 18 17:00 device -> ../../../3f200000.gpio
-rwxrwx--- 1 root gpio 4.0K Mar 18 17:00 direction
-rwxrwx--- 1 root gpio 4.0K Mar 18 17:00 edge
drwxrwx--- 2 root gpio 0 Mar 18 17:00 power
lrwxrwxrwx 1 root gpio 0 Mar 18 17:00 subsystem -> ../../../../../class/gpio
-rwxrwx--- 1 root gpio 4.0K Mar 18 17:00 uevent
-rwxrwx--- 1 root gpio 4.0K Mar 18 17:00 value
root@raspberrypi:/sys/class/gpio/gpio20# cd ..
root@raspberrypi:/sys/class/gpio# echo out > gpio20/direction
root@raspberrypi:/sys/class/gpio# echo 1 > gpio20/value
root@raspberrypi:/sys/class/gpio# echo 0 > gpio20/value
root@raspberrypi:/sys/class/gpio# echo 20 > unexport
root@raspberrypi:/sys/class/gpio# l
total 0
drwxrwx--- 2 root gpio 0 Mar 18 17:03 .
drwxr-xr-x 46 root root 0 Mar 18 16:53 ..
-rwxrwx--- 1 root gpio 4.0K Mar 18 17:00 export
lrwxrwxrwx 1 root gpio 0 Jan 1 1970 gpiochip0 -> ../../devices/soc/3f200000.gpio/gpio/gpiochip0
-rwxrwx--- 1 root gpio 4.0K Mar 18 17:03 unexport
root@raspberrypi:/sys/class/gpio#
[/codesyntax] gpio20文件夹下有direction和value两个接口。direction接收in(输入)、out(输出)俩个值,默认为输出;value接口代表GPIO电平,非零值为高电平,零为低电平。
想知道你的树莓派到底有那些GPIO接口吗,请看这里。
https://github.com/concefly/openRPi_GPIO/wiki/%E7%AE%80%E6%98%8E-Linux-GPIO-%E9%A9%B1%E5%8A%A8%E6%8C%87%E5%AF%BC