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

Raspberry Pi 5 #60

Closed
jamesecc opened this issue Jan 28, 2024 · 3 comments
Closed

Raspberry Pi 5 #60

jamesecc opened this issue Jan 28, 2024 · 3 comments

Comments

@jamesecc
Copy link
Contributor

I've just installed my official raspberry pi touchscreen onto my new raspberry pi 5. I kept getting this error:

pi@rpi5:~ $ rpi-backlight -b 100
Traceback (most recent call last):
  File "/usr/local/bin/rpi-backlight", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/rpi_backlight/cli.py", line 80, in main
    backlight = Backlight(
                ^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/rpi_backlight/__init__.py", line 82, in __init__
    self._max_brightness = self._get_value("max_brightness")  # 255
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/rpi_backlight/__init__.py", line 99, in _get_value
    raise e
  File "/usr/local/lib/python3.11/dist-packages/rpi_backlight/__init__.py", line 91, in _get_value
    return int((self._backlight_sysfs_path / name).read_text())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/pathlib.py", line 1059, in read_text
    with self.open(mode='r', encoding=encoding, errors=errors) as f:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/pathlib.py", line 1045, in open
    return io.open(self, mode, buffering, encoding, errors, newline)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/backlight/rpi_backlight/max_brightness'

After some digging around a bit it looks like neither of these two folders exist on my rpi5:

/sys/class/backlight/rpi_backlight
/sys/class/backlight/10-0045

Instead, there is a folder called

/sys/class/backlight/4-0045

I was able to get it working when I changed the __init__.py files as follows:

_BACKLIGHT_SYSFS_PATHS = {
    BoardType.RASPBERRY_PI: (
        "/sys/class/backlight/4-0045/"
        if Path("/sys/class/backlight/4-0045/").exists()
        else "/sys/class/backlight/rpi_backlight/"
    ),

Whilst this worked for me, I have no idea how to implement a general solution for all pi models.

@c899173-1024
Copy link

c899173-1024 commented Mar 24, 2024

I can confirm this error on the RPI5 which has 2 display/camera ports.

Plugging into Display 1 creates 4-0045 and into Display 0 creates 6-0045 - The 10-0045 seems to be a Pi4 artifact which only has 1 display port.

My messy fix to rpi_backlight-2.6.0 init.py (Tested on Pi5 but not tested on Pi4 or Pi3 with earlier versions of Raspbian) is:

_BACKLIGHT_SYSFS_PATHS = {
BoardType.RASPBERRY_PI: (
"/sys/class/backlight/4-0045/"
if Path("/sys/class/backlight/4-0045/").exists()
else "/sys/class/backlight/6-0045/"
if Path("/sys/class/backlight/6-0045/").exists()
else "/sys/class/backlight/10-0045/"
if Path("/sys/class/backlight/10-0045/").exists()
else "/sys/class/backlight/rpi_backlight/"
),
BoardType.TINKER_BOARD: "/sys/devices/platform/ff150000.i2c/i2c-3/3-0045/",
BoardType.TINKER_BOARD_2: "/sys/devices/platform/ff3e0000.i2c/i2c-8/8-0045/",
BoardType.MICROSOFT_SURFACE_RT: "/sys/class/backlight/backlight/",
}

This library will probably not work correctly if you plug in 2 displays.

@Vizzyy
Copy link

Vizzyy commented Apr 20, 2024

Just ran into the same issue, and came to the same conclusions as the posters above.

@linusg
Copy link
Owner

linusg commented Jul 10, 2024

If anyone wants to make a PR that would be most welcome :)

There already is dynamic detection of which base directory to use, this should be simple to add.

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

No branches or pull requests

4 participants