I have a simple Python 3 program which works as it would be expected to under Bookworm. It uses 'gpiozero' to control a LED connected to GPIO 24. The 'led=LED(LED_PIN)' then 'led.on()' causes 'gpiozero' to take ownership of GPIO24, set it as an output high ...The question is, how do I get 'gpiozero' to relinquish ownership of GPIO24 without exiting my Python program ?
I was hoping to be able to do something like below, but after 'led.close()' GPIO24 reverts to an input, and it doesn't actually relinquish ownership of GPIO24 -I can achieve what I want by forgoing 'gpiozero', shelling out to execute a 'gpioset' CLI command, but any ideas on how to achieve the same using 'gpiozero' ?
Code:
from gpiozero import LEDimport timeLED_PIN = 24led = LED(LED_PIN)while True: led.on() time.sleep(5)
Code:
pi@Pi4B:~/apps/libgpiod/gpiozero $ gpioinfo | grep "24" line 24: "GPIO24" unused input active-highpi@Pi4B:~/apps/libgpiod/gpiozero $ python3 on_gpiozero_forever.py &[1] 2685pi@Pi4B:~/apps/libgpiod/gpiozero $ gpioinfo | grep "24" line 24: "GPIO24" "lg" output active-high [used]
I was hoping to be able to do something like below, but after 'led.close()' GPIO24 reverts to an input, and it doesn't actually relinquish ownership of GPIO24 -
Code:
from gpiozero import LEDimport timeLED_PIN = 24while True: led = LED(LED_PIN) led.on() led.close() time.sleep(5)
Code:
pi@Pi4B:~/apps/libgpiod/gpiozero $ gpioinfo | grep "24" line 24: "GPIO24" unused output active-highpi@Pi4B:~/apps/libgpiod/gpiozero $ python3 on_gpiozero.py &[1] 3700pi@Pi4B:~/apps/libgpiod/gpiozero $ gpioinfo | grep "24" line 24: "GPIO24" "lg" input active-high [used bias-disabled]
Statistics: Posted by hippy — Thu Jan 04, 2024 5:38 pm