User avatar
jakeh12
Posts: 9
Joined: Wed Jul 31, 2013 7:46 pm
Location: Iowa, USA

rpi-backlight: Control over display brightness and power

Fri Apr 29, 2016 6:08 am

Hello everybody!

I just wrote a simple program that can control the brightness and power state of the official touchscreen display. I though it might come handy if you need a simple interface for controlling such stuff.

https://github.com/jakeh12/rpi-backlight

COMPLETE FUNCTIONALITY ON DISPLAY BOARDS V2.0 AND V1.1 ONLY!
DISPLAY BOARD V1.0 ONLY "on" AND "off" WORKING (need to verify)

DO NOT FORGET TO READ USEFUL INFO ON BRIGHTNESS KEYBOARD MAPPING BELOW

Make sure you have git installed:
(Raspbian)

Code: Select all

sudo apt-get install git
(Arch)

Code: Select all

sudo pacman -S git
Then download, compile, and install the program itself:

Code: Select all

git clone https://github.com/jakeh12/rpi-backlight.git
cd rpi-backlight
make
sudo make install
Also, it is very important to make sure that you have appropriate permissions to read and write into backlight and display power configuration files:

Code: Select all

sudo su -c 'echo SUBSYSTEM==\"backlight\", RUN+=\"/bin/chmod 0666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power\" > /etc/udev/rules.d/99-backlight.rules'
sudo reboot
Usage:

Code: Select all

rpi-backlight [option]

    up:     increases brightness by 10%
    down:   decreases brightness by 10%
    max:    sets brightness to 100%
    min:    sets brightness to 0%
    on:     turns the screen on
    off:    turns the screen off
You can also bind your keyboard buttons to appropriate brightness actions. Use xbindkeys https://wiki.archlinux.org/index.php/Xbindkeys to define the key binding (try typing "xbindkeys" in your terminal and hit enter to see if it is already installed, otherwise google your distro + xbindkeys if not using Arch).

Edit .xbindkeysrc in your ~/

Code: Select all

touch .xbindkeysrc
nano .xbindkeysrc
Sample usage of rpi-backlight with xbindkeys is here (.xbindkeysrc file):

Code: Select all

# Increase backlight
"rpi-backlight up" 
XF86MonBrightnessUp

# Decrease backlight
"rpi-backlight down" 
XF86MonBrightnessDown
or you can use key codes:

Code: Select all

# Increase backlight
"rpi-backlight up"
m:0x0 + c:233

# Decrease backlight
"rpi-backlight down" 
m:0x0 + c:232
Now run

Code: Select all

xbindkeys
and see if it works. If it does, add this command to your .xinitrc in ~/ to make the mapping happen every time you start your desktop environment.

Hint: You can map the brightness to any key. Find out the key code by running

Code: Select all

xbindkeys -k
and pressing the desired key.



RPi 3 and Display Board V2.0 currents (RPi 3 running Arch with LXDE, idling):
Image



Feel free to leave any comments or suggestions.


Jake
Last edited by jakeh12 on Fri May 13, 2016 12:02 am, edited 10 times in total.

texy
Forum Moderator
Forum Moderator
Posts: 5146
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: rpi-backlight: Control over display brightness and power

Fri Apr 29, 2016 6:30 am

It may be worth mentioning that this will only work with the 2nd generation control board...

Texy
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

User avatar
MaitreDede
Posts: 18
Joined: Wed Sep 16, 2015 10:55 am
Location: New Caledonia

Re: rpi-backlight: Control over display brightness and power

Mon May 09, 2016 10:51 am

How to check (with my eyes or by software) the generation board I have ?

dgordon42
Posts: 754
Joined: Tue Aug 13, 2013 6:55 pm
Location: Dublin, Ireland

Re: rpi-backlight: Control over display brightness and power

Mon May 09, 2016 1:48 pm

The version number is written on the display PCB. V1.0 has no brightness control, V1.1 has got brightness control.

I don't know how to check the board revision in software.

It's possible, from looking through jakeh12's source code posted above, that checking for the absence or existence of the file:

Code: Select all

/sys/class/backlight/rpi_backlight/brightness
could indicate whether brightness control is available, but it's also possible that this file is created by the driver, and has no effect on a V1.0 board. I don't have a V1.0 board to check this on, mine's a V1.1 :D

Hope this helps,
Dave.

W. H. Heydt
Posts: 9252
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: rpi-backlight: Control over display brightness and power

