GPIO-88_LED-flash
【触觉智能 Purple Pi开发板试用】+03.GPIO测试(zmj)
Purple Pi开发板通过J12排针提供了丰富的GPIO接口,包括UART、SPI、I2C、GPIO等(还包括DC5V、DC3.3V、GND)。
本节主要测试Purple Pi开发板的GPIO接口(输出功能)。其中LED添加限流电阻,连接到GPIO-88和GND管脚。
1. GPIO单步测试流程
首先检视GPIO设备,然后申请GPIO设备(此处申请GPIO-88),接着设置GPIO属性(包括输入输出和Value)。
a.检视GPIO设备
ls -la /sys/class/gpio
b.申请GPIO设备(GPIO-88)
echo 88 > /sys/class/gpio/export
c.此时重新检视GPIO设备,发现多了gpio88的设备
ls -la /sys/class/gpio
d.检视GPIO-88属性(输入输出方向,引脚电平)
cat /sys/class/gpio/gpio88/direction && cat /sys/class/gpio/gpio88/value
e.设置GPIO-88属性:输出out,值为高电平“1”
echo out > /sys/class/gpio/gpio88/direction
echo 1 > /sys/class/gpio/gpio88/value
f.此时LED点亮。
详细Log如下所示:
# ls -la /sys/class/gpio
total 0
drwxr-xr-x 2 root root 0 Jan 1 00:00 .
drwxr-xr-x 35 root root 0 Jan 1 00:00 ..
--w------- 1 root root 4096 Jan 1 00:00 export
lrwxrwxrwx 1 root root 0 Jan 1 00:00 gpio72 -> ../../devices/gpiochip0/gpio/gpio72
lrwxrwxrwx 1 root root 0 Jan 1 00:00 gpiochip0 -> ../../devices/gpiochip0/gpio/gpiochip0
--w------- 1 root root 4096 Jan 1 00:00 unexport
#
# echo 88 > /sys/class/gpio/export
#
# ls -la /sys/class/gpio
total 0
drwxr-xr-x 2 root root 0 Jan 1 00:00 .
drwxr-xr-x 35 root root 0 Jan 1 00:00 ..
--w------- 1 root root 4096 Jan 1 00:06 export
lrwxrwxrwx 1 root root 0 Jan 1 00:00 gpio72 -> ../../devices/gpiochip0/gpio/gpio72
lrwxrwxrwx 1 root root 0 Jan 1 00:06 gpio88 -> ../../devices/gpiochip0/gpio/gpio88
lrwxrwxrwx 1 root root 0 Jan 1 00:00 gpiochip0 -> ../../devices/gpiochip0/gpio/gpiochip0
--w------- 1 root root 4096 Jan 1 00:00 unexport
# ls -la /sys/class/gpio/gpio88/
total 0
drwxr-xr-x 3 root root 0 Jan 1 00:06 .
drwxr-xr-x 5 root root 0 Jan 1 00:00 ..
-rw-r--r-- 1 root root 4096 Jan 1 00:09 active_low
lrwxrwxrwx 1 root root 0 Jan 1 00:09 device -> ../../../gpiochip0
-rw-r--r-- 1 root root 4096 Jan 1 00:09 direction
-rw-r--r-- 1 root root 4096 Jan 1 00:09 edge
drwxr-xr-x 2 root root 0 Jan 1 00:09 power
lrwxrwxrwx 1 root root 0 Jan 1 00:09 subsystem -> ../../../../class/gpio
-rw-r--r-- 1 root root 4096 Jan 1 00:06 uevent
-rw-r--r-- 1 root root 4096 Jan 1 00:09 value
# cat /sys/class/gpio/gpio88/direction && cat /sys/class/gpio/gpio88/value
in
1
#
# echo out > /sys/class/gpio/gpio88/direction
# echo 1 > /sys/class/gpio/gpio88/value
#
# cat /sys/class/gpio/gpio88/direction && cat /sys/class/gpio/gpio88/value
out
1
#
2. GPIO循环点灯
参考脚本,循环对GPIO-88赋值“1”和“0”,这样控制LED循环亮灭。
#!/bin/sh
while true;
do
echo 1 > /sys/class/gpio/gpio88/value
sleep 1
echo 0 > /sys/class/gpio/gpio88/value
sleep 1
done
|