Page 1 of 1

Raspberry pi 7”touchscreen brightness

Posted: Mon May 21, 2018 2:26 pm
by Sdftdssetggh
Hi , someone can explain me how to set screen lightness on my raspberry touchscreen ?
I’m using a rpi 3 model b and I have installed raspbian

Re: Raspberry pi 7”touchscreen brightness

Posted: Mon May 21, 2018 5:48 pm
by DougieLawson
Assuming this is the official RPF 7" touch screen and not a V1.0 model. There's a virtual filesystem
/sys/class/backlight/rpi_backlight

In there you've got

Code: Select all

pi@Challenger:/sys/class/backlight/rpi_backlight $ ls -la
total 0
drwxr-xr-x 3 root root    0 May 19 09:17 .
drwxr-xr-x 3 root root    0 May 19 09:17 ..
-r--r--r-- 1 root root 4096 May 21 18:46 actual_brightness
-rw-r--r-- 1 root root 4096 May 21 18:46 bl_power
-rw-r--r-- 1 root root 4096 May 19 09:17 brightness
lrwxrwxrwx 1 root root    0 May 21 18:46 device -> ../../../rpi_backlight
-r--r--r-- 1 root root 4096 May 19 09:17 max_brightness
drwxr-xr-x 2 root root    0 May 21 18:45 power
lrwxrwxrwx 1 root root    0 May 19 09:17 subsystem -> ../../../../../class/backlight
-r--r--r-- 1 root root 4096 May 19 09:17 type
-rw-r--r-- 1 root root 4096 May 19 09:17 uevent
pi@Challenger:/sys/class/backlight/rpi_backlight $
A root user can write to the brightness file.
sudo sh -c 'echo "128" > /sys/class/backlight/rpi_backlight/brightness'

Values run from 0 (dark) to 255 (full brightness).

Re: Raspberry pi 7”touchscreen brightness

Posted: Mon May 21, 2018 6:22 pm
by Sdftdssetggh
I tried to set 255 but the brightness still low , but it changes When I set different values .
Yes , it is the official display

Re: Raspberry pi 7”touchscreen brightness

Posted: Sun Jul 22, 2018 3:02 am
by helioz2000
DougieLawson wrote:
Mon May 21, 2018 5:48 pm
Values run from 0 (dark) to 255 (full brightness).
I'm no guru on this subject, but ........
My lab test shows maximum brightness around 200, whereas 255 is actually slightly dimmer than 200.
This finding also corresponds with measured current consumption which is around 85mA higher at the 200 setting than the 255 setting.

Re: Raspberry pi 7”touchscreen brightness

Posted: Fri Apr 12, 2019 4:01 pm
by royleith
I've coded a little Python program that calls Linus Groh's module (he does all the good stuff like error trapping).

It requires three files as given below,

1) The python program, called brightness.py

Code: Select all

# brightness.py  Version 0.1
# Copyright (C) 2019 Roy Leith 
# This program is distributed under the terms of the GNU General Public License V3

import rpi_backlight as bl
from Tkinter import *

def maxbl ():
	maxb = bl.get_max_brightness()
	return maxb
	
def statusquo ():
	value = bl.get_actual_brightness()
	return value / ratio
	
def setb (val):
	bl.set_brightness (int(int(val) * ratio))

master = Tk()
master.title('Brightness')
master.option_add('*font', ('verdana', 10, 'bold'))
	
maxv = maxbl ()
ratio = float(maxv) / 100
maxvalue = int(maxv / ratio)
Rvalue = statusquo()

brivar = IntVar()       
brivar.set(Rvalue)
brightness = Scale(master, from_=maxvalue, to=10, orient=VERTICAL, length=200, width=10,
    tickinterval=20, variable=brivar, command= setb,)

brightness.grid(row=0, column=0, sticky='NE')

mainloop()
2) The desktop file brightness.desktop, so that it can appear as an application icon,

Code: Select all

[Desktop Entry]
Name=Brightness
Comment=Brightness Control
TryExec=python
Exec=python /home/pi/Programs/Brightness/brightness.py
Icon=/usr/share/icons/Adwaita/96x96/status/display-brightness-symbolic.symbolic.png
Terminal=false
Type=Application
Categories=GTK;Utility
3) Readme.txt to tell you how to use the files.

Code: Select all

How to add Brightness to your Raspberry Pi Official 7" touch display.
You will need to install two Python modules. 

The first is Linus Groh's rpi-backlight module released under the MIT License.

     pip install rpi_backlight

Second is tkinter,

     sudo apt-get install python3-tk

You will need to give your user permission to use the system files.
    sudo leafpad  /etc/udev/rules.d/backlight-permissions.rules

Insert the line::

    SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"

Place the files, brightness.py, brightness.desktop and this 
Readme.txt file in a folder called,
 
     /home/pi/Programs/Brightness

If you have changed your user name, then replace the name 'pi'
in the above path and in the brightness.desktop file.

Please note that the file brightness.desktop will appear as the file 
Brightness, with a 'sun' icon.

Run the File Manager with root permissions,

     sudo pcmanfm

     and copy the file brightness.desktop to the folder,

     /usr/share/raspi-ui-overrides/applications

When you open the Applications Menu you will find the Brightness icon 
in the 'Accessories' catagory. Add it to the Panel by adding an 
'Application Launcher' Panel Item and editing it to use Brightness.

Copy the code for each of the above files into Leafpad and save all three in /home/pi/Programs/Brightness using the filenames indicated, above. It is important that the files are in the correct subdirectory. If you have changed your user name, then replace the name 'pi' with your user name in the above path and in the brightness.desktop file.

Then read the Readme.txt file for instructions for adding the program to the Applications Launcher and to the panel..

Re: Raspberry pi 7”touchscreen brightness

Posted: Wed Jul 24, 2019 10:22 pm
by Istalri
Hello, thank you for your work, for a newbie like me it seems incredible. I followed all thei nstructions but when I try to change the level of brightness in the app, it close instantly. Do you know an how I can solve that problem ?

Re: Raspberry pi 7”touchscreen brightness

Posted: Sat Apr 25, 2020 7:15 pm
by p1r473
Istalri wrote:
Wed Jul 24, 2019 10:22 pm
Hello, thank you for your work, for a newbie like me it seems incredible. I followed all thei nstructions but when I try to change the level of brightness in the app, it close instantly. Do you know an how I can solve that problem ?
Your permissions are probably incorrect

BTW, this tool is useful: https://github.com/linusg/rpi-backlight