while 1:
time.sleep (1)
exit (1)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The above scripts are common shutdown scripts that can be found on the web, utilizing an NO pushbutton connected to GPIO 26 and ground (physical 37). None of the above scripts work though, since a falling edge is never detected. My setup has been tested and actually, the 1st script was working properly on Raspberry Pi OS a few weeks ago (before switching to Ubuntu). gpiozero uses rpi.gpio as the pin factory. A different pin was tested too.
Consider the 3 following scripts :
1~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~~
#!/bin/python3
from gpiozero import Button
import time
import os
stopButton = Button (17)
while True: is_pressed: ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~
if stopButton.
os.system ("sudo shutdown now -h")
time.sleep (1)
exit (1)
2~~~~~~
#!/bin/python3
import RPi.GPIO as GPIO
import os
import time
from threading import Thread
GPIO.setwarnings (False) down=GPIO. PUD_UP)
GPIO.setmode (GPIO.BCM)
shutdown_pin = 26
GPIO.setup (shutdown_pin, GPIO.IN, pull_up_
def shutdown_check():
pulsetime = 1
GPIO. wait_for_ edge (shutdown_pin, GPIO.FALLING)
print ("falling detected")
time. sleep (0.01)
while GPIO.input (shutdown_pin) == GPIO.LOW:
time. sleep (0.01)
pulsetime += 1
os.system ("sudo reboot")
elif pulsetime >=4 and pulsetime <=5:
os.system ("sudo shutdown now -h")
GPIO.cleanup () ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~
while True:
if pulsetime >=2 and pulsetime <=3:
try:
t1 = Thread (target = shutdown_check)
t1.start ()
except:
t1.stop ()
exit (0)
3~~~~~~
#!/bin/python3
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode (GPIO.BCM)
GPIO.setup (17, GPIO.IN, pull_up_down = GPIO.PUD_UP)
def Shutdown (channel):
print ("Shutting down...")
os.system ("echo $(date) >> shutdown.log")
time.sleep (3)
os.system ("sudo shutdown now -h")
exit (0)
GPIO.add_ event_detect (17, GPIO.FALLING, callback = Shutdown, bouncetime=2000)
while 1: ~~~~~~~ ~~~~~~~ ~~~~~~~ ~~~~~
time.sleep (1)
exit (1)
~~~~~~~
The above scripts are common shutdown scripts that can be found on the web, utilizing an NO pushbutton connected to GPIO 26 and ground (physical 37). None of the above scripts work though, since a falling edge is never detected. My setup has been tested and actually, the 1st script was working properly on Raspberry Pi OS a few weeks ago (before switching to Ubuntu). gpiozero uses rpi.gpio as the pin factory. A different pin was tested too.
ProblemType: Bug ature: Ubuntu 5.4.0-1021.24-raspi 5.4.65 esult: skip DIR=<set>
DistroRelease: Ubuntu 20.04
Package: python3-rpi.gpio 0.6.5-1ubuntu3
ProcVersionSign
Uname: Linux 5.4.0-1021-raspi aarch64
ApportVersion: 2.20.11-0ubuntu27.9
Architecture: arm64
CasperMD5CheckR
Date: Wed Oct 14 20:27:59 2020
ImageMediaBuild: 20200731
ProcEnviron:
TERM=alacritty
PATH=(custom, no user)
XDG_RUNTIME_
LANG=C.UTF-8
SHELL=/bin/bash
SourcePackage: rpi.gpio
UpgradeStatus: No upgrade log present (probably fresh install)