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

Access to GPIO fails with all versions of RaspiOS starting from 2024-10-28 on Raspberry Pi 5 #2366

Open
ciacco85 opened this issue Nov 27, 2024 · 1 comment
Labels
bug Something isn't working untriaged

Comments

@ciacco85
Copy link

Describe the bug

It was ok with previous versions of RaspiOS until 2024-07-04.
The code runs in a container under IotHub module.

Steps to reproduce
First of all, I've solved with a workaround using this code that isn't production ready

#pragma warning disable SDGPIO0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
        gpioController = new GpioController(PinNumberingScheme.Logical, new LibGpiodDriver(0, LibGpiodDriverVersion.V1));
#pragma warning restore SDGPIO0001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
    }

and with the following Dockerfile (I'm sure I can remove some packages)

RUN apt-get update \
    && apt-get install -y sudo libgpiod2 gpiod libgpiod-dev libpigpiod-if-dev libpigpiod-if1 libpigpiod-if2-1

Full very simple code at my repo gpio-tester
Previous attempts as suggested in #2361

  • 1 Create a simple Console App and run outside the container -> OK
  • 2 Containerized the app, but using the old approach that has worked fine in the last year -> KO
        gpioController = new GpioController();

and with the following Dockerfile

RUN apt-get update \
    && apt install -y sudo libgpiod-dev

Made a lot of attempt trying different package without success until I've found the working solution described above

Expected behavior

All should work with

        gpioController = new GpioController();

or at least this code inside your library should be modified from this

case RaspberryBoardInfo.Model.RaspberryPi5:

                // For now, for Raspberry Pi 5, we'll use the LibGpiodDriver.
                // We need to create a new driver for the Raspberry Pi 5,
                // because the Raspberry Pi 5 uses an entirely different GPIO controller (RP1)
                return new LibGpiodDriver(4);

to this

case RaspberryBoardInfo.Model.RaspberryPi5:

                // For now, for Raspberry Pi 5, we'll use the LibGpiodDriver.
                // We need to create a new driver for the Raspberry Pi 5,
                // because the Raspberry Pi 5 uses an entirely different GPIO controller (RP1)
                return new LibGpiodDriver(0, LibGpiodDriverVersion.V1);

I can make a PR, but I think this part is so crucial and you're already working on the implementation for RP1

Actual behavior
This exception is thown

11/11/2024 14:22:45 +01:00 System.IO.IOException: Unable to find a chip, error code: 2
   at System.Device.Gpio.Drivers.Libgpiod.V1.LibGpiodV1Driver..ctor(Int32 gpioChip)
   at System.Device.Gpio.Drivers.LibGpiodDriverFactory.CreateInternal(LibGpiodDriverVersion version, Int32 chipNumber)
   at System.Device.Gpio.Drivers.LibGpiodDriverFactory.CreateAutomaticallyChosenDriver(Int32 chipNumber)
   at System.Device.Gpio.Drivers.LibGpiodDriverFactory.Create(Int32 chipNumber)
   at System.Device.Gpio.Drivers.LibGpiodDriver..ctor(Int32 gpioChip)
   at System.Device.Gpio.GpioController.GetBestDriverForBoardOnLinux()
   at System.Device.Gpio.GpioController.GetBestDriverForBoard()
   at System.Device.Gpio.GpioController..ctor(PinNumberingScheme numberingScheme)
   at System.Device.Gpio.GpioController..ctor()

Versions used

Latest version 3.2.0 of System.Device.Gpio and net9

@ciacco85 ciacco85 added the bug Something isn't working label Nov 27, 2024
@ciacco85
Copy link
Author

One of the attempts I've tried is

 return new LibGpiodDriver(0, LibGpiodDriverVersion.V2);

without succes. Diggin into LibGpiodDriver contructor I've found into LibGpiodDriverFactory

private LibGpiodDriverVersion? GetAutomaticallySelectedDriverVersion()
{
    return DriverCandidates.Any() ? DriverCandidates.Max() : null;
}

that deals with _installedLibraries. Since in my working solution I've forced V1 version, may be that latest RaspiOS now install by the V2 version, the library find it but has some incompatibility with your code?

One more thingh: what about the gpioChip parameter of LibGpiodDriver contructor? Your default is 4, mine is 0 and is working!
Thank you for your amazing job with this ecosystem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working untriaged
Projects
None yet
Development

No branches or pull requests

1 participant