Skip to content

Auto-Dimming for the RPi and Waveshare DSI Touchscreens

Notifications You must be signed in to change notification settings

morphias2004/PiAutoDim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PiAutoDim

image Based on the original from @dandydanny https://github.com/dandydanny

Auto dimming for the Official RPi and Waveshare DSI Touchscreens

Some minor code fixes and added a version for the Waveshare DSI displays, which work the same as the RPi screens, but the dimming logic is inverted. That is , 255-0 instead of 0-255 with 255 being the darket instead of the brightest setting.

What?

Code and schematic diagram to automatically dim the backlight of the Official RPi and Waveshare DSI Touchscreens. Based on this light-sensor example from GPIO Zero.

Why?

  1. I don't want to be blinded by the bright LCD backlight at night and don't want my kitchen lit up like Christmas
  2. Provide dynamic display brightness adjustment for optimal display contrast in all lighting conditions

Hardware Setup

Parts needed:

Connection diagram:

You can use either 3.3V pin (1 or 17) on the GPIO header, any GND (6, 9, 14, 20, 25, 30, 34 or 39) and pin 12 for the input.

The photoresistor is not polarity sensitive, so you can connect the 3.3V line to either leg. The capacitor is polarity sensitive, so the positive leg needs to be connected to the same wire as the second leg on the photoresitor and both terminate at pin 12 on the RPi. The negative leg can go to any available GND.

image

Software Setup

Install GPIO Zero

sudo pip3 install gpiozero

For Waveshare 7" DSI screens, the backlight range is inverted when compared to an official RPi screen. 255-0 instead of 0-255.

To deal with this, the logic needs to be inverted. Use the wvautobrightness.py file instead.

Copy the autobrightness.py file to ~/PiAutoDim If using the wvautobrightness.py file, rename it to autobrightness.py before copying it over.

Permissions on the brightness file are not retained between reboots, so it needs to have the permissions added at boot.

crontab -e

add the line for the RPi display

@reboot sudo chmod 766 /sys/class/backlight/rpi_backlight/brightness

or for the Waveshare display

@reboot sudo chmod 766 /sys/waveshare/rpi_backlight/brightness

and to make the script run in the background on boot, also add

@reboot python3 ~/PiAutoDim/autobrightness.py

The backlighting with adjust dynamically based on the amount of light falling on the sensor. The default update interval is 1 second.

License

MIT

About

http://www.ipind.com.au

About

Auto-Dimming for the RPi and Waveshare DSI Touchscreens

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%