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

Python • Raspberry Pi 5 GPIO busy

$
0
0
Hi everyone, I just got a raspberry pi 5 and what I noticed right away was how to use the GPIO. With RPI4 it's a lot easier, and with this one I've had a lot of problems. The GPIO control library is not the same, and so far I've only been able to do it with gpiozero. Even with the use of this library for such a simple program to check if I pressed a push button gives me an error. Below I show the simple test code I have and the error I am presented with.


THE CODE:

Code:

from gpiozero import Buttonfrom time import sleepbutton = Button(2)while True:        if button.is_pressed:                print("Pressed")    else:        print("Released")    sleep(1)

THE ERROR:

Code:

Traceback (most recent call last):  File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 408, in pin    pin = self.pins[info]          ~~~~~~~~~^^^^^^KeyError: PinInfo(number=3, name='GPIO2', names=frozenset({2, 'J8:3', 'WPI8', 'BOARD3', 'BCM2', 'GPIO2', '2'}), pull='up', row=2, col=1, interfaces=frozenset({'', 'uart', 'gpio', 'dpi', 'spi', 'i2c'}))During handling of the above exception, another exception occurred:Traceback (most recent call last):  File "/home/diogo/Desktop/test.py", line 5, in <module>    button = Button(2)             ^^^^^^^^^  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 103, in __call__    self = super().__call__(*args, **kwargs)           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 412, in __init__    super().__init__(  File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 417, in __init__    super().__init__(*args, **kwargs)  File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 162, in __init__    super().__init__(  File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 243, in __init__    super().__init__(*args, **kwargs)  File "/usr/lib/python3/dist-packages/gpiozero/input_devices.py", line 79, in __init__    super().__init__(pin, pin_factory=pin_factory)  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 549, in __init__    pin = self.pin_factory.pin(pin)          ^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 410, in pin    pin = self.pin_class(self, info)          ^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3/dist-packages/gpiozero/pins/lgpio.py", line 126, in __init__    lgpio.gpio_claim_input(  File "/usr/lib/python3/dist-packages/lgpio.py", line 755, in gpio_claim_input    return _u2i(_lgpio._gpio_claim_input(handle&0xffff, lFlags, gpio))           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/usr/lib/python3/dist-packages/lgpio.py", line 458, in _u2i    raise error(error_text(v))lgpio.error: 'GPIO busy'

INFORMATION ABOUT THE SYSTEM:

OS: Debian GNU/Linux 12 (bookworm) aarch64
Host: Raspberry Pi 5 Model B Rev 1.0
Kernel: 6.6.28+rpt-rpi-2712
Uptime: 1 hour, 5 mins
Packages: 1547 (dpkg)
Shell: bash 5.2.15
Resolution: 2560x1440
DE: LXDE-pi-wayfire
WM: wayfire
Theme: PiXflat [GTK3]
Icons: PiXflat [GTK3]
Terminal: lxterminal
Terminal Font: Monospace 10
CPU: (4) @ 2.400GHz
Memory: 2331MiB / 8048MiB



PS: I tried with different pins and it gives me the same error. At the first attempt it ran well. Hope that someone can help me with this one

Statistics: Posted by a81310 — Tue Jun 04, 2024 10:48 pm



Viewing all articles
Browse latest Browse all 1225

Trending Articles