gpiozero is a convenience wrapper for a bunch of GPIO backends. Which one it uses depends on your configuration and hardware. By default now, and in your case, it uses lgpio as a backend, and the kernel interface that uses requests GPIOs exclusively. So the error from lgpio is telling you something else has already requested that GPIO. That might be another process or another request in the same process.I guess I have a few questions:
1. Why would the GPIO be busy?
You can use
Code:
$ gpioinfo gpiochip0
You need to remove the source of contention, so that other request. If that is another process then you need to kill it. If your process is requesting the GPIO multiple times then you need to restructure your code to request it once and then share the request.2. How do you clear the GPIO?
Alternatively, if you are not using a Pi5, then you could change to one of the other backends that doesn't care about contention and will happily let multiple processes twiddle with the same GPIO willy-nilly, i.e. the good old days.
For the interface lgpio uses, yeah pretty much. When a GPIO is requested a file descriptor is returned. That is used to control the GPIO and you close the file when you are done. I'm not sure how that is exposed in lgpio and gpiozero. Typically you need to close or destroy whatever object is containing the GPIO request.3. Is using GPIO like database connections where you need to close the connection at the end of the request? If so, how do you do that?
Statistics: Posted by warthog618 — Sun Jan 26, 2025 3:00 am