Hello and thanks for all the things I learned from this forum.
Until some days ago I had the following setup working on my Rpi 4B but then it stopped working.
External power button connected to GPIO 3 and pin 9 (according to https://pinout.xyz/) that I was using to switch RPi on using an external button.
I also monitored the GPIO3 to call a shutdown python script (executed inside .config/autostart.sh at startup)
Switch on does not work anymore and GPIO3 is reported busy. What should I do ? Is there a way to reset the GPIO3 to low ?
Code
LibreELEC:~ # gpioinfo -c 0
gpiochip0 - 58 lines:
line 0: "ID_SDA" input
line 1: "ID_SCL" input
line 2: "GPIO2" input
line 3: "GPIO3" input active-low consumer="shutdown"
...
...
LibreELEC:~ # gpioset GPIO3=0
gpioset: unable to request lines on chip '/dev/gpiochip0': Device or resource busy
Display More
Python
### shutdown_button.py
import os
os.environ['LG_WD'] = '/tmp'
from time import sleep
import sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
from signal import pause
from gpiozero import Button
from subprocess import check_call
def poweroff():
check_call(['kodi-send','--notification="Shutting down!"'])
sleep(1)
check_call(['shutdown','now'])
shutdown_btn = Button("GPIO3", hold_time=2)
shutdown_btn.when_held = poweroff
pause()
Display More
Code
LibreELEC:~ # python scripts/shutdown_button.py
Traceback (most recent call last):
File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/pins/pi.py", line 411, in pin
pin = self.pins[info]
~~~~~~~~~^^^^^^
KeyError: PinInfo(number=5, name='GPIO3', names=frozenset({'J8:5', 3, 'GPIO3', 'BCM3', 'WPI9', 'BOARD5', '3'}), pull='up', row=3, col=1, interfaces=frozenset({'', 'spi', 'gpio', 'uart', 'dpi', 'i2c'}))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/storage/scripts/shutdown_button.py", line 22, in <module>
shutdown_btn = Button("GPIO3", hold_time=2)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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 162, in __init__
super().__init__(
File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/mixins.py", line 243, in __init__
super().__init__(*args, **kwargs)
File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/input_devices.py", line 79, in __init__
super().__init__(pin, pin_factory=pin_factory)
File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/devices.py", line 553, in __init__
pin = self.pin_factory.pin(pin)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/pins/pi.py", line 413, in pin
pin = self.pin_class(self, info)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/pins/lgpio.py", line 126, in __init__
lgpio.gpio_claim_input(
File "/storage/.kodi/addons/virtual.rpi-tools/lib/lgpio.py", line 755, in gpio_claim_input
return _u2i(_lgpio._gpio_claim_input(handle&0xffff, lFlags, gpio))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/storage/.kodi/addons/virtual.rpi-tools/lib/lgpio.py", line 458, in _u2i
raise error(error_text(v))
lgpio.error: 'GPIO busy'
Display More