Tue May 10, 2016 1:31 am

dgordon42 wrote:The version number is written on the display PCB. V1.0 has no brightness control, V1.1 has got brightness control.
Nitpicking just a bit.... The v1.0 does have brightness control, but it only has two values (on and off), but that can be controlled with software.

User avatar
Douglas6
Posts: 4472
Joined: Sat Mar 16, 2013 5:34 am
Location: Chicago, IL

Re: rpi-backlight: Control over display brightness and power

Tue May 10, 2016 3:23 am

That seems an overly-generous interpretation of 'brightness control' . Like saying a cheap soldering iron has 'temperature control' - on and off.

User avatar
DougieLawson
Posts: 34167
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: rpi-backlight: Control over display brightness and power

Tue May 10, 2016 5:49 pm

The usage instructions are wrong. The code steps the brightness by 17 up or 17 down.

I also added a couple of displays to show the old and new values for brightness and power. Power is a bit funky because power=0 means back-light ON and power=1 means back-light OFF (because the folks from the RPF got it backwards in their kernel driver).
Note:The use of baseball bats for educational purposes is completely disallowed on this forum.

Any DMs sent on Twitter will be answered next month.

User avatar
jakeh12
Posts: 9
Joined: Wed Jul 31, 2013 7:46 pm
Location: Iowa, USA

Re: rpi-backlight: Control over display brightness and power

Thu May 12, 2016 10:49 pm

Hi guys,

sorry I am replying late, I have been very busy lately. Thank you, texy, for mentioning that it only works on 2.0 and possibly on 1.1 display board. Could somebody test if the off and on works on 1.0? (Program does not run if any of the two config files for power and brightness are missing).

When I get back home from vacation, I will change the brightness MAX, MIN, and STEP values. I have noticed that the backlight pretty much ignores values below 30 and over 180. I will make step size 15, that will correspond to 10% increment/decrement in this range.

Also, I measured some currents going throught the RPi and the display board, see the graph below (RPi 3 running LXDE, idling). I have not noticed any difference between off and 0% brightness. Current flow remained the same.
graph.png
graph.png (58.01 KiB) Viewed 8819 times
(30-180 brightness values correspond to 0%-100% actual brightness, will fix in the next version)

Thank you for your suggestions!

sen8or
Posts: 1
Joined: Wed Jun 01, 2016 12:32 pm

Re: rpi-backlight: Control over display brightness and power

Wed Jun 01, 2016 1:04 pm

Hi, can anyone tell me if the standard brightness on v 1.0 the same brightness at 100% on v1.1 or v2.0? I have v1.0 at the moment but want a brighter screen, wanting to see if it's worth upgrading to a newer display board. Thanks

User avatar
jakeh12
Posts: 9
Joined: Wed Jul 31, 2013 7:46 pm
Location: Iowa, USA

Re: rpi-backlight: Control over display brightness and power

Wed Jun 01, 2016 2:44 pm

I might have to change the program. I assumed all the versions have the same parameters brightness-wise.

marcusvanr
Posts: 11
Joined: Mon Sep 21, 2015 11:04 am

Re: rpi-backlight: Control over display brightness and power

Thu Nov 17, 2016 4:28 pm

I checked with my v1.0 Display:

-- turned screen "off" and I could not get the screen to turn back on...

-- edited: /sys/class/backlight/rpi_backlight $ nano brightness
-> found if I lower brightness to 30 the screen turns off
-> raised the brightness above 230 the screen turns on again

Conclusion, don't use the "off" feature in "rpi-backlight", as it might kill the screen and require a reboot.

But, at least you can turn screen off temporarily and revive it later by changing "brightness" (my idea here is to have a PIR sensor that wakes up and turns on the screen when someone walks near the Display).

I'm looking forward to purchasing newer Displays where I can control brightness for daytime/night use in our bedrooms (for climate and light controls).
sen8or wrote:Hi, can anyone tell me if the standard brightness on v 1.0 the same brightness at 100% on v1.1 or v2.0? I have v1.0 at the moment but want a brighter screen, wanting to see if it's worth upgrading to a newer display board. Thanks

Sinfreealex
Posts: 1
Joined: Sun Mar 20, 2016 12:24 am

Re: rpi-backlight: Control over display brightness and power

Tue Mar 28, 2017 4:29 pm

Why is this post not pinned at the top of the Foundation Display topic. There are multiple threads looking for help on this and then being redirected here.

