Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 | bookworm/kernel 6.6 GPIO: Failed to add edge detection #2313

Open
varac opened this issue Mar 30, 2024 · 26 comments
Open

🐛 | bookworm/kernel 6.6 GPIO: Failed to add edge detection #2313

varac opened this issue Mar 30, 2024 · 26 comments
Labels

Comments

@varac
Copy link
Contributor

varac commented Mar 30, 2024

Version

3.5.2

Branch

future/main

OS

RPI OS bookworm lite - 32bit

Pi model

3 B+

Hardware

What happened?

After a fresh install of RPI OS bookworm lite, 32-bit with latest future/main, the GPIO buttons and the RFID reader stopped working (They worked before with the same configuration on an older 2.x installation on RPI OS bullseye).
I saw this discussion thread which confirms this issue, but I wanted to create a dedicated issue for it, to not bloat the discussion topic too much since it covers also other issues of a bookworm/future/main installation.

I can see this relevant log entry:

Exception in thread read_00Thread:
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/home/varac/RPi-Jukebox-RFID/src/jukebox/components/rfid/reader/__init__.py", line 143, in run
    self._reader = self._reader_module.ReaderClass(self._reader_cfg_key)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/varac/RPi-Jukebox-RFID/src/jukebox/components/rfid/hardware/rc522_spi/rc522_spi.py", line 85, in __init__
    self.device = pirc522.RFID(bus=spi_bus,
                  ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/varac/RPi-Jukebox-RFID/.venv/lib/python3.11/site-packages/pirc522/rfid.py", line 103, in __init__
    GPIO.add_event_detect(pin_irq, GPIO.FALLING,
RuntimeError: Failed to add edge detection

In the discussion Sharing tips for future3 on bookworm/kernel 6.6 and upstreaming fixes #2295 @hoffie pointed out possible ways forward but I am missing concrete instructions know how to actually fix this issue on my current installation. Any help welcome, thanks already !

Logs

app.log
errors.log
INSTALL-1710188086.log

Configuration

rfid.yaml.txt
jukebox.yaml.txt
gpio.yaml.txt

More info

No response

@varac varac added bug future3 Relates to future3 development needs triage labels Mar 30, 2024
@AlvinSchiller
Copy link
Collaborator

AlvinSchiller commented Mar 30, 2024

Hi, currently there is no immediate solution, other then using bullseye.

The linked discussion suggests swapping the pirc lib, so you could try this by uninstalling the old one and install from the linked repo.

But we need to look into it, cause at least the buttons should work in v3.

@hoffie
Copy link
Contributor

hoffie commented Apr 1, 2024

I am missing concrete instructions know how to actually fix this issue on my current installation.

Here is what I did:

Use system lgpio (because the version on pypi is too old):
(Update: Maybe this step is no longer necessary, since 0.2.2.0 seems to be on pypi since 2024-03-29?)

rm /home/phoniebox/RPi-Jukebox-RFID/.venv/lib/python3.11/site-packages/lgpio.py /home/phoniebox/RPi-Jukebox-RFID/.venv/lib/python3.11/site-packages/lgpio-0.2.2.0.egg-info /home/phoniebox/RPi-Jukebox-RFID/.venv/lib/python3.11/site-packages/_lgpio.cpython-311-arm-linux-gnueabihf.so
ln -s /usr/lib/python3/dist-packages/lgpio.py /home/phoniebox/RPi-Jukebox-RFID/.venv/lib/python3.11/site-packages/lgpio.py
ln -s /usr/lib/python3/dist-packages/lgpio-0.2.2.0.egg-info/ /home/phoniebox/RPi-Jukebox-RFID/.venv/lib/python3.11/site-packages/lgpio-0.2.2.0.egg-info
ln -s /usr/lib/python3/dist-packages/_lgpio.cpython-311-arm-linux-gnueabihf.so /home/phoniebox/RPi-Jukebox-RFID/.venv/lib/python3.11/site-packages/_lgpio.cpython-311-arm-linux-gnueabihf.so

Configure Jukebox gpio.yaml to use LGPIO for buttons:
I'm using this in my gpio.yml and it works (other Factories may work as well, I haven't tried):

pin_factory:
  # Default is RPi.GPIO, which can't handle buttons on kernel 6.6+ anymore:
  type: lgpio.LGPIOFactory

Replace PIRC522 by PIRC522-gpiozero:

bash -c "source /home/phoniebox/RPi-Jukebox-RFID/.venv/bin/activate && pip uninstall pi-rc522 && pip install git+https://github.com/hoffie/pi-rc522-gpiozero/"`

You could also try to replace the broken RPi.GPIO by the following shim. I haven't tested it though. It might still need the above lgpio changes, but it should make the other changes redundant:
https://rpi-lgpio.readthedocs.io/en/release-0.4/install.html

@varac
Copy link
Contributor Author

varac commented Apr 6, 2024

@hoffie Thanks, I can confirm that your instructions work, my rfc 522 reader works again 🎉 !
I don't know how to properly include this fix in the install script though, but it works as a reference workaround to make the rfc module working with current bookworm PiOS.

@varac
Copy link
Contributor Author

varac commented Apr 6, 2024

I wonder if it would make sense to create a bookworm issue label to gather all bookworm-related issues. I'd be happy to test if needed.

@s-martin
Copy link
Collaborator

I tend to the lgpio and the rc522 gpiozero solution, because I think while the shim might be the most non-intrusive solution right now I'm not sure, if this will work as a long term solution.

Don't know what others think here?

@hoffie, did you make a PR to the rc522, so this fix may be included?
Nevertheless I think we could also use your branch.

@hoffie
Copy link
Contributor

hoffie commented May 16, 2024

@hoffie, did you make a PR to the rc522, so this fix may be included?

Not yet, because the changes seemed a bit too fundamental. I'll try to find some time in the coming days.
(Sorry, I was rather unresponsive, also on my other interactions here; real life is rather busy right now)

@s-martin
Copy link
Collaborator

Real life always comes first ;)

@ben0r33
Copy link

ben0r33 commented May 22, 2024

So I can confirm @hoffie second solution by simple uninstalling python package rpi-gpio and instlling rpi-lgpio instead via pip to make rfid reader rc522 work again with latest linux kernel 6.6.28 on Raspbian Bookworm with RPI4:

systemctl --user stop jukebox-daemon
source .venv/bin/activate
pip uninstall rpi-gpio
pip install rpi-lgpio
systemctl --user start jukebox-daemon

Maybe the best option would be always using rpi-lgpio package moving forward?

@s-martin
Copy link
Collaborator

Right now I think using the shim rpi-lgpio looks like the easiest solution (despite my comments earlier), because it's a one line replacement in requirements.txt

Only question to @pabera or @AlvinSchiller: I would like to use a RPi.GPIO uninstall command to make it more robust, where would be a good place in the installation scripts?

@AlvinSchiller
Copy link
Collaborator

Right now I think using the shim rpi-lgpio looks like the easiest solution (despite my comments earlier), because it's a one line replacement in requirements.txt

Only question to @pabera or @AlvinSchiller: I would like to use a RPi.GPIO uninstall command to make it more robust, where would be a good place in the installation scripts?

For v2 this could be done right before the apt installation.
For v3 we have currently no automated update path, so this would be only a hint in the documentation / release notes (like we already have in the current develop version )

@s-martin s-martin mentioned this issue May 24, 2024
9 tasks
@alesrosina
Copy link

Hello, I'm now trying to install it on a bookworm, and rfid works after I've replaced rpio-gpio with rpi-lgpio (according to this comment #2313 (comment)). I'm using rc522 rfid reader.

With two issues that I'm not sure why it's happening:

Same setup worked on raspberry 1 with previous version of raspberry os (so all gpio buttons & rfid reader), but now I've changed it with raspberry 3B+ and installed also 64 bit OS. I know you're mentioning, that we should use 32 bit version, but since all other things are working on 64 bit os, I don't see why this should not. For installation on 64 bit i removed checks in install script and it (mostly) worked.

Any ideas would be appreciated.

@s-martin
Copy link
Collaborator

s-martin commented Jun 7, 2024

With two issues that I'm not sure why it's happening:

  • gpio buttons (rotary button, led light and a normal button) does not seems to work. I cannot see any errors anywhere, and since rfid is working, not sure what's going on

Can you post your gpio.yaml (assuming you use V3) and the logs?

Ntags don't work at the moment. See #2373

@AlvinSchiller
Copy link
Collaborator

Same setup worked on raspberry 1 with previous version of raspberry os

Are you sure that the NTAGs also worked with the previous setup? That wouldn't match our observation.

@alesrosina
Copy link

Same setup worked on raspberry 1 with previous version of raspberry os

Are you sure that the NTAGs also worked with the previous setup? That wouldn't match our observation.

Now I'm not sure anymore :)

It definitely worked on v2, but when I've installed v3 I'm no longer sure, since on raspi 1 it never worked nicely (web interface didnt respond well) and I assumed, this was due to lack of power on raspi1. So afterwards it was never fully in use, until I've now stated playing around with raspi3.

@alesrosina
Copy link

Can you post your gpio.yaml (assuming you use V3) and the logs?

Sure:

pin_factory:
  type: lgpio.LGPIOFactory

input_devices:
  VolumeRotator:
    type: RotaryEncoder
    kwargs:
      a: 27
      b: 22
    actions:
      on_rotate_clockwise:
        alias: change_volume
        args: 5
      on_rotate_counter_clockwise:
        alias: change_volume
        args: -5

output_devices:
  StatusLED:
    type: LED
    connect:
      - gpio.gpioz.plugin.connectivity.register_status_led_callback
    kwargs:
      pin: 14
[app.log](https://github.com/user-attachments/files/15728795/app.log)

Here's also app.log:

app.log

@AlvinSchiller
Copy link
Collaborator

AlvinSchiller commented Jun 7, 2024

pin_factory: type: lgpio.LGPIOFactory

I think the changed factory is not needed if you only swapped the libs. Can you try with the "old"/original?

@alesrosina
Copy link

pin_factory: type: lgpio.LGPIOFactory

I think the changed factory is not needed if you only swapped the libs. Can you try with the "old"/original?

Tried. Same result.

Should I also try to replace libs as suggested in first comment? #2313 (comment)
Probably not important, since rfid reader works ...

@s-martin
Copy link
Collaborator

s-martin commented Jun 7, 2024

Should I also try to replace libs as suggested in first comment? #2313 (comment)
Probably not important, since rfid reader works ...

No, as your reader works....

@alesrosina
Copy link

Should I also try to replace libs as suggested in first comment? #2313 (comment)
Probably not important, since rfid reader works ...

No, as your reader works....

Is there anything else I could provide, just to get some ideas what's going on? Or any direction in which I could be looking.

One thing I forgot to metion is, that I've did an install directly from future3/develop branch.

@s-martin
Copy link
Collaborator

s-martin commented Jun 7, 2024

Did you activate GPIO in jukebox.yaml?

Line 106:

gpioz:
  enable: true
  config_file: ../../shared/settings/gpio.yaml

enable needs to be true

@alesrosina
Copy link

Did you activate GPIO in jukebox.yaml?

Line 106:

gpioz:
  enable: true
  config_file: ../../shared/settings/gpio.yaml

enable needs to be true

Oh. 🙈 Of course, this was the reason. Thanks for this, this was a very obvious mistake.

So with this out of the way, I can confirm v3 is working as it should on raspberian 64bit bookworm (raspberry 3B+), so I guess this limitation could be removed from setup, right?

@s-martin
Copy link
Collaborator

s-martin commented Jun 7, 2024

Cool!

Thanks for trying 64 bit Bookworm. So we will figure out how to handle 64bit in the future.

@plimptm
Copy link

plimptm commented Jun 27, 2024

I just took another stab at this on a pi zero w (armv6l) and the pip install rpi-lgpio failed as unable to to build the wheel for lgpio (might be a code/architecture issue).

I tested installing rpi-lgpio in a clean venv using the --system-site-packages option (per this rpi-lgpio doc page) and that met the lgpio dependency for the shim to install. I believe that means the symlink strategy @hoffie suggested here would also work, though using the rpi-lgpio shim might render the rest of those steps unecessary.

I'm going to see if I can get this working within the proper venv using symlinks + the shim and will update here with my results.

Update: confirmed that creating symlinks for lgpio from the system python library into the project venv was enough to be able to install rpi-lgpio. So, right now, for armv6l platform on bookworm, this workaround should be helpful:

systemctl --user stop jukebox-daemon
cd; source RPi-Jukebox-RFID/.venv/bin/activate
pip uninstall rpi-gpio
ln -s /usr/lib/python3/dist-packages/lgpio.py /home/pi/RPi-Jukebox-RFID/.venv/lib/python3.11/site-packages/lgpio.py
ln -s /usr/lib/python3/dist-packages/lgpio-0.2.2.0.egg-info/ /home/pi/RPi-Jukebox-RFID/.venv/lib/python3.11/site-packages/lgpio-0.2.2.0.egg-info
ln -s /usr/lib/python3/dist-packages/_lgpio.cpython-311-arm-linux-gnueabihf.so /home/pi/RPi-Jukebox-RFID/.venv/lib/python3.11/site-packages/_lgpio.cpython-311-arm-linux-gnueabihf.so
pip install rpi-lgpio
deactivate
systemctl --user start jukebox-daemon

@rgbetanco
Copy link

I am using Debian GNU/Linux 12 (bookworm) on Raspberry Pi 5, I had cloned the branch pi-rc522-gpiozero and ran the setup.py in it. I have uninstall rpi-gpio and install rpi-lgpio. I connected the RC522 module to the pi and ran the example code. Nothing happens, no card is detected. Pi5 is 64bits.

@alexxx-k
Copy link

Hello,

i stumbled accross the issue as well on my RP4 running 32bit
Linux phoniebox 6.6.51+rpt-rpi-v7l #1 SMP Raspbian 1:6.6.51-1+rpt3 (2024-10-08) armv7l GNU/Linux.

First i thought my wiring is wrong, so i followed a tiny tutorial (https://www.youtube.com/watch?v=evRuZRxvPFI)

from there i tested these two scripts.
This does work very well. Maybe this is a possible solution as well.

example.zip

@alexxx-k
Copy link

alexxx-k commented Oct 31, 2024

Hello, I made a testfile that get my reader working.
This file breaks the _read_card_legacy method. I basically do not understand what its purpose so, i cannot make any fix here.

RPi-Jukebox-RFID/src/jukebox/components/rfid/hardware/rc522_spi/rc522_spi.py
rc522_spi.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants