0

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: enter image description here

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: wiring if 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.

enter image description here enter image description here


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?

  • The most likely reason for GPIO damage is feeding more than 3V3 into a GPIO. You only need to feed more than 3V3 into one GPIO, unfortunately a cascade effect may eventually take out all the others many days later. – joan Sep 30 '17 at 11:32
  • Can you add some images of your wiring ? – CoderMike Sep 30 '17 at 20:10
  • I added further information. Let me know if you need more! Thanks! – Pascal Oct 1 '17 at 11:51
2

Is it possible that at any point PIN 4 (PIR) was configured as OUT? That would damage GPIO permanently and be an easy root cause (if PIN 4 was set to OUT0, and sensor is reading 1, that is a direct short from 3V3 to ground) .

EDIT::

For the Motion Sensor the wiring is as follows:

grey (GPIO4 / board pin 7)

white (GPIO3 / board pin 5)

black (5V / board pin 2)

Please review the connection diagram, for the PIR device, surely the sensor needs a ground connection. GPIO configured as input is a very poor ground and would cause the problems described below (but with a different mode of action).


Otherwise

There is always the risk of occasional, static, capacitative, or inductive voltage spikes on GPIO when interfacing external devices. The causes of this are many, but the risk is higher when using a remote board or long wire connections directly to GPIO pin. The risk increases when you "hotplug" or there is intermittent wire contact. The risk is highest when using active devices with their own power supply or on-board regulators

The worst culprit is when you have a ground connection that is intermittent. Even if only few milliseconds due to poor contact, it can cause the onboard regulator of your PIR sensor to float up many volts from the raspberry PI, when ground reference is reestablished this now appears as a large potential on GPIO pin, maybe even more than 5V, NOT GOOD

It is unlikely that this due to the fast rate of switching of LED control signals, but more likely an intermittent issue due to (wiring) design flaw.

Recommendations

  1. Use multiple ground wires (e.g. use pin 6,9, and 14 at the same time) to minimize the risk of an intermittent ground
    • If Possible, use tight fitting ribbon connectors and not single-wire jumpers
  2. If possible, never disconnect sensor or LED when under power, if you must:

    • Always connect ground first
    • Always disconnect ground last

      (if you notice, on hot plug interface like USB, ground pin is longer and always makes contact first and disconnects last)

  3. Use a buffer (transistor) to drive GPIO pins and outputs
    • This reduces the coupled impedance and removes chance of inductive spikes
  4. Use External Zener diodes to clamp the GPIO voltage to 0<->3V3
    • Sacrificial protection from any accidental overvoltage
  5. Place resistors (low value ~100Ohm) in series with GPIO pins.
    • This limits the discharge current through GPIO in case of voltage spike
    • Prevents reflections for fast switching signals
  • Wow many thanks for the detailed advices and recommendations. I will get a new raspberry and will try to implement as many of these as possible. So that hopefully the next raspberry will last longer ;) – Pascal Oct 2 '17 at 21:11
  • @Pascal make sure there is no possibility that GPIO4 was configured as OUT, accidentally configuring an input pin as output, even for a moment, would cause instant death. A mistaken command to pigpiod could be the cause. – crasic Oct 2 '17 at 21:58
  • @Pascal see my new edit, I think there is something strange with your pinout for PIR – crasic Oct 2 '17 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.