You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GPIO.add_event_detect no longer works with the new kernel 6.60 #6037
Feb 29 2024 12:24:53
Copyright (c) 2012 Broadcom
version f4e2138c2adc8f3a92a3a65939e458f11d7298ba (clean) (release) (start)
Logs
No response
Additional context
No response
Reacted by Christian Hoffmann, Nils K, Mark Ireland, xtreye, Cody Scott, Qichen, tobyaharris, noorullah-karimi, Alexandru Dulgheriu, radutomy and 5 more
I suspect this is because the rpi-6.6.y kernel no longer overrides an upstream kernel decision to force the base number of the main GPIO controller to be global GPIO 0. Running cat /sys/kernel/debug/gpio will show that GPIO0 (named ID_SDA) is allocated global GPIO number 512. It is going to be painful until the 3rd party libraries are updated, but the choice to stop swimming against the tide was intentional.
Okay, if that was the intention, then I know. Since many tutorials on the internet still use the RPi.GPIO library, this will definitely be painful for users.
I also don't think that the RPi.GPIO library will receive an update or be adapted, as it has not received an update for the Raspberry Pi 5 either.
What sensible alternative should users use? Especially with a trigger for events?
Old Kernel on a other RPI:
gpiochip0: GPIOs 0-53, parent: platform/3f200000.gpio, pinctrl-bcm2835:
gpio-0 (ID_SDA )
gpio-1 (ID_SCL )
gpio-2 (SDA1 )
gpio-3 (SCL1 )
gpio-4 (GPIO_GCLK )
gpio-5 (GPIO5 )
gpio-6 (GPIO6 )
gpio-7 (SPI_CE1_N )
gpio-8 (SPI_CE0_N )
gpio-9 (SPI_MISO )
gpio-10 (SPI_MOSI )
gpio-11 (SPI_SCLK )
gpio-12 (GPIO12 )
gpio-13 (GPIO13 |sysfs ) in lo IRQ
gpio-14 (TXD1 )
gpio-15 (RXD1 )
gpio-16 (GPIO16 )
gpio-17 (GPIO17 )
gpio-18 (GPIO18 |sysfs ) in lo IRQ
gpio-19 (GPIO19 |sysfs ) in lo IRQ
gpio-20 (GPIO20 )
gpio-21 (GPIO21 )
gpio-22 (GPIO22 |sysfs ) in lo IRQ
gpio-23 (GPIO23 )
gpio-24 (GPIO24 )
gpio-25 (GPIO25 |sysfs ) in lo IRQ
gpio-26 (GPIO26 |sysfs ) in lo IRQ
gpio-27 (GPIO27 |sysfs ) in lo IRQ
gpio-28 (NC )
gpio-29 (LAN_RUN_BOOT )
gpio-30 (CTS0 )
gpio-31 (RTS0 )
gpio-32 (TXD0 )
gpio-33 (RXD0 )
gpio-34 (SD1_CLK )
gpio-35 (SD1_CMD )
gpio-36 (SD1_DATA0 )
gpio-37 (SD1_DATA1 )
gpio-38 (SD1_DATA2 )
gpio-39 (SD1_DATA3 )
gpio-40 (PWM0_OUT )
gpio-41 (PWM1_OUT )
gpio-42 (ETH_CLK )
gpio-43 (WIFI_CLK )
gpio-44 (SDA0 )
gpio-45 (SCL0 )
gpio-46 (SMPS_SCL )
gpio-47 (SMPS_SDA )
gpio-48 (SD_CLK_R )
gpio-49 (SD_CMD_R )
gpio-50 (SD_DATA0_R )
gpio-51 (SD_DATA1_R )
gpio-52 (SD_DATA2_R )
gpio-53 (SD_DATA3_R )
gpiochip1: GPIOs 100-101, brcmvirt-gpio, can sleep:
gpio-100 ( |ACT ) out lo
gpiochip3: GPIOs 500-503, parent: usb/1-1.2:1.0, ftdi-cbus, can sleep:
gpiochip2: GPIOs 504-511, parent: platform/soc:firmware:expgpio, raspberrypi-exp-gpio, can sleep:
gpio-504 (BT_ON |shutdown ) out hi
gpio-505 (WL_ON )
gpio-506 (STATUS_LED )
gpio-507 (LAN_RUN )
gpio-508 (HDMI_HPD_N |hpd ) in lo ACTIVE LOW
gpio-509 (CAM_GPIO0 |cam1_regulator ) out lo
gpio-510 (CAM_GPIO1 )
gpio-511 (PWR_LOW_N |PWR ) in hi
I suspect this is because the rpi-6.6.y kernel no longer overrides an upstream kernel decision to force the base number of the main GPIO controller to be global GPIO 0. Running cat /sys/kernel/debug/gpio will show that GPIO0 (named ID_SDA) is allocated global GPIO number 512. It is going to be painful until the 3rd party libraries are updated, but the choice to stop swimming against the tide was intentional.
Ok, what is the fix? Sorry for the basic question. Newbie at Rpi
The fix is for someone to patch RPi.GPIO to locate the global GPIO number for GPIO0, and add that as an offset to the requested GPIO number. In this case it is likely to be 512.
Thanks Phil. I guess I'll have to wait for 'someone'. Although I'd be
willing to do such a fix, I have zero experience in RPi for the time being.
Saludos, Greetings
*Jean-Robert STRELE*
COL: +57.321.414.6328
USA: +1.925.922.4231
***@***.***
ᐧ
I thought we'd pulled that shim into Raspberry Pi OS, but we only appear to have python3-rpi.gpio and not python3-rpi-gpio. @XECDesign am I wrong on this one?
Now you are really crossing the streams. The config.txt lines are interpreted by the firmware, which should then set default pull-ups on some pins and make others outputs. These changes may persist once the kernel has booted, but they may also be overwritten.
Are you saying that this changed with the switch to the 6.6 kernel?
Can you point out some parts of the /sys/kernel/debug/gpio output that show the problem?
I thought we'd pulled that shim into Raspberry Pi OS, but we only appear to have python3-rpi.gpio and not python3-rpi-gpio. @XECDesign am I wrong on this one?
Off the top of my head, I'm not sure. Last time I looked at GPIO libraries, there was some uncertainty about what the right way forward is and what to focus on. I'll revisit when I'm back in April.
@pelwell we can separate that, sure. Wasn't sure if it's also related here. But yes, it's new since the switch on 6.6. not sure what's the cause, kernel or other firmware/OS related changes.
To me it looks like there's also a difference on the GPIO mapping (gpio 3 on Pi 4 on 515, Pi 5 on 574), is that true in general or depends on the kernel Version? Linux 6.6.20+rpt-rpi-2712 aarch64 is installed. Can post more information in April, don't get hands on my Pi next 2 weeks...
Hello,
If I understand the conversation correctly we are looking for a solution
sometime in April, correct?
Just so I can plan my project around this.
Have a good weekend
Saludos, Regards,
Jean-Robert STRELE
COL +57.321.414.6328
USA +1.925.922.4231
***@***.***
This is a local project for my pool chemistry. One time solution.
I don't have the knowledge to build/modify my own RPi.gpio.
So, yes, a local solution would be acceptable to me as an interim solution,
until a stock solution is available...
Keep in mind, I'm a newbie at RPi...
Thanks!
On Fri, Mar 15, 2024, 12:50 Phil Elwell ***@***.***> wrote:
we are looking for a solution sometime in April, correct?
You probably won't get an answer before April, but there is no timeframe
for a solution.
So we can understand your situation a bit better:
1. Are you building RPi.GPIO yourself?
2. Are you shipping/going to ship it to your customers (if there are
customers)?
3. In other words, would a locally modified version of RPi.GPIO be a
workable solution?
—
Reply to this email directly, view it on GitHub
<#6037 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQXPNSHM26OUXSW3M2WH4TYYMYHJAVCNFSM6AAAAABEUTY3D2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBQGE2TONRXGQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
☝️ Is it worth mentioning that in the docs @aallan ? 🤷
(also ping @waveform80 as a heads-up that he might get more people using rpi-lgpio now 😃 )
Yikes! As someone semi-connected/responsible for this state of affairs, it's probably time I waded in. I'm not going to respond to everything, but here's some important points:
But now to the topic. In my humble opinion, letting die the RPi.GPIO library is one of the biggest mistakes of the Raspberry Pi Foundation.
It's not the Pi Foundation's library (they simply went with what the community leapt on as "the" GPIO library), and they're not "letting [it] die". This is a change that's being driven upstream from the Linux kernel. For the full story, I wrote a long and very boring blog post about it several years ago but the long and short is that the kernel really doesn't like processes bypassing it entirely and stomping on registers it thinks it has exclusive access to, and it's a minor miracle it's worked as well as it has for as long as it did.
The abstraction also breaks the second the hardware changes fundamentally, as it's now had to with the Pi 5 (the GPIOs are no longer driven by the SoC but by the RP1 at the other end of a PCIe bus).
All in all, this state of affairs was never going to last.
the GPIOZERO library is not an equivalent replacement. First of all, GPIOS cannot be accessed with several programs at the same time. The new library may be suitable for beginners, but if you are an advanced beginner, this is no longer the case. Not everyone is familiar with sockets or named pipes. The leap is simply too big for many beginners. RPi.GPIO could do this without any problems.
@Blackbox-git , "add_event_detect works" as expected on RPi4s running Bookworm when using the rpi-lgpio package
Yes. But you cant access from another programm the gpio with this libary.
Yes, it's not an equivalent replacement. However, the complaint that GPIOs cannot be accessed simultaneously by separate processes is to do with the new kernel-based system of driving GPIOs. It's nothing to do with gpiozero (which will happily share pins between processes if the underlying driver, like RPi.GPIO, permits it, but when the underlying driver doesn't, like lgpio, there's nothing we can do about it).
Frankly anything built on the new kernel-based system of driving GPIOs will not support this. If you are relying on it, you need to find a new way of doing things, like using threading instead of processes, or IPC between processes (having one process that handles your GPIOs and let your other processes talk to it).
if you terminate a program that uses the GPIOZERO library, the current state of the GPIO is not retained after termination. This means that no script can be programmed that changes the state of the pin and is then terminated. Beginners in the web area will find this particularly difficult.
Yes, and that's absolutely deliberate (there's a story behind this choice... I should write another blog post about that... hears the audience groaning).
It's also arguable whether this is easier or harder for "beginners in the web area". It's only harder if you're using separate processes per request (in which case you're going to get bitten by processes sharing pins anyway).
Switch to a threading or async model and you deal with both problems simultaneously. In the traditional Python http.server module, this is as simple as changing one keyword (ForkingMixIn to ThreadingMixIn) -- I'm afraid I'm rather out of date on other libraries, so I can't give recommendations there.
Therefore, in my humble opinion, the library should be adapted for all models, even if the original developer no longer does this, the maintenance could be continued by the Raspberry Pi Foundation.
Again, it's not their library, they've never maintained it, and it's not a question of anyone maintaining it. The kernel interfaces it relies upon are going away, and the new ones do not permit things like sharing GPIOs between processes.
good morning @TimW55, So, I installed a new venv and installed the rpi-lgpio package into it. Trying to run the following program (copied from my other project. agreed that it might not work as is):
[snip...]
Traceback (most recent call last): File "/tmp/pycharm_project_14/testlgpio.py", line 2, in import RPi.GPIO as GPIO File "/home/Helios/.virtualenvs/TestLGPIO/lib/python3.11/site-packages/RPi/GPIO/init.py", line 13, in import lgpio ModuleNotFoundError: No module named 'lgpio' ' ᐧ
Argh, this is at least partially my fault, but should now be corrected.
For a long time, lgpio's had a very out of date source package up on PyPI because joan, the author of lg (the project containing lgpio) isn't an expert on Python packaging which is a convoluted area in recent years, to say the least (ask me how I know...). I finally found a bit of time to dig into this and figure out how to build some pre-compiled wheels of lgpio for PyPI for a variety of Python versions. So, as of a couple of weeks ago there should be a decent variety of wheels for the two main architectures available from PyPI.
If you've been struggling with getting lgpio (or rpi-lgpio, which I'll come onto shortly) running, please try again (or upgrade your venv to the current lgpio wheel versions) and hopefully things should go smoother this time. And sorry it's taken me so long to get around to this!
This is especially annoying as fixing this within (Docker) containers is even more annoying. lgpio only has a very old version up on pypi which is incompatible with gpiozero so I had to download a tar from a fork and compile that (as it uses native C bindings) inside Docker :/
Yes, rpi-lgpio is intended as a drop-in replacement for RPi.GPIO in the new kernel-based /dev/gpiochip world. If you're desperate to read more of my rambling there's yet another blog post that introduces that one, but for most users I would urge them to read the differences chapter in the documentation prior to usage.
There will be some differences that I simply cannot paper over (like the aforementioned multiple-processes accessing one GPIO problem), and others that it's probably not worth papering over (see the Debounce section) because doing so would cause even more grief. The chapter should hopefully set your expectations for what's going to work and what's not.
Reacted by Nils K, XECDesign, Alasdair Allan, Liz Upton, Andrew Scheller, Tom Dewey, Ben Nuttall, Jasmin68k, Helen Lynn, Aiden Scandella and 1 more
Thanks @dave Jones,
Yesterday I broke my SD Card while changing RPi cases and since I was
developing my project on PyCharm via SAMBA and SSH, and only was doing
commits instead of Pushes, I lost 8 weeks' worth of learning/coding! DUH!
But, silver lining, I get to re-evaluate my program structure and clean out
all the trial/errors that have been accumulating on the RPi and the code.
One of the findings was that when installing lgpio inside the venv, it
worked on the first try, drop-in compatible with the snippet of code I had
emailed to someone and as a result got preserved. So, thanks again @dave
Jones for fixing that part.
On a peripherally related topic: I'm using PyCharm's AI Assistant
extensively in my coding and it is he/she that recommended using RPi.GPIO
in the first place (about 8 weeks ago). So there is some truth to an
earlier comment about RPi.GPIO being the de-facto standard. Yesterday I
told AI Assistant that RPi.GPIO in its existing form was broken and what to
recommend instead: 'gpiozero' or 'RPi.GPIO2' came back the answer. I guess
more coders on PyCharm will need to update their code to lgpio for AI to
catch up.
Cheers.
ᐧ
On Wed, 10 Apr 2024 at 08:06, Dave Jones ***@***.***> wrote:
☝️ Is it worth mentioning that in the docs @aallan
<https://github.com/aallan> ? 🤷
(also ping @waveform80 <https://github.com/waveform80> as a heads-up that
he might get more people using rpi-lgpio now 😃 )
Yikes! As someone semi-connected/responsible for this state of affairs,
it's probably time I waded in. I'm not going to respond to everything, but
here's some important points:
But now to the topic. In my humble opinion, letting die the RPi.GPIO
library is one of the biggest mistakes of the Raspberry Pi Foundation.
It's not the Pi Foundation's library (they simply went with what the
community leapt on as "the" GPIO library), and they're not "letting [it]
die". This is a change that's being driven upstream from the Linux kernel.
For the full story, I wrote a long and very boring blog post
<https://waldorf.waveform.org.uk/2021/the-pins-they-are-a-changin.html>
about it several years ago but the long and short is that the kernel really
doesn't like processes bypassing it entirely and stomping on registers it
thinks it has exclusive access to, and it's a minor miracle it's worked as
well as it has for as long as it did.
The abstraction also breaks the second the hardware changes fundamentally,
as it's now had to with the Pi 5 (the GPIOs are no longer driven by the SoC
but by the RP1 at the other end of a PCIe bus).
All in all, this state of affairs was *never* going to last.
2. the GPIOZERO library is not an equivalent replacement. First of
all, GPIOS cannot be accessed with several programs at the same time. The
new library may be suitable for beginners, but if you are an advanced
beginner, this is no longer the case. Not everyone is familiar with sockets
or named pipes. The leap is simply too big for many beginners. RPi.GPIO
could do this without any problems.
@Blackbox-git <https://github.com/Blackbox-git> , "add_event_detect
works" as expected on RPi4s running Bookworm when using the *rpi-lgpio*
package
Yes. But you cant access from another programm the gpio with this libary.
Yes, it's not an equivalent replacement. However, the complaint that GPIOs
cannot be accessed simultaneously by separate processes is to do with the
new kernel-based system of driving GPIOs. It's nothing to do with gpiozero
(which will happily share pins between processes *if* the underlying
driver, like RPi.GPIO, permits it, but when the underlying driver doesn't,
like lgpio, there's nothing we can do about it).
Frankly *anything* built on the new kernel-based system of driving GPIOs *will
not support this*
<https://rpi-lgpio.readthedocs.io/en/release-0.4/differences.html#simultaneous-access>.
If you are relying on it, you need to find a new way of doing things, like
using threading instead of processes, or IPC between processes (having one
process that handles your GPIOs and let your other processes talk to it).
3. if you terminate a program that uses the GPIOZERO library, the
current state of the GPIO is not retained after termination. This means
that no script can be programmed that changes the state of the pin and is
then terminated. Beginners in the web area will find this particularly
difficult.
Yes, and that's absolutely deliberate (there's a story behind this
choice... I should write another blog post about that... *hears the
audience groaning*).
It's also arguable whether this is easier or harder for "beginners in the
web area". It's only harder if you're using separate processes per request
(in which case you're going to get bitten by processes sharing pins anyway).
Switch to a threading or async model and you deal with both problems
simultaneously. In the traditional Python http.server module
<https://docs.python.org/3/library/http.server.html>, this is as simple
as changing one keyword (ForkingMixIn to ThreadingMixIn) -- I'm afraid
I'm rather out of date on other libraries, so I can't give recommendations
there.
Therefore, in my humble opinion, the library should be adapted for all
models, even if the original developer no longer does this, the maintenance
could be continued by the Raspberry Pi Foundation.
Again, it's not their library, they've never maintained it, and it's not a
question of anyone maintaining it. The kernel interfaces it relies upon *are
going away*, and the new ones do not permit things like sharing GPIOs
between processes.
good morning @TimW55 <https://github.com/TimW55>, So, I installed a new
venv and installed the rpi-lgpio package into it. Trying to run the
following program (copied from my other project. agreed that it might not
work as is):
[snip...]
Traceback (most recent call last): File
"/tmp/pycharm_project_14/testlgpio.py", line 2, in import RPi.GPIO as GPIO
File
"/home/Helios/.virtualenvs/TestLGPIO/lib/python3.11/site-packages/RPi/GPIO/
*init*.py", line 13, in import lgpio ModuleNotFoundError: No module named
'lgpio' ' ᐧ
Argh, this is at least partially my fault, but *should* now be corrected.
For a long time, lgpio's had a very out of date source package up on PyPI
because joan, the author of lg (the project containing lgpio) isn't an
expert on Python packaging <joan2937/lg#24>
which is a convoluted area in recent years, to say the least (ask me how
I know <https://piwheels.org/>...). I finally found a bit of time to dig
into this and figure out how to build some pre-compiled wheels of lgpio for
PyPI for a variety of Python versions. So, as of a couple of weeks ago
there should be a decent variety of wheels
<https://pypi.org/project/lgpio/#files> for the two main architectures
available from PyPI.
If you've been struggling with getting lgpio (or rpi-lgpio, which I'll
come onto shortly) running, please try again (or upgrade your venv to the
current lgpio wheel versions) and hopefully things should go smoother this
time. And sorry it's taken me so long to get around to this!
This is especially annoying as fixing this within (Docker) containers is
even more annoying. lgpio only has a very old version up on pypi which is
incompatible with gpiozero so I had to download a tar from a fork and
compile that (as it uses native C bindings) inside Docker :/
See section above.
Or switch to rpi-lgpio, which has the same API:
https://github.com/waveform80/rpi-lgpio
Yes, rpi-lgpio is intended as a drop-in replacement for RPi.GPIO in the
new kernel-based /dev/gpiochip world. If you're desperate to read more of
my rambling there's yet another blog post
<https://waldorf.waveform.org.uk/2022/the-one-where-dave-breaks-stuff.html>
that introduces that one, but for most users I would urge them to read the differences
chapter <https://rpi-lgpio.readthedocs.io/en/latest/differences.html> in
the documentation prior to usage.
There *will* be some differences that I simply cannot paper over (like
the aforementioned multiple-processes accessing one GPIO problem), and
others that it's probably not worth papering over (see the Debounce
section
<https://rpi-lgpio.readthedocs.io/en/release-0.4/differences.html#debounce>)
because doing so would cause even more grief. The chapter should hopefully
set your expectations for what's going to work and what's not.
—
Reply to this email directly, view it on GitHub
<#6037 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFQXPNVRLSDCNRMBDHZDTIDY4U2NDAVCNFSM6AAAAABEUTY3D2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBXGQ4TIOJRHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
@Trilife, perhaps you have missed an important lesson. AI is not always factually correct. In deed the more I use it, and I use it a lot in my VS Code environment, the less I rely on its responses. Nevertheless AI, and ChatGPT in particular, has improved my productivity and the quality of my coding considerably.
My apologies for veering slightly off topic.
@TimW55,
Indeed, I have come to the same conclusion, but my coding skills are not
quite where I can discern fact from fiction. And yes, having AI put down a
skeleton to work on has sped up quality and speed.
I am using RPI 4B with Bullseye. I was able to fix this by rolling back the firmware update [rpi-update] to the stable version.
sudo apt-get update; sudo apt-get install --reinstall raspberrypi-bootloader raspberrypi-kernel
After that update the software and reboot
sudo apt-get update
sudo apt-get upgrade
Unable to install package rpi-lgpio: WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /musllinux-index/rpi-lgpio/ error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [8 lines of output] running bdist_wheel running build running build_py running build_ext building '_lgpio' extension swigging lgpio.i to lgpio_wrap.c swig -python -o lgpio_wrap.c lgpio.i error: command 'swig' failed: No such file or directory [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for lgpio ERROR: Could not build wheels for lgpio, which is required to install pyproject.toml-based projects
Unable to install package rpi-lgpio: error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [8 lines of output] running bdist_wheel running build running build_py running build_ext building '_lgpio' extension swigging lgpio.i to lgpio_wrap.c swig -python -o lgpio_wrap.c lgpio.i error: command 'swig' failed: No such file or directory [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for lgpio ERROR: Could not build wheels for lgpio, which is required to install pyproject.toml-based projects
As far as I know I cannot simply create a venv within pyscript, so how can I use lgpio?
@Beiri22 What version of Python are you using, and what OS are you on (I'm guessing HAOS but I've no idea what version of Python is currently on there)? I've uploaded wheels for armhf, arm64, amd64 on Python versions 3.9 through 3.12, so if your environment matches that it shouldn't be attempting to compile the wheel from source.
Activity
pelwell commentedon Mar 13, 2024
I suspect this is because the rpi-6.6.y kernel no longer overrides an upstream kernel decision to force the base number of the main GPIO controller to be global GPIO 0. Running
cat /sys/kernel/debug/gpiowill show that GPIO0 (named ID_SDA) is allocated global GPIO number 512. It is going to be painful until the 3rd party libraries are updated, but the choice to stop swimming against the tide was intentional.Blackbox-git commentedon Mar 13, 2024
Okay, if that was the intention, then I know. Since many tutorials on the internet still use the RPi.GPIO library, this will definitely be painful for users.
I also don't think that the RPi.GPIO library will receive an update or be adapted, as it has not received an update for the Raspberry Pi 5 either.
What sensible alternative should users use? Especially with a trigger for events?
Old Kernel on a other RPI:
New Kernel on the RPI 4:
Trilife commentedon Mar 14, 2024
Ok, what is the fix? Sorry for the basic question. Newbie at Rpi
pelwell commentedon Mar 14, 2024
The fix is for someone to patch RPi.GPIO to locate the global GPIO number for GPIO0, and add that as an offset to the requested GPIO number. In this case it is likely to be 512.
Trilife commentedon Mar 14, 2024
6by9 commentedon Mar 14, 2024
Ubuntu have already been down this path (GPIO via sysfs has totally gone there), and Dave Jones has written an RPi.GPIO shim on top of lgpio
https://waldorf.waveform.org.uk/2022/the-one-where-dave-breaks-stuff.html
https://rpi-lgpio.readthedocs.io/en/release-0.4/#
I thought we'd pulled that shim into Raspberry Pi OS, but we only appear to have python3-rpi.gpio and not python3-rpi-gpio.
@XECDesign am I wrong on this one?
andi34 commentedon Mar 14, 2024
On Pi 5
/boot/firmware/config.txtworked withIn the past, now only first 5 values take effect for each line.... (Values adjusted for sure)
pelwell commentedon Mar 14, 2024
Now you are really crossing the streams. The config.txt lines are interpreted by the firmware, which should then set default pull-ups on some pins and make others outputs. These changes may persist once the kernel has booted, but they may also be overwritten.
Are you saying that this changed with the switch to the 6.6 kernel?
Can you point out some parts of the
/sys/kernel/debug/gpiooutput that show the problem?XECDesign commentedon Mar 14, 2024
Off the top of my head, I'm not sure. Last time I looked at GPIO libraries, there was some uncertainty about what the right way forward is and what to focus on. I'll revisit when I'm back in April.
andi34 commentedon Mar 14, 2024
@pelwell we can separate that, sure. Wasn't sure if it's also related here. But yes, it's new since the switch on 6.6. not sure what's the cause, kernel or other firmware/OS related changes.
To me it looks like there's also a difference on the GPIO mapping (gpio 3 on Pi 4 on 515, Pi 5 on 574), is that true in general or depends on the kernel Version?
Linux 6.6.20+rpt-rpi-2712 aarch64is installed. Can post more information in April, don't get hands on my Pi next 2 weeks...andi34 commentedon Mar 14, 2024
597,598 and 595 are ignored.
pelwell commentedon Mar 15, 2024
The firmware still expects the GPIOs to be numbered from 0 (the firmware and kernel are completely different worlds), so:
was correct.
Trilife commentedon Mar 15, 2024
pelwell commentedon Mar 15, 2024
You probably won't get an answer before April, but there is no timeframe for a solution.
So we can understand your situation a bit better:
Trilife commentedon Mar 15, 2024
47 remaining items
lurch commentedon Apr 9, 2024
☝️ Is it worth mentioning that in the docs @aallan ? 🤷
(also ping @waveform80 as a heads-up that he might get more people using
rpi-lgpionow 😃 )pelwell commentedon Apr 9, 2024
And to say thank you, obviously
aallan commentedon Apr 9, 2024
The documentation talks about using
gpiozerowaveform80 commentedon Apr 10, 2024
Yikes! As someone semi-connected/responsible for this state of affairs, it's probably time I waded in. I'm not going to respond to everything, but here's some important points:
It's not the Pi Foundation's library (they simply went with what the community leapt on as "the" GPIO library), and they're not "letting [it] die". This is a change that's being driven upstream from the Linux kernel. For the full story, I wrote a long and very boring blog post about it several years ago but the long and short is that the kernel really doesn't like processes bypassing it entirely and stomping on registers it thinks it has exclusive access to, and it's a minor miracle it's worked as well as it has for as long as it did.
The abstraction also breaks the second the hardware changes fundamentally, as it's now had to with the Pi 5 (the GPIOs are no longer driven by the SoC but by the RP1 at the other end of a PCIe bus).
All in all, this state of affairs was never going to last.
Yes, it's not an equivalent replacement. However, the complaint that GPIOs cannot be accessed simultaneously by separate processes is to do with the new kernel-based system of driving GPIOs. It's nothing to do with gpiozero (which will happily share pins between processes if the underlying driver, like RPi.GPIO, permits it, but when the underlying driver doesn't, like lgpio, there's nothing we can do about it).
Frankly anything built on the new kernel-based system of driving GPIOs will not support this. If you are relying on it, you need to find a new way of doing things, like using threading instead of processes, or IPC between processes (having one process that handles your GPIOs and let your other processes talk to it).
Yes, and that's absolutely deliberate (there's a story behind this choice... I should write another blog post about that... hears the audience groaning).
It's also arguable whether this is easier or harder for "beginners in the web area". It's only harder if you're using separate processes per request (in which case you're going to get bitten by processes sharing pins anyway).
Switch to a threading or async model and you deal with both problems simultaneously. In the traditional Python http.server module, this is as simple as changing one keyword (
ForkingMixIntoThreadingMixIn) -- I'm afraid I'm rather out of date on other libraries, so I can't give recommendations there.Again, it's not their library, they've never maintained it, and it's not a question of anyone maintaining it. The kernel interfaces it relies upon are going away, and the new ones do not permit things like sharing GPIOs between processes.
Argh, this is at least partially my fault, but should now be corrected.
For a long time, lgpio's had a very out of date source package up on PyPI because joan, the author of lg (the project containing lgpio) isn't an expert on Python packaging which is a convoluted area in recent years, to say the least (ask me how I know...). I finally found a bit of time to dig into this and figure out how to build some pre-compiled wheels of lgpio for PyPI for a variety of Python versions. So, as of a couple of weeks ago there should be a decent variety of wheels for the two main architectures available from PyPI.
If you've been struggling with getting lgpio (or rpi-lgpio, which I'll come onto shortly) running, please try again (or upgrade your venv to the current lgpio wheel versions) and hopefully things should go smoother this time. And sorry it's taken me so long to get around to this!
See section above.
Yes, rpi-lgpio is intended as a drop-in replacement for RPi.GPIO in the new kernel-based /dev/gpiochip world. If you're desperate to read more of my rambling there's yet another blog post that introduces that one, but for most users I would urge them to read the differences chapter in the documentation prior to usage.
There will be some differences that I simply cannot paper over (like the aforementioned multiple-processes accessing one GPIO problem), and others that it's probably not worth papering over (see the Debounce section) because doing so would cause even more grief. The chapter should hopefully set your expectations for what's going to work and what's not.
Trilife commentedon Apr 10, 2024
TimW55 commentedon Apr 10, 2024
@Trilife, perhaps you have missed an important lesson. AI is not always factually correct. In deed the more I use it, and I use it a lot in my VS Code environment, the less I rely on its responses. Nevertheless AI, and ChatGPT in particular, has improved my productivity and the quality of my coding considerably.
My apologies for veering slightly off topic.
Trilife commentedon Apr 10, 2024
DimuthuDKA commentedon Apr 24, 2024
I am using RPI 4B with Bullseye. I was able to fix this by rolling back the firmware update [rpi-update] to the stable version.
sudo apt-get update; sudo apt-get install --reinstall raspberrypi-bootloader raspberrypi-kernel
After that update the software and reboot
sudo apt-get update
sudo apt-get upgrade
lurch commentedon Apr 24, 2024
@DimuthuDKA
rpi-updateis a use-it-at-your-own-risk thing, and not something that we'd recommend most users to run https://www.raspberrypi.com/documentation/computers/os.html#rpi-updateEspecially if you're still using Bullseye, which is now our Legacy OS!
Beiri22 commentedon May 13, 2024
Hi, i am using this function from pyscript. (https://hacs-pyscript.readthedocs.io/en/latest/) I tried to change the requirements.txt to use rpi-lgpio but got the error from above
As far as I know I cannot simply create a venv within pyscript, so how can I use lgpio?
waveform80 commentedon May 14, 2024
@Beiri22 What version of Python are you using, and what OS are you on (I'm guessing HAOS but I've no idea what version of Python is currently on there)? I've uploaded wheels for armhf, arm64, amd64 on Python versions 3.9 through 3.12, so if your environment matches that it shouldn't be attempting to compile the wheel from source.
Use correct offset for gpiochip0 on flat
use correct offset for GPIO0
Added better handling of issues with the GPIO subsystem in rq_hat.py,
Updated rq_hat.py and updater.py to use modern GPIO control (#122)