Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1225

Python • Re: Bookworm, 'gpiozero' and 'libgpiod'

$
0
0
Slowly getting there. It seems the 'led.close()' call finds its way to here -

https://github.com/gpiozero/gpiozero/blob/master/gpiozero/pins/lgpio.py#L129

Code:

    def close(self):        if self.factory._handle is not None:            # Closing is really just "resetting" the function of the pin;            # we let the factory close deal with actually freeing stuff            lgpio.gpio_claim_input(                self.factory._handle, self._number, lgpio.SET_PULL_NONE)
That doesn't so much release the pin as merely turn it into an input. To actually release the pin it appears we need to change that to -

Code:

    def close(self):        if self.factory._handle is not None:            lgpio.gpio_free(self.factory._handle, self._number)
And that seems to work, the LED line is repeatedly claimed, set, and released, in the main loop, however, when Ctrl-C aborted 'gpiozero' appears to try and release that pin which is already released and consequently errors.

At least I now know it is possible to get 'gpiozero' to relinquish a pin without exiting the program, so onwards and upwards.

Statistics: Posted by hippy — Sun Jan 07, 2024 9:25 am



Viewing all articles
Browse latest Browse all 1225

Trending Articles