Is there a way to adjust the brightness of the official touchscreen display? I couldn't find a definite answer. I'm running the latest release of Raspbian Jessie.
The driver for the screen provides an interface through /sys/
. To turn the screen on you can use the command:
echo 0 > /sys/class/backlight/rpi_backlight/bl_power
and to turn it off:
echo 1 > /sys/class/backlight/rpi_backlight/bl_power
the brightness can be adjusted using:
echo n > /sys/class/backlight/rpi_backlight/brightness
where n
is some value between 0 and 255.
-
1Just small typo... rpi-backlight should be rpi_backlight for the brightness – Luc Eeckelaert May 25 '16 at 20:21
-
2Note that the 'brightness' setting only works on v1.1 LCD hardware. on v1.0, the control is binary, < 128 are "off", >= 128 are "on" see raspberrypi.stackexchange.com/questions/49822/… – Dave Lawrence Jun 15 '16 at 14:17
-
4If you get "Permission denied" errors, try with
sudo bash -c "echo 0 > /sys/class/backlight/rpi_backlight/bl_power"
(from raspberrypi.org/forums/viewtopic.php?p=848197#p848197) – MasterScrat Apr 6 '18 at 9:54 -
What if the folder
rpi_backlight
or the filebl_power
don't exist? It's the case with openplotter so none of this works – NaturalBornCamper Nov 1 '18 at 14:11
I've made a Python package for this: github.com/linusg/rpi-backlight. Now you don't need to implement this yourself anymore.
(GIF is outdated because API was changed quite a bit in v2, sorry... Below example is correct 🙂)
Works basically like the above, example:
>>> from rpi_backlight import Backlight
>>>
>>> backlight = Backlight()
>>> backlight.brightness
100
>>> backlight.brightness = 50
>>> backlight.brightness
50
>>>
>>> with backlight.fade(duration=1):
... backlight.brightness = 0
...
>>> backlight.fade_duration = 0.5
>>> # subsequent `backlight.brightness = x` will fade 500ms
>>>
>>> backlight.power
True
>>> backlight.power = False
>>> backlight.power
False
>>>
It has a GUI, a CLI and a simple Python API :)