I am using a Pi 4 with Raspian, writing a program in Python (3.9.2) to do (amongst other things) shutdown of the Pi via a physical button. Based on this link https://linuxhint.com/set-up-shutdown-button-raspberry-pi-python/ I am using the code below:
import wiringpi as wp
. . .
def is_shutdown_button_pressed(self):
if wp.digitalRead(self.POWEROFF) == wp.HIGH:
return True
else:
return False
POWEROFF being GPIO 5 (pin 29) or GPIO 25 (pin 22) (have tested both) and in both cases the IF is always true (so returns true) regardless of the switch position (ON or OFF).
The image above is what I am doing, except in the image is GPIO 26. So the question is wether the sketch works at the mentioned GPIOs or it has to be a specif GPIO for powering off the Pi?
EDIT: I made it work. Turns out I was grounding the IO pin when the button is pressed, but what was necessary was to offer 3.3V to it instead. Both wiringpi and gpiozero work for it. I end up using pin 22 (GPIO 25).