Problem Description
I have experienced some problems with the GPIOs on my Pi3. From one day to another the MotionSensor and the LED strip that where connected to the GPIOs stopped working while the Raspberry was in productive use. I use it for a Magic Mirror Project. It was running like this for about four months.
Now that the GPIOs stopped working I am looking for the reason why. I already ran the pintest. The result gave me failures for every single pin. So for now I know that they do not work properly and that the reasen are actually the pins and not the LED strip or the MotionSensor (because at first I thought that it could be the MotionSenseor and therefore tried to use another, new one).
Below the output of the pintest:
Does anyone have some hints for what I have to do now?
Is the hardware damaged, so that i need to buy a new Pi3?
Thanks in advance.
Python Script
I was also thinking that it may have been caused by the code that I used to control the MotionSensor and the LED strip. Might there be any issues that caused the problems with the GPIOs over time? Or maybe damaged the Pi3 over time?
Below the python script. It is loaded and managed by the process manager pm2
:
"""
last update on 20170603
- defines a motion sensor (PIR)
- turns on the monitor when a motion is detected
- turns off the monitor after a specified time
- resets the timer when motion is detected while monitor is already on
- defines a led strip
- turn on the led strip incrementally by percentage of given target colors
- turns off the led strip after a specified time
- resets the timer when motion is detected while led strip is already on
"""
import os, sys, subprocess, time
from gpiozero import MotionSensor
"""
display configuration
"""
os.environ['DISPLAY'] = ":0"
SHUTOFF_DELAY = 180 # seconds
PIR_PIN = 4 # Pin 7 on the board
"""
LED strip configuration
"""
pin_red = '17' # reference
pin_green = '22' # reference
pin_blue = '24' # reference
rgb = [250,255,30] # color setting [red, green, blue], in a range of 0 to 255
red = 0 # temp value
green = 0 # temp value
blue = 0 # temp value
subprocess.call('sudo pigpiod', shell=True) #start pigpio deamon
"""
**main function
program entrance...
"""
def main():
pir = MotionSensor(PIR_PIN)
turnDisplay_on() #initially turn monitor on
led_on() #initially turn led strip on
turned_off = False
last_motion_time = time.time()
while True:
if pir.motion_detected:
last_motion_time = time.time()
print("info:", "Motion detected!")
if turned_off:
turned_off = False
turnDisplay_on()
led_on()
else:
if not turned_off and time.time() > (last_motion_time + SHUTOFF_DELAY):
turned_off = True
turnDisplay_off()
led_off()
time.sleep(1)
print("debug-info -->","time left:",SHUTOFF_DELAY - ( time.time() - last_motion_time ) )
"""
**turnDisplay_on() function
- this function will turn the monitor on
"""
def turnDisplay_on():
print("debug-info -->","turn ON")
subprocess.call('vcgencmd display_power 1',shell=True)
"""
**turnDisplay_off() function
- this function will turn the monitor off
"""
def turnDisplay_off():
print("debug-info -->","turn OFF")
subprocess.call('vcgencmd display_power 0',shell=True)
"""
**led_on() function
- this function will turn on the LEDs (strip)
- it will generally be set the values from 0% to 100% of the color specified above
"""
def led_on():
global red, green, blue
percentage = 0
while percentage < 101:
red = int(rgb[0] * percentage / 100)
green = int(rgb[1] * percentage / 100)
blue = int(rgb[2] * percentage / 100)
subprocess.call('pigs p ' + pin_red +' '+ str(red) + ' && pigs p ' + pin_green +' '+ str(green) + ' && pigs p ' + pin_blue +' '+ str(blue), shell=True)
percentage += 1
"""
**led_off() function
this function will turn on the LEDs (strip)
it will generally be set the values from 0% to 100% of the color specified above
"""
def led_off():
global red, green, blue
percentage = 100
while percentage >= 0:
red = int(rgb[0] * percentage / 100)
green = int(rgb[1] * percentage / 100)
blue = int(rgb[2] * percentage / 100)
subprocess.call('pigs p ' + pin_red +' '+ str(red) + ' && pigs p ' + pin_green +' '+ str(green) + ' && pigs p ' + pin_blue +' '+ str(blue), shell=True)
percentage -= 1
if __name__ == '__main__': # to make main() be called
#print("info:","script starting")
main()
Wiring of the Components
Here is one picutre of the wiring of the MotionSensor itself:
In the next two picures you can see the wiring on the Raspberry Pi.
For the Motion Sensor the wiring is as follows:
- grey (GPIO4 / board pin 7)
- white (GPIO3 / board pin 5)
- black (5V / board pin 2)
For the LED strip the wiring is as follows:
- blue (GPIO24 / board pin 18)
- green (GPIO22 / board pin 15)
- red (GPIO17 / board pin 11)
- black (GND / board pin 6)
For the LED strip I followed the instructions of http://dordnung.de/raspberrypi-ledstrip/ (unfortunately in german). But there are also pictures. I did it just like described there.
Could there be a mistake in the wiring that has led to a hardware damage?
Or could it be something with the code? Because it is fading the LEDs and sending 100*3 commands to pigpio for one fade action. Could that stress the GPIOs too much?