Raspberry Pi Legacy Tools Add-on

  • I would like to know the reasons why the RPi.GPIO library was dropped from the Raspberry Pi Tools add-on. In my opinion, this is a mistake. I'll explain. I am the author of the OLEDproc plugin. It depends on several libraries, including the luma.oled and luma.core libraries. And therein lies the trouble. The luma.core library needs the RPi.GPIO library to work. I am convinced that it is unthinkable and also pointless for me to create some clone of the luma.core library, which would use, for example, gpiozero instead of RPi.GPIO. So, as it stands, the OLEDproc add-on user could not upgrade their system to LE12, otherwise their OLED display would stop working. It occurred to me that it was possible to go another way. I tried to reincarnate the Raspberry Pi Tools add-on to include the necessary RPi.GPIO library. The result is the "new" add-on Raspberry Pi Legacy Tools.
    And it really works!
    I know there are more similarly affected add-ons (dependent on Raspberry Pi Tools/RPi.GPIO). If their users couldn't upgrade to LE12 because of this, now they can! It is really easy. You only need to do two steps:
    1. Install the Raspberry Pi Legacy Tools add-on
    2. Make a simple edit to the addon.xml file of the dependent addon. As an example, I present an excerpt from the addon.xml file that belongs to the OLEDproc add-on:
    Original version:
     <requires>
       <import addon="xbmc.python" version="3.0.0"/>
       <import addon="script.module.luma" />
       <import addon="script.module.cbor2" />
       <import addon="script.module.smbus2" />
       <import addon="script.module.spidev" />
       <import addon="virtual.rpi-tools" />
     </requires>

    Modified version:
     <requires>
       <import addon="xbmc.python" version="3.0.0"/>
       <import addon="script.module.luma" />
       <import addon="script.module.cbor2" />
       <import addon="script.module.smbus2" />
       <import addon="script.module.spidev" />
       <import addon="virtual.rpi-legacy-tools" />
     </requires>

  • First of RPi.GPIO is EOL and does not support RPi5 and has problems with recent kernels.

    For luma this is ofc a problem, as long they do not support the recent way of doing GPIO (RPi.GPIO was always more or less a massive hack rather then doing it properly). I have no idea what's needed that the standard way of dealing with gpio is gets supported there - there are open issues in that directions too.

    For reference

    rpi-tools: update addon and build for aarch64 as well by HiassofT · Pull Request #8230 · LibreELEC/LibreELEC.tv
    update gpiozero to 2.0 and switch from RPI.GPIO to the libgpiod-based lg-gpio, like RPiOS did in it's bookworm release Also drop the ancient adafruit libraries…
    github.com
    GPIO.add_event_detect no longer works with the new kernel 6.60 · Issue #6037 · raspberrypi/linux
    Describe the bug Since the update to the following kernel, the "add_event_detect" function from the RPi.GPIO library no longer works. Linux outdoor enclosurePi…
    github.com
  • First of RPi.GPIO is EOL and does not support RPi5 and has problems with recent kernels.

    Yes, I am aware of the EOL situation. But I (and surely many other users) don't have an RPi5 and for the RPi4 the RPi.GPIO library works FOR NOW...
    I just wanted to use the Raspberry Pi Legacy Tools to help myself (and perhaps other similarly affected users) give some time to the final solution.
    But okay, there's another option. It is also a workaround, but probably with a much longer perspective than the previous solution.
    The other option is rpi-lgpio.
    I tried to integrate it into Raspberry Pi Tools and it works!
    I am attaching both the finished add-on and the modified sources.

  • In less than two months, the modified add-on was downloaded more than 100 times!

    And none of the people (who downloaded the add-on) left any feedback here. This is really sad.

    I don't know if something is wrong. Please write your experience with it! Any, even negative.

    And maybe there are some positive ones?

    How would you comment on the idea that such a modified add-on would become part of the official distribution?

  • I tested the add-on on libreelec 12.0.1 and it does not work.

    In the logs I find the following errors:

    Error Type: <class 'lgpio.error'>
    Error Contents: 'GPIO not allocated'
    Traceback (most recent call last):
    File "/storage/.kodi/addons/service.oled.cm4/service.py", line 475, in <module>
    monitor = BackgroundService()
    ^^^^^^^^^^^^^^^^^^^
    File "/storage/.kodi/addons/service.oled.cm4/service.py", line 429, in __init__
    self.oled = Oled(*args)
    ^^^^^^^^^^^
    File "/storage/.kodi/addons/service.oled.cm4/service.py", line 77, in __init__
    serial = spi(gpio_DC=dc, gpio_RST=rst,device=spidevice, port=spiport)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/storage/.kodi/addons/script.module.luma/lib/luma/core/interface/serial.py", line 305, in __init__
    bitbang.__init__(self, gpio, transfer_size, reset_hold_time, reset_release_time, DC=gpio_DC, RST=gpio_RST)
    File "/storage/.kodi/addons/script.module.luma/lib/luma/core/interface/serial.py", line 193, in __init__
    self._DC = self._configure(kwargs.get("DC"))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/storage/.kodi/addons/script.module.luma/lib/luma/core/interface/serial.py", line 206, in _configure
    self._gpio.setup(pin, self._gpio.OUT)
    File "/storage/.kodi/addons/virtual.rpi-tools/lib/RPi/GPIO/__init__.py", line 704, in setup
    initial = _check(lgpio.gpio_read(_chip, gpio))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/storage/.kodi/addons/virtual.rpi-tools/lib/lgpio.py", line 903, in gpio_read
    return _u2i(_lgpio._gpio_read(handle&0xffff, gpio))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/storage/.kodi/addons/virtual.rpi-tools/lib/lgpio.py", line 458, in _u2i
    raise error(error_text(v))
    lgpio.error: 'GPIO not allocated'

  • If you have a RPi5 in use, please be aware that the gpiochip has been reordered back to gpiochip 0 with kernel version 6.6.45 and following.

    Use gpiochip0 for the user-facing GPIOs on Pi 5 by pelwell · Pull Request #6144 · raspberrypi/linux
    Pi 5 contains multiple GPIO controllers; running gpiodetect shows that there are five. Prior to this patch set, they appear like this: gpiochip0…
    github.com
    lgpio pin factory is broken on RPi5 since kernel 6.6.45 · Issue #1166 · gpiozero/gpiozero
    Operating system: e.g. RPiOS Bookworm Python version: 3.11.2 Pi model: Pi 5 GPIO Zero version: 2.0.1 Pin factory used: lgpio A recent change in the RPi kernel…
    github.com

    Maybe this is the issue for not working with 12.0.1.