Ever wondered if one of your GPIO pins is not working, the python script below (and a couple of basic components!) should help.
You will need:
1 LED
1 500 ish ohm resistor
1 breakout board (to avoid having to jab wires into the pi)
Couple of jumper leads
Usual GPIO library.
Connect the resistor to ground, one end of the LED to the other end of the resistor, attach the jumper lead to the other end of the LED, to test that the LED is the right way round, attach the jumper lead to +3.3v to see if it illuminates, if not switch the LED the other way around.
Run the script and place the jumper cable over each of the gpio pins in sequence, you should see the LED blink. If it does not blink (stays off or on) then chances are is that that GPIO pin is fried, as happened to me! (for reference, putting +5V through it will do that!)
Please note that I think some pins (I think) are fixed as non GPIO use and may show half illumination if they are digital lines or other behaviour.
The script below will setup the GPIO pins in output mode then cycle through switching them all on and off in a half second loop and print the gpio states to screen.
The start and end GPIO pins can be set via GPIO_start/end in the script.
This is my first python code from scratch so sorry if it 'doesn't read nice'
Code: Select all
import RPi.GPIO as GPIO
import time
gpio_start = 1
gpio_end = 27
GPIO.setmode(GPIO.BCM)
for x in range (gpio_start, gpio_end):
GPIO.setup(x, GPIO.OUT)
while True:
for y in range (gpio_start, gpio_end):
GPIO.output(y, True)
print 'on ', y
time.sleep(.5)
for z in range (gpio_start, gpio_end):
GPIO.output(z, False)
print 'off ',z
time.sleep(.5)