Closed pjmpessers closed 2 years ago
I don't know. Try:
from rpi_backlight import Backlight
backlight = Backlight("/sys/class/backlight/10-0045")
backlight.brightness = 50
and see if that works.
Thank you Linus.
This works great when i go into the python shell. But how can i make it work when i want to do the same with a SSH command? I want it to do the same with my home automation.
Glad to hear :)
If you mean using the rpi-backlight
command, you can simply pass the path as the first argument:
rpi-backlight --options /sys/class/...
Out of curiosity, is this plain Debian or Raspbian / Raspberry Pi OS?
With :"rpi-backlight --options /sys/class/backlight/..."
i got:
usage: rpi-backlight [-h] [--get-brightness] [-b VALUE] [--get-power] [-p VALUE] [-d DURATION] [-B {raspberry-pi,tinker-board,tinker-board-2}] [-V] [SYSFS_PATH] rpi-backlight: error: unrecognized arguments: --options
It is the Debian bullseye. I got no problem with the debian buster for my raspberry pi 4b
Sure, that was just an example - you need to provide some proper options ;)
If this was Raspbian I'd consider a built-in workaround, but for plain Debian I'm afraid the existing option of explicitly specifying a path will need to be sufficient enough.
Running Bullseye on Raspbian (upgraded from Buster- not a fresh install) I have /sys/class/backlight/rpi_backlight/max_brightness
Strange. I don't. I did a fresh install of the debian bullseye. And i can't create a /sys/class/backlight/rpi-backlight. It is saying "access denied" or something like that. And i'm not good at it, but don't know how to make a path.
Yep have the same issue with a fresh installed Raspbian Buster 64-Bit its listed under /sys/class/10-0045 i've modified the init.py on my Pi manually. Line 29: BoardType.RASPBERRY_PI: "/sys/class/backlight/rpi_backlight/", to BoardType.RASPBERRY_PI: "/sys/class/10-0045/rpi_backlight/", its located in ~/.local/lib/python3.9/site-packages/rpi_backlight. Could be that you have another Python version then you have to change the version in the link
I've got very similar issue, but I'm struggling with the last step you are suggesting. I'm running Raspbian bullseye 11 on Rpi4b and original 7" touch display. After installation, if I try to launch the GUI, I get the FileNotFoundError:
This is my sys/class directory content:
Running your solution on a command shell would lead to:
And now I'm stuck because it's not clear to me which commands are required to get the rpi-backlight folder up.
You're running that in a bash shell, but it's python code.
Now I run it on python:
but the directory didn't change:
So I'm still having the same FileNotFoundError when trying to launch rpi-backlight-gui
Why the python commands are not effective ?
rpi-backlight worked in debian buster, but not on bullseye. Installing gives this notification:
Defaulting to user installation because normal site-packages is not writeable Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting rpi-backlight Downloading https://www.piwheels.org/simple/rpi-backlight/rpi_backlight-2.4.1-py3-none-any.whl (9.8 kB) Installing collected packages: rpi-backlight Successfully installed rpi-backlight-2.4.1
After installation i gave the command:"echo 'SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"' | sudo tee -a /etc/udev/rules.d/backlight-permissions.rules" and a reboot, when i give the command backlight -b5 it is saying it doesn't excist. With rpi-backlight -b5 it is saying:"
Traceback (most recent call last): File "/home/pi/.local/bin/rpi-backlight", line 8, in
sys.exit(main())
File "/home/pi/.local/lib/python3.9/site-packages/rpi_backlight/cli.py", line 78, in main
backlight = Backlight(
File "/home/pi/.local/lib/python3.9/site-packages/rpi_backlight/init.py", line 75, in init
self._max_brightness = self._get_value("max_brightness") # 255
File "/home/pi/.local/lib/python3.9/site-packages/rpi_backlight/init.py", line 92, in _get_value
raise e
File "/home/pi/.local/lib/python3.9/site-packages/rpi_backlight/init.py", line 84, in _get_value
return int((self._backlight_sysfs_path / name).read_text())
File "/usr/lib/python3.9/pathlib.py", line 1255, in read_text
with self.open(mode='r', encoding=encoding, errors=errors) as f:
File "/usr/lib/python3.9/pathlib.py", line 1241, in open
return io.open(self, mode, buffering, encoding, errors, newline,
File "/usr/lib/python3.9/pathlib.py", line 1109, in _opener
return self._accessor.open(self, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/sys/class/backlight/rpi_backlight/max_brightness'
In /sys/class there is a directory "backlight", but no directory "rpi_backlight". Only a directory "10-0045" Has this to do with a new video-driver in the debian bullseye?
Thanks in advance.