Last active
January 8, 2019 19:24
-
-
Save TobleMiner/001fbcdb0479a6766a98cd3e33d76490 to your computer and use it in GitHub Desktop.
Simple shell script to determine GPIO -> LED mappings on embedded linux devices
This file contains hidden or 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/ash | |
| # This script is a helper for creating GPIO -> LED mappings on openwrt devices | |
| # Just run it and watch for blinking LEDs on your device. | |
| # If your device does crash/reboot while running this script you can limit | |
| # which GPIOs it addresses. Just take the number of the last GPIO the script | |
| # displayed before the device rebooted, increment it by one and call the script again: | |
| # ./gpio_blink.sh <number> | |
| min=0 | |
| [ -n "$1" ] && echo "$1" | egrep -q '[0-9]+' && min="$1" | |
| for gpio in `seq "$min" 100`; do | |
| echo "$gpio" > /sys/class/gpio/export 2> /dev/null && \ | |
| echo "Exporting gpio${gpio}" | |
| done | |
| for f in /sys/class/gpio/*; do | |
| gpio="$(echo "$f" | egrep -o 'gpio[0-9]+$')" | |
| [ -n "$gpio" ] || continue | |
| echo "Enabling $gpio" | |
| echo out > "$f/direction" | |
| echo "Blinking $gpio" | |
| state=0 | |
| for i in `seq 3`; do | |
| if [ $state -eq 0 ]; then | |
| echo 1 > "$f/value" | |
| state=1 | |
| else | |
| echo 0 > "$f/value" | |
| state=0 | |
| fi | |
| sleep 1 | |
| done | |
| echo ====== | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment