Public bug reported:

Consider the 3 following scripts :

1~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/python3

from gpiozero import Button
import time
import os

stopButton = Button (17)

while True:
     if stopButton.is_pressed:
         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)
GPIO.setmode (GPIO.BCM)
shutdown_pin = 26
GPIO.setup (shutdown_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def shutdown_check():
        while True:
                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
                if pulsetime >=2 and pulsetime <=3:
                        os.system ("sudo reboot")
                elif pulsetime >=4 and pulsetime <=5:
                        os.system ("sudo shutdown now -h")
try:
        t1 = Thread (target = shutdown_check)
        t1.start ()
except:
        t1.stop ()
        GPIO.cleanup ()
        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) and the other 2 were never tested on Raspberry Pi
OS. gpiozero uses rpi.gpio as the pin factory. A different pin was
tested too.

ProblemType: Bug
DistroRelease: Ubuntu 20.04
Package: python3-rpi.gpio 0.6.5-1ubuntu3
ProcVersionSignature: Ubuntu 5.4.0-1021.24-raspi 5.4.65
Uname: Linux 5.4.0-1021-raspi aarch64
ApportVersion: 2.20.11-0ubuntu27.9
Architecture: arm64
CasperMD5CheckResult: skip
Date: Wed Oct 14 20:27:59 2020
ImageMediaBuild: 20200731
ProcEnviron:
 TERM=alacritty
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=C.UTF-8
 SHELL=/bin/bash
SourcePackage: rpi.gpio
UpgradeStatus: No upgrade log present (probably fresh install)

** Affects: rpi.gpio (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: apport-bug arm64 focal uec-images

** Description changed:

  Consider the 3 following scripts :
  
  1~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  #!/bin/python3
  
  from gpiozero import Button
  import time
  import os
  
  stopButton = Button (17)
  
  while True:
-      if stopButton.is_pressed:
-          os.system ("sudo shutdown now -h")
-      time.sleep (1)
+      if stopButton.is_pressed:
+          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)
  GPIO.setmode (GPIO.BCM)
  shutdown_pin = 26
  GPIO.setup (shutdown_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  
  def shutdown_check():
-         while True:
-                 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
-                 if pulsetime >=2 and pulsetime <=3:
-                         os.system ("sudo reboot")
-                 elif pulsetime >=4 and pulsetime <=5:
-                         os.system ("sudo shutdown now -h")
+         while True:
+                 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
+                 if pulsetime >=2 and pulsetime <=3:
+                         os.system ("sudo reboot")
+                 elif pulsetime >=4 and pulsetime <=5:
+                         os.system ("sudo shutdown now -h")
  try:
-         t1 = Thread (target = shutdown_check)
-         t1.start ()
+         t1 = Thread (target = shutdown_check)
+         t1.start ()
  except:
-         t1.stop ()
-         GPIO.cleanup ()
-         exit (0)
+         t1.stop ()
+         GPIO.cleanup ()
+         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)
+     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)
+     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.
+ switching to Ubuntu) and the other 2 were never tested on Raspberry Pi
+ OS. gpiozero uses rpi.gpio as the pin factory. A different pin was
+ tested too.
  
  ProblemType: Bug
  DistroRelease: Ubuntu 20.04
  Package: python3-rpi.gpio 0.6.5-1ubuntu3
  ProcVersionSignature: Ubuntu 5.4.0-1021.24-raspi 5.4.65
  Uname: Linux 5.4.0-1021-raspi aarch64
  ApportVersion: 2.20.11-0ubuntu27.9
  Architecture: arm64
  CasperMD5CheckResult: skip
  Date: Wed Oct 14 20:27:59 2020
  ImageMediaBuild: 20200731
  ProcEnviron:
-  TERM=alacritty
-  PATH=(custom, no user)
-  XDG_RUNTIME_DIR=<set>
-  LANG=C.UTF-8
-  SHELL=/bin/bash
+  TERM=alacritty
+  PATH=(custom, no user)
+  XDG_RUNTIME_DIR=<set>
+  LANG=C.UTF-8
+  SHELL=/bin/bash
  SourcePackage: rpi.gpio
  UpgradeStatus: No upgrade log present (probably fresh install)

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1899824

Title:
  RPi.GPIO doesn't detect falling edge (wait_for_edge,
  add_event_detect)

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/rpi.gpio/+bug/1899824/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to