Posts by DeWildeP
-
-
Hello, i have an Element14 Pi Desktop case with a powerbutton on it.
I recently updated to LibreElec 12.0.1 and now my shutdownscript does not work anymore.
After some search i found that GPIO is not supported anymore and i need to switch to gpiozero.After a couple of hours fiddling around, trying to alter the script and even use chatGPT for coding help i gave up...
Anyone wants to help me in creating a working script?
My shutdown.py script used to look like this:
Python
Display More#!/usr/bin/python import sys sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib') import RPi.GPIO as GPIO import time import os,sys import signal GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(31,GPIO.OUT) GPIO.setup(33,GPIO.IN) GPIO.output(31,GPIO.LOW) def shutdown_system(channels): os.system("sync") time.sleep(1) os.system("shutdown -h now") sys.exit() GPIO.add_event_detect(33,GPIO.RISING,callback=shutdown_system) while True: time.sleep(1)
with the help of chatGPT i got this output to convert it to gpiozero:
Python
Display More#!/usr/bin/python import sys sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib') from gpiozero import LED, Button from signal import pause import os import time # Stel de LED en de knop in met BCM pin nummering led = LED(6) # Fysieke pin 31 is BCM pin 6 button = Button(13) # Fysieke pin 33 is BCM pin 13 # Zet de LED uit led.off() # Definieer de shutdown functie def shutdown_system(): os.system("sync") time.sleep(1) os.system("shutdown -h now") sys.exit() # Koppel de shutdown functie aan de knop button.when_pressed = shutdown_system # Houd het script draaiende pause()
But that gives errors in the debug log like:
Code
Display MoreEXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<-- - NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS! Error Type: <class 'OSError'> Error Contents: [Errno 22] Invalid argument Traceback (most recent call last): File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/pins/native.py", line 237, in export result = self._exports[pin] ~~~~~~~~~~~~~^^^^^ KeyError: 13 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/pins/native.py", line 247, in export result = os.open(self.path_value(pin), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/gpio/gpio13/value' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/storage/.kodi/addons/service.shutdown.pidesktop/shutdown.py", line 13, in <module> button = Button(13) # Fysieke pin 33 is BCM pin 13 ^^^^^^^^^^ File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/devices.py", line 108, in __call__ self = super().__call__(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/input_devices.py", line 412, in __init__ super().__init__( File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/mixins.py", line 417, in __init__ super().__init__(*args, **kwargs) File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/input_devices.py", line 167, in __init__ self.pin.edges = 'both' ^^^^^^^^^^^^^^ File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/pins/__init__.py", line 441, in <lambda> lambda self, value: self._set_edges(value), ^^^^^^^^^^^^^^^^^^^^^^ File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/pins/native.py", line 519, in _set_edges self.factory.fs.export(self._number)
Anyone has some ideas? I hope i'm not the only one using a hardware case for Raspberry Pi with a power button