Created
November 3, 2015 12:58
-
-
Save huzhifeng/e3c222e6b780d82967db to your computer and use it in GitHub Desktop.
Shell scripts used to test GPIO LEDs and buttons, fork and improve based on http://wiki.openwrt.org/doc/devel/add.new.device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Single GPIO test | |
root@OpenWrt:~# gpio_led_test.sh 18 18 | |
Testing [GPIO18]... | |
[GPIO18] Trying value 0 | |
[GPIO18] Trying value 1 | |
root@OpenWrt:~# | |
GPIO range test | |
root@OpenWrt:~# gpio_led_test.sh 0 2 | |
Testing [GPIO0]... | |
[GPIO0] Trying value 0 | |
[GPIO0] Trying value 1 | |
Testing [GPIO1]... | |
[GPIO1] Trying value 0 | |
[GPIO1] Trying value 1 | |
Testing [GPIO2]... | |
[GPIO2] Trying value 0 | |
[GPIO2] Trying value 1 | |
root@OpenWrt:~# | |
Test all GPIOs | |
root@OpenWrt:~# gpio_led_test.sh | |
Testing [GPIO0]... | |
[GPIO0] Trying value 0 | |
[GPIO0] Trying value 1 | |
Testing [GPIO1]... | |
[GPIO1] Trying value 0 | |
[GPIO1] Trying value 1 | |
Testing [GPIO2]... | |
[GPIO2] Trying value 0 | |
[GPIO2] Trying value 1 | |
Testing [GPIO3]... | |
[GPIO3] Trying value 0 | |
[GPIO3] Trying value 1 | |
Testing [GPIO4]... | |
[GPIO4] Trying value 0 | |
[GPIO4] Trying value 1 | |
Testing [GPIO5]... | |
[GPIO5] Trying value 0 | |
[GPIO5] Trying value 1 | |
Testing [GPIO6]... | |
[GPIO6] Trying value 0 | |
[GPIO6] Trying value 1 | |
Testing [GPIO7]... | |
[GPIO7] Trying value 0 | |
[GPIO7] Trying value 1 | |
Testing [GPIO8]... | |
[GPIO8] Trying value 0 | |
[GPIO8] Trying value 1 | |
Testing [GPIO9]... | |
[GPIO9] Trying value 0 | |
^@[GPIO9] Trying value 1 | |
Testing [GPIO10]... | |
[GPIO10] Trying value 0 | |
[GPIO10] Trying value 1 | |
Testing [GPIO11]... | |
sh: write error: Device or resource busy | |
Failed to export [GPIO11] | |
Testing [GPIO12]... | |
sh: write error: Device or resource busy | |
Failed to export [GPIO12] | |
Testing [GPIO13]... | |
sh: write error: Device or resource busy | |
Failed to export [GPIO13] | |
Testing [GPIO14]... | |
sh: write error: Device or resource busy | |
Failed to export [GPIO14] | |
Testing [GPIO15]... | |
sh: write error: Device or resource busy | |
Failed to export [GPIO15] | |
Testing [GPIO16]... | |
sh: write error: Device or resource busy | |
Failed to export [GPIO16] | |
Testing [GPIO17]... | |
[GPIO17] Trying value 0 | |
[GPIO17] Trying value 1 | |
Testing [GPIO18]... | |
[GPIO18] Trying value 0 | |
[GPIO18] Trying value 1 | |
Testing [GPIO19]... | |
[GPIO19] Trying value 0 | |
[GPIO19] Trying value 1 | |
Testing [GPIO20]... | |
[GPIO20] Trying value 0 | |
[GPIO20] Trying value 1 | |
Testing [GPIO21]... | |
[GPIO21] Trying value 0 | |
[GPIO21] Trying value 1 | |
Testing [GPIO22]... | |
[GPIO22] Trying value 0 | |
[GPIO22] Trying value 1 | |
root@OpenWrt:~# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
GPIOCHIP=0 | |
BASE=$(cat /sys/class/gpio/gpiochip${GPIOCHIP}/base) | |
NGPIO=$(cat /sys/class/gpio/gpiochip${GPIOCHIP}/ngpio) | |
max=${2:-$(($BASE+$NGPIO-1))} | |
gpio=${1:-$BASE} | |
while [ $gpio -le $max ] ; do | |
echo "Testing [GPIO$gpio]..." | |
echo $gpio > /sys/class/gpio/export | |
[ -d /sys/class/gpio/gpio${gpio} ] || echo "Failed to export [GPIO$gpio]" | |
[ -d /sys/class/gpio/gpio${gpio} ] && { | |
echo out > /sys/class/gpio/gpio$gpio/direction | |
echo "[GPIO$gpio] Trying value 0" | |
echo 0 > /sys/class/gpio/gpio$gpio/value | |
sleep 3s | |
echo "[GPIO$gpio] Trying value 1" | |
echo 1 > /sys/class/gpio/gpio$gpio/value | |
sleep 3s | |
echo $gpio > /sys/class/gpio/unexport | |
} | |
gpio=$((gpio+1)) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment