選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

188 行
4.0 KiB

  1. #!/bin/bash
  2. #
  3. # pintest
  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
  9. #
  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.
  14. #
  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.
  19. #
  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. #################################################################################
  23. # logErr pin, expected got
  24. ################################################################################
  25. logErr ()
  26. {
  27. if [ $errs = 0 ]; then
  28. echo ""
  29. fi
  30. echo " --> Pin $1 failure. Expected $2, got $3"
  31. let errs+=1
  32. }
  33. # printErrorCount
  34. ################################################################################
  35. printErrCount()
  36. {
  37. if [ $errs = 0 ]; then
  38. echo "No faults detected."
  39. elif [ $errs = 1 ]; then
  40. echo "One fault detected."
  41. else
  42. echo "$errs faults detected"
  43. fi
  44. }
  45. # testPins start end
  46. ################################################################################
  47. testPins()
  48. {
  49. start=$1
  50. end=$2
  51. errs=0
  52. printf "%30s %2d:%2d: " "$3" $1 $2
  53. # Set range to inputs
  54. for i in `seq $start $end`; do
  55. gpio mode $i in
  56. done
  57. # Enable internal pull-ups and expect to read high
  58. for i in `seq $start $end`; do
  59. gpio mode $i up
  60. if [ `gpio read $i` = 0 ]; then
  61. logErr $i 1 0
  62. fi
  63. done
  64. # Enable internal pull-downs and expect to read low
  65. for i in `seq $start $end`; do
  66. gpio mode $i down
  67. if [ `gpio read $i` = 1 ]; then
  68. echo "Pin $i failure - expected 0, got 1"
  69. let errs+=1
  70. fi
  71. done
  72. # Remove the internal pull up/downs
  73. for i in `seq $start $end`; do
  74. gpio mode $i tri
  75. done
  76. if [ $errs = 0 ]; then
  77. echo " OK"
  78. else
  79. printErrCount
  80. fi
  81. let totErrs+=errs
  82. }
  83. intro()
  84. {
  85. cat <<EOF
  86. PinTest
  87. =======
  88. This is a simple utility to test the GPIO pins on your Raspberry Pi.
  89. NOTE: All GPIO peripherals must be removed to perform this test. This
  90. includes serial, I2C and SPI connections. You may get incorrect results
  91. if something is connected and it interferes with the test.
  92. This test can only test the input side of things. It uses the internal
  93. pull-up and pull-down resistors to simulate inputs. It does not test
  94. the output drivers.
  95. You will need to reboot your Pi after this test if you wish to use the
  96. serial port as it will be left in GPIO mode rather than serial mode.
  97. This test only tests the original pins present on the Rev A and B. It
  98. does not test the extra pins on the Revision A2, B2 nor the A+ or B+
  99. Please make sure everything is removed and press the ENTER key to continue,
  100. EOF
  101. echo -n "or Control-C to abort... "
  102. read a
  103. }
  104. # Start here
  105. ################################################################################
  106. intro
  107. gpio unexportall
  108. errs=0
  109. totErrs=0
  110. echo ""
  111. # Main pins
  112. testPins 0 7 "The main 8 GPIO pins"
  113. # SPI
  114. testPins 10 14 "The 5 SPI pins"
  115. # Serial
  116. testPins 15 16 "The serial pins"
  117. # I2C - Needs somewhat different testing
  118. # due to the on-board pull-up's
  119. echo -n " The I2C pins 8: 9: "
  120. errs=0
  121. gpio mode 8 in
  122. gpio mode 9 in
  123. if [ `gpio read 8` = 0 ]; then
  124. echo "Pin 8 failure - expected 1, got 0"
  125. let errs+=1
  126. fi
  127. if [ `gpio read 9` = 0 ]; then
  128. echo "Pin 9 failure - expected 1, got 0"
  129. let errs+=1
  130. fi
  131. if [ $errs = 0 ]; then
  132. echo " OK"
  133. else
  134. printErrCount
  135. fi
  136. echo ""
  137. if [ $totErrs != 0 ]; then
  138. echo ""
  139. echo "Faults detected! Output of 'readall':"
  140. gpio readall
  141. fi