Skip to content

Commit 271e3c7

Browse files
committed
Dumb GPIO input test script
Not very intelligent - no bound checking or validity checking. Just lets you see the GPIO input status, and show the 'direction' bug that is present where even when the direction is initially in on export, that the IO pin doesn't respond.
1 parent b7f82af commit 271e3c7

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

testing/gpio-input-test.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
RootCheck() {
4+
if [ "$(id -u)" != "0" ]; then
5+
echo "${0##*/} requires root privleges - run as root or through sudo. Exiting" >&2
6+
exit 1
7+
fi
8+
}
9+
10+
usage() {
11+
echo "Usage:"
12+
echo "$ $0 <gpio> [-in]"
13+
echo ""
14+
echo " gpio - gpio number to test"
15+
echo ""
16+
echo " -in - set the direction to be 'in'"
17+
echo ""
18+
exit 1
19+
}
20+
21+
cleanup() {
22+
echo "CTRL-C pressed!"
23+
echo ${GPIO_NUM} > "${GPIO_PATH}/unexport"
24+
exit 0
25+
}
26+
27+
if [[ $# -ne 1 ]] && [[ $# -ne 2 ]]; then
28+
usage
29+
fi
30+
31+
RootCheck
32+
33+
#catch Ctrl+C
34+
trap cleanup 2
35+
36+
GPIO_NUM="$1"
37+
GPIO_PATH="/sys/class/gpio/"
38+
39+
test ! -e ${GPIO_PATH}${GPIO_NUM} && echo 73 > "/sys/class/gpio/export"
40+
41+
if [[ $2 == "-in" ]]; then
42+
echo -ne "'direction' of GPIO #${GPIO_NUM} is currently "
43+
cat ${GPIO_PATH}/gpio${GPIO_NUM}/direction
44+
echo "Setting direction to 'in'..."
45+
echo in > ${GPIO_PATH}/gpio${GPIO_NUM}/direction
46+
fi
47+
48+
while true; do
49+
echo -ne "value of GPIO #${GPIO_NUM}: "
50+
cat ${GPIO_PATH}${GPIO_NUM}/value
51+
sleep 1
52+
done

0 commit comments

Comments
 (0)