This is the only relevant post, for this topic, on the internet. Period.

Thank you jakeh12 for this.

CyberCreator
Posts: 1
Joined: Mon Apr 03, 2017 10:06 am

Re: rpi-backlight: Control over display brightness and power

Mon Apr 03, 2017 10:27 am

Jake,

is there a way t control the screen brightness on WIndows 10 IOT core?

Regards
Cyber

User avatar
jakeh12
Posts: 9
Joined: Wed Jul 31, 2013 7:46 pm
Location: Iowa, USA

Re: rpi-backlight: Control over display brightness and power

Mon Apr 03, 2017 2:52 pm

CyberCreator wrote:Jake,

is there a way t control the screen brightness on WIndows 10 IOT core?

Regards
Cyber
Unfortunately, this solution is for Linux only. I am not familiar with Windows 10 IOT on RPi.

User avatar
DougieLawson
Posts: 34167
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: rpi-backlight: Control over display brightness and power

Mon Apr 03, 2017 5:01 pm

CyberCreator wrote:Jake,

is there a way t control the screen brightness on WIndows 10 IOT core?

Regards
Cyber
You'll have to ask the nice folks at Microsoft to add that feechur for you.
https://social.msdn.microsoft.com/forum ... WindowsIoT
Note:The use of baseball bats for educational purposes is completely disallowed on this forum.

Any DMs sent on Twitter will be answered next month.

carljohanjensen
Posts: 3
Joined: Fri Aug 05, 2016 12:51 pm

Re: rpi-backlight: Control over display brightness and power

Tue Dec 04, 2018 10:09 am

Hello,

Thanks for writing this very nice little software. :D
But I'd like to dim my display very low, and You have set a min value that is not zero.
Can You tell me how possibly to lower the min value to maybe zero ?
Or maybe reveal how You manipulate the display backlight system ?

Carl Johan

W. H. Heydt
Posts: 9252
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: rpi-backlight: Control over display brightness and power

Wed Dec 05, 2018 4:16 pm

carljohanjensen wrote:
Tue Dec 04, 2018 10:09 am
Hello,

Thanks for writing this very nice little software. :D
But I'd like to dim my display very low, and You have set a min value that is not zero.
Can You tell me how possibly to lower the min value to maybe zero ?
Or maybe reveal how You manipulate the display backlight system ?

Carl Johan
Personally...I find this method to be overkill. Here are some samples of changing the backlight from root crontab...

Code: Select all

# Evening Dim Display
00 22 * * * echo 50 > /sys/class/backlight/rpi_backlight/brightness
30 22 * * * echo 16 > /sys/class/backlight/rpi_backlight/brightness

# Normal weekday
40 05 * * 1-5 echo 250 > /sys/class/backlight/rpi_backlight/brightness
You can set any value in the range of 0 to 255.

User avatar
jakeh12
Posts: 9
Joined: Wed Jul 31, 2013 7:46 pm
Location: Iowa, USA

Re: rpi-backlight: Control over display brightness and power

Thu Dec 06, 2018 6:10 pm

carljohanjensen wrote:
Tue Dec 04, 2018 10:09 am
Hello,

Thanks for writing this very nice little software. :D
But I'd like to dim my display very low, and You have set a min value that is not zero.
Can You tell me how possibly to lower the min value to maybe zero ?
Or maybe reveal how You manipulate the display backlight system ?

Carl Johan
Hi Carl,

You can use the method highlighted above or you can change the #define on line 23 of rpi-backlight.c. When I wrote the C program a couple years ago, I noticed that the display reached minimum before it got to 0 brightness so I had to "move the minimum higher" to get a linear feel when setting the brightness. This issue might have been solved since so feel free to change the defines for MIN and MAX in the source code.

rpi-backlight.c:

Code: Select all

...
22   #define BRIGHTNESS_MAX 180
23   #define BRIGHTNESS_MIN 30
24   #define BRIGHTNESS_STEP 15
...

W. H. Heydt
Posts: 9252
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: rpi-backlight: Control over display brightness and power

Fri Dec 07, 2018 6:51 am

I can only conclude that you didn't do your brightness tests (at the low end) in a dark room. I've found a noticeable difference in reducing the level from 20 down to 16 (and I'm considering going lower). My usage is an "alarm clock" that sits next to the bed and having it just bright enough to read in the middle of the night without lighting up the room is important...at least to me.

Return to “Official Foundation Display”