marcusmota
Posts: 5
Joined: Sat Jun 13, 2015 7:30 pm

Raspberry GPIO3 switching between HIGH and LOW alone (bug?)

Wed Mar 15, 2017 8:02 pm

Hi everyone i have a rpi 2 B+ and im using a relay to close the circuit between GPIO 3 and GROUND (it does the rpi start when its off and rpi shutdown when its on) but im confused because the GPIO3 is switching between HIGH and LOW alone, my python script to shutdown is

Code: Select all

import RPi.GPIO as GPIO
import time
import os

GPIO.setmode(GPIO.BCM)
GPIO.setup(3, GPIO.IN, pull_up_down = GPIO.PUD_UP)

def Shutdown(channel):
    os.system("sudo shutdown -h now")

GPIO.add_event_detect(3, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)

while 1:
    print("waiting");
    time.sleep(1)
when i run python script.py my pc immediatle shutdown, so i commented the line os.system("sudo shutdown -h now") and wrote print ("HIGH"), so i got a lot of HIGH even though I was not doing anything (relay is OPEN), is that a bug ? im really newbie on eletronic

Thank you

ghp
Posts: 1498
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Raspberry GPIO3 switching between HIGH and LOW alone (bu

Wed Mar 15, 2017 8:32 pm

Hello,
when I run this script on my pi it works: when I connect GPIO3 to GND then the shutdown is 'fired'.
GPIO3 is somewhat special as this pin is also used for I2C, so when another program is writing to I2C this might trigger the callback too. Perhaps you move this pin to a 'plain' GPIO like GPIO4 ?
Regards,
Gerhard

marcusmota
Posts: 5
Joined: Sat Jun 13, 2015 7:30 pm

Re: Raspberry GPIO3 switching between HIGH and LOW alone (bu

Wed Mar 15, 2017 8:41 pm

thank you for the answer, it's confused because sometimes it works sometimes it doesnt. What about another GPIO like 17, it's keep fire like my GPIO 3, i connected GPIO 17 to the 3.3v PIN and control them with relay, when my relay is "up" my GPIO 17 should has 3.3v, but i got on console (with the same code)

"waiting"
"fired"
"waiting"
"fired"
"waiting"
"waiting"
"waiting"
"fired"

I use arduino + IR control to control the RELAY

:shock: :shock:

ghp
Posts: 1498
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Raspberry GPIO3 switching between HIGH and LOW alone (bu

Wed Mar 15, 2017 8:58 pm

Hmm, perhaps you should explain this a little bit more:
i connected GPIO 17 to the 3.3v PIN and control them with relay
Assume the relais setup is like

Code: Select all

   +--------------------==GPIO17 internal pullup to 3.3V
   |
   O /
    /
	/   Relais contact
	O
	|
	+-------------------==GND
This behavior could be caused by contact problems, when some connections fail in between you get jitter. Or long wires, keep connections shorter that prox 30cm. Twist the two wires from relais contacts towards PI(GPIO,GND). Connect a capacitor 100nF between GPIO and GND parallel to relais contact. And check that relais is switching only once..

klintkrossa
Posts: 81
Joined: Tue Nov 10, 2015 3:06 pm

Re: Raspberry GPIO3 switching between HIGH and LOW alone (bu

Fri Mar 17, 2017 2:29 pm

Hello,
This is a problem in a lot of logic inputs.

This page might be a good read, https://www.ibiblio.org/kuphaldt/electr ... IGI_3.html
04137.png
from https://www.ibiblio.org/kuphaldt/electricCircuits/Digital/DIGI_3.html
04137.png (8.02 KiB) Viewed 607 times

In the image replace the CMOS with gpio.

WARNING
Make sure that the resister Ohms is big enough!!!!!
If the ohms is to small it will burn out the Raspberry Pi.
WARNING
Thanks
This is not like any other bulletin boards that I have been on. Been flamed on other BB's so bad I was afraid to ask.

All my Raspberry Pi's are like the Hessian artilleryman of Sleepy Hollow.

Return to “Python”