0

Good morning everyone,

i'm working in a project that involves having an state pin and button detection.

The escenario is the following:

  • when raspberry pi finish booting, a pin is pulled HIGH (this is done via rc.local). That pin acts as "correct boot" state, and it will draw a little current (as it's powering a small circuit).
  • when that pin is pulled to ground, via a push button, i want to execute a shutdown command.

The current code is:

import RPi.GPIO as GPIO
import os

pinNum = 26

GPIO.setmode(GPIO.BCM)
GPIO.setup(pinNum, GPIO.IN, pull_up_down=GPIO.PUD_UP)
try:
    GPIO.wait_for_edge(pinNum, GPIO.FALLING)
    os.system("sudo shutdown -h now")
except:
    pass

GPIO.cleanup()

The circuit hanging from that pin draws 0.2uA, which is not enough to trigger the edge detection, but, it eventually triggers the falling edge detection.

I'm working in the filtering of that circuit, as i suspect that is some AC oscillation or transient on that circuit that triggers that. I'll post how the debbuging gets.

is there a more efficient/intelligent way to do this?

Regards,

Dani

  • pins, at any one time, can only be input OR output – Jaromanda X May 17 at 7:51
  • I've read your post several times, but I cannot find a question. It should be possible what you want to do, but I don't know if your code will do it. Have you tried it? Did you get error messages? – Dirk May 17 at 7:55
  • The question is: how can i set a pin high being an input pin? (or turning it later to an input pin, but keep that high state) – Daniel Saiz May 17 at 7:56
  • by the way, you should look at overlay gpio-shutdown - you can then do shutdown and power up using GPIO 3 – Jaromanda X May 17 at 7:57
  • @JaromandaX you can read a pin that is set for output. At least that's what they keep telling me... Can't remember if I ever needed to do that. – Dirk May 17 at 7:57

Your Answer

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

Browse other questions tagged or ask your own question.