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

Beginners • Re: GPIO Busy error with gpiozero

$
0
0
I guess I have a few questions:
1. Why would the GPIO be busy?
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.

You can use

Code:

$ gpioinfo gpiochip0
to find out what has requested the line. gpioinfo can be installed from the gpiod apt package, if not already installed.
2. How do you clear the GPIO?
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.

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.
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?
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.

Statistics: Posted by warthog618 — Sun Jan 26, 2025 3:00 am



Viewing all articles
Browse latest Browse all 4804

Trending Articles