4 # Test the Pi's GPIO port
5 # Copyright (c) 2013 Gordon Henderson
6 #################################################################################
7 # This file is part of wiringPi:
8 # Wiring Compatable library for the Raspberry Pi
10 # wiringPi is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU Lesser General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # wiringPi is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU Lesser General Public License for more details.
20 # You should have received a copy of the GNU Lesser General Public License
21 # along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
22 #################################################################################
25 # logErr pin, expected got
26 ################################################################################
30 if [ $errs = 0 ]; then
33 echo " --> Pin $1 failure. Expected $2, got $3"
39 ################################################################################
43 if [ $errs = 0 ]; then
44 echo "No faults detected."
45 elif [ $errs = 1 ]; then
46 echo "One fault detected."
48 echo "$errs faults detected"
54 ################################################################################
62 printf "%30s %2d:%2d: " "$3" $1 $2
66 for i in `seq $start $end`; do
70 # Enable internal pull-ups and expect to read high
72 for i in `seq $start $end`; do
74 if [ `gpio read $i` = 0 ]; then
79 # Enable internal pull-downs and expect to read low
81 for i in `seq $start $end`; do
83 if [ `gpio read $i` = 1 ]; then
84 echo "Pin $i failure - expected 0, got 1"
89 # Remove the internal pull up/downs
91 for i in `seq $start $end`; do
95 if [ $errs = 0 ]; then
112 This is a simple utility to test the GPIO pins on your revision $revision
115 NOTE: All GPIO peripherals must be removed to perform this test. This
116 includes serial, I2C and SPI connections. You may get incorrect results
117 if something is connected and it interferes with the test.
119 This test can only test the input side of things. It uses the internal
120 pull-up and pull-down resistors to simulate inputs. It does not test
123 You will need to reboot your Pi after this test if you wish to use the
124 serial port as it will be left in GPIO mode rather than serial mode.
126 Please make sure everything is removed and press the ENTER key to continue,
129 echo -n "or Control-C to abort... "
135 ################################################################################
148 testPins 0 7 "The main 8 GPIO pins"
150 # P5 pins, if a rev 2:
152 if [ $revision = 2 ]; then
153 testPins 17 20 "The 4 pins on the P5 connector"
158 testPins 10 14 "The 5 SPI pins"
162 testPins 15 16 "The serial pins"
164 # I2C - Needs somewhat different testing
165 # due to the on-board pull-up's
167 echo -n " The I2C pins 8: 9: "
172 if [ `gpio read 8` = 0 ]; then
173 echo "Pin 8 failure - expected 1, got 0"
177 if [ `gpio read 9` = 0 ]; then
178 echo "Pin 9 failure - expected 1, got 0"
182 if [ $errs = 0 ]; then
189 if [ $totErrs != 0 ]; then
191 echo "Faults detected! Output of 'readall':"