4 # Test the Pi's GPIO port
5 # Copyright (c) 2013-2015 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
111 This is a simple utility to test the GPIO pins on your Raspberry Pi.
113 NOTE: All GPIO peripherals must be removed to perform this test. This
114 includes serial, I2C and SPI connections. You may get incorrect results
115 if something is connected and it interferes with the test.
117 This test can only test the input side of things. It uses the internal
118 pull-up and pull-down resistors to simulate inputs. It does not test
121 You will need to reboot your Pi after this test if you wish to use the
122 serial port as it will be left in GPIO mode rather than serial mode.
124 This test only tests the original pins present on the Rev A and B. It
125 does not test the extra pins on the Revision A2, B2 nor the A+ or B+
127 Please make sure everything is removed and press the ENTER key to continue,
130 echo -n "or Control-C to abort... "
136 ################################################################################
148 testPins 0 7 "The main 8 GPIO pins"
152 testPins 10 14 "The 5 SPI pins"
156 testPins 15 16 "The serial pins"
158 # I2C - Needs somewhat different testing
159 # due to the on-board pull-up's
161 echo -n " The I2C pins 8: 9: "
166 if [ `gpio read 8` = 0 ]; then
167 echo "Pin 8 failure - expected 1, got 0"
171 if [ `gpio read 9` = 0 ]; then
172 echo "Pin 9 failure - expected 1, got 0"
176 if [ $errs = 0 ]; then
183 if [ $totErrs != 0 ]; then
185 echo "Faults detected! Output of 'readall':"