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

Replace RPi.GPIO with rpi-lgpio for V2 legacy #2469

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

s-martin
Copy link
Collaborator

@s-martin s-martin commented Dec 22, 2024

Following the discussion in #2313 replacing RPi.GPIO with rpi-lgpio

@hoffie @varac

@s-martin s-martin added bug legacy_v2 Issues, discussions and PRs related to Version 2.x labels Dec 22, 2024
@s-martin s-martin added this to the v2.9.0 milestone Dec 22, 2024
@s-martin s-martin linked an issue Dec 22, 2024 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Dec 22, 2024

Pull Request Test Coverage Report for Build 12700220430

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 78.51%

Totals Coverage Status
Change from base Build 12430982183: 0.0%
Covered Lines: 453
Relevant Lines: 577

💛 - Coveralls

@Groovylein
Copy link
Collaborator

I had similar issues and did the same thing. Now everything is working 👍

Copy link
Collaborator

@AlvinSchiller AlvinSchiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not sufficient. If the pi-rc522 package is installed later on, the dependency for RPi.GPIO is resolved and installed. In the end both libs are installed (rpi-lgpio and rpi-gpio) which breaks the reader.

Possible solution:
On installation of the pi-rc522 package the option "--no-deps" needs to be added, to not install the RPi.GPIO package.

.../components/rfid-reader/RC522/requirements.txt

# RC522 related requirements
# You need to install these with `sudo python3 -m pip install --upgrade --force-reinstall --no-deps -q -r requirements.txt`

spidev
pi-rc522==2.3.0

.../components/rfid-reader/RC522/setup_rc522.sh#L26

sudo python3 -m pip install --upgrade --force-reinstall --no-deps -q -r "${JUKEBOX_HOME_DIR}"/components/rfid-reader/RC522/requirements.txt

Downside: if any other package is installed, which has a RPi.GPIO dependecy, the reader breaks again. But i did not find any option to block a single package in pip.
Also if the rpi-lgpio package would not be installed before, the reader is also non-functional (but as it is listed in our main reqiurement, this is negligible).

Any other/better ideas?

scripts/installscripts/install-jukebox.sh Outdated Show resolved Hide resolved
@AlvinSchiller
Copy link
Collaborator

AlvinSchiller commented Dec 30, 2024

This change is not sufficient. If the pi-rc522 package is installed later on, the dependency for RPi.GPIO is resolved and installed. In the end both libs are installed (rpi-lgpio and rpi-gpio) which breaks the reader.

Possible solution: On installation of the pi-rc522 package the option "--no-deps" needs to be added, to not install the RPi.GPIO package.

.../components/rfid-reader/RC522/requirements.txt

# RC522 related requirements
# You need to install these with `sudo python3 -m pip install --upgrade --force-reinstall --no-deps -q -r requirements.txt`

spidev
pi-rc522==2.3.0

.../components/rfid-reader/RC522/setup_rc522.sh#L26

sudo python3 -m pip install --upgrade --force-reinstall --no-deps -q -r "${JUKEBOX_HOME_DIR}"/components/rfid-reader/RC522/requirements.txt

Downside: if any other package is installed, which has a RPi.GPIO dependecy, the reader breaks again. But i did not find any option to block a single package in pip. Also if the rpi-lgpio package would not be installed before, the reader is also non-functional (but as it is listed in our main reqiurement, this is negligible).

Any other/better ideas?

Another option would be to use the pi-rc522-gpiozero from @hoffie. But i did not test it yet.
But this is maybe a too big change for V2. Especially asgpiozero is discouraged in V2.

@s-martin
Copy link
Collaborator Author

This change is not sufficient. If the pi-rc522 package is installed later on, the dependency for RPi.GPIO is resolved and installed. In the end both libs are installed (rpi-lgpio and rpi-gpio) which breaks the reader.

Good catch!

[…]

Downside: if any other package is installed, which has a RPi.GPIO dependecy, the reader breaks again. But i did not find any option to block a single package in pip. Also if the rpi-lgpio package would not be installed before, the reader is also non-functional (but as it is listed in our main reqiurement, this is negligible).

Any other/better ideas?

For me the downside would be ok as we don’t want to add new functionality to V2 (= no new packages) - nevertheless I’m aware so far we updated many things on V2 although we didn’t want to.

maybe we can add a test to CI, which at least recognizes, if we install RPi.GPIO again.

@AlvinSchiller
Copy link
Collaborator

AlvinSchiller commented Jan 1, 2025

Turns out there are some more problems, regarding compatibility to bullseye.
The rpi-lgpio lib throws errors as it seems the binary of lgpio is broken fit bullseye (glibc is expected in version 2.33 but bullseye only has 2.31).
It works though if lgpio is build manually.

I also tried to keep RPi.GPIO for bullseye, but that was complicated to handle, especially for automatic tests.

Also the order of de-/installation of the two libs is important. It must be a deinstallation first, otherwise imports are broken
(I tried to play around the" no-deps" option, but this was the showstopper for this solution).

What seems to work now (final tests pending, but ci looks good. Commit with the changes will follow):

  • On setup(or update) the old rpi-gpio lib is removed (pip and apt as bullseye has the apt package installed by default and pip can't remove it).

  • install rpi-lgpio as replacement

  • manually handle libs with dependencies to RPi.GPIO (currently only pi-rc22) with the "no-deps" option.

  • for bullseye and below manually build lgpio

  • check in ci tests that RPi.GPIO is not installed.

@AlvinSchiller
Copy link
Collaborator

AlvinSchiller commented Jan 1, 2025

Also to mention are some incompatibilities of the libs. See rpi-lgpio differences

  • Pi 1 Models (B, A, A+, B+, and Compute Module 1) are not supported right away, and need a special environment variable to work. I think this is not a big issue but needs to be documented.

  • The gpio_function function behave differently, but I didn't find any usage of it in the project.

  • simultaneous access of pins does not work anymore. Should not be a problem for the main functionality but some special use case with hardware might not work.

  • debounce behaviour has changed, which causes some unexpected delay.
    This is notable on using Buttons. An example is pressing a button continuously quite fast (debounce == bouncetime defaults to 500ms).
    -- With the old RPi.GPIO lib the function is trigger immediatly on press every 500 ms.
    -- With the new rpi-lgpio lib the function is not triggered at all, only after the state is stable for 500ms (= button not pressed).
    With this behavior every hold_mode with hold_time has a longer delay as originally (extended by bouncetime)

components/rfid-reader/RC522/requirements.txt Outdated Show resolved Hide resolved
scripts/installscripts/install-jukebox.sh Outdated Show resolved Hide resolved
CONTRIBUTING.md Outdated Show resolved Hide resolved
packages-excluded.txt Outdated Show resolved Hide resolved
requirements-excluded.txt Outdated Show resolved Hide resolved
scripts/installscripts/install-jukebox.sh Outdated Show resolved Hide resolved
scripts/installscripts/install-jukebox.sh Show resolved Hide resolved
Co-authored-by: s-martin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug legacy_v2 Issues, discussions and PRs related to Version 2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 | bookworm/kernel 6.6 GPIO: Failed to add edge detection
4 participants