Auto-Dimming for the Raspberry-Pi 7" Touchscreen LCD Display
Code and schematic diagram to automatically dim the backlight of the Raspberry-Pi Official 7" Touchscreen LCD display. Based on this light-sensor example from GPIO Zero.
- I don't want to be blinded by the bright LCD backlight at night
- Provide dynamic display brightness adjustment for optimal display contrast in all lighting conditions
On my nightstand, but you can see how it works at this demo link
- v0.1 - Initial release
Parts needed:
- Cds photo cell / photoresistor (photo transistor OK)
- 10µF 16V capacitor (if using 1µF, edit
charge_time_limit
argument inautobrightness.py
so that thecharge_time_limit=0.01
) - Female jumper wires
sudo nano /etc/udev/rules.d/backlight-permissions.rules
Insert:
SUBSYSTEM=="backlight",RUN+="/bin/chmod 666 /sys/class/backlight/%k/brightness /sys/class/backlight/%k/bl_power"
git clone https://github.com/dandydanny/PiAutoDim.git
In /etc/systemd/system/
, make a autobrightness.service
file.
touch autobrightness.service
Open this file in an editor:
sudo nano autobrightness.service
Put in following:
[Unit]
Description=Get auto brightness service running at boot
After=mosquitto.service mysql.service
[Service]
ExecStart=/usr/bin/python3 /home/pi/PiAutoDim/autobrightness.py
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=autobrightness
User=pi
Group=pi
[Install]
WantedBy=multi-user.target
Press CTRL-O
to save, and CTRL-X
to exit nano editor.
Enable service to run on startup:
sudo systemctl enable autobrightness.service
Start autobrightness service (for current boot):
sudo systemctl start autobrightness.service
Check if it's running:
systemctl status autobrightness.service
Adjust the amount of light falling on the Cds sensor. The backlight level should change accordingly.
MIT
Daniel is a web developer seeking opportunities, beverage socials, and late-night taco runs. dandydanny.github.io