Controlling PiTFT Plus 3.5" 480x320 backlight

edited December 2018 in Tips & Tricks

I'm using PiTFT Plus 3.5" 480x320 TFT Touch (ADA2441) display which has TFT backlight pin connected to the raspberry pi.
When using a screensaver and after display goes blank, it still has the backlight on and it glows.
I have my printer in bedroom and raspberry is always on, so this glowing TFT is not good.

It can be fixed. I have following scripts and services installed that will monitor display screensaver state.
When the display is turned off it's will also turn off the backlight and opposite.

First, you have to install the display as Adafruit recommends.
Backlight control should be available in
/sys/class/backlight/soc\:backlight/brightness

Then you need 5 files
  • screen-on.sh
  • screen-off.sh
  • screen-monitor.sh
  • screen-monitor.service
  • screen-off.service

download files wget <gist_raw_file_link>
https://gist.github.com/mcmatrix/bb7ae9f72be7ac48e53c6a31966a459b/raw/299d122ec0f0871da1dc2e9c1e47cfa3a8c84326/screen-on.sh
https://gist.github.com/mcmatrix/bb7ae9f72be7ac48e53c6a31966a459b/raw/299d122ec0f0871da1dc2e9c1e47cfa3a8c84326/screen-off.sh
https://gist.github.com/mcmatrix/bb7ae9f72be7ac48e53c6a31966a459b/raw/299d122ec0f0871da1dc2e9c1e47cfa3a8c84326/screen-monitor.sh
https://gist.github.com/mcmatrix/bb7ae9f72be7ac48e53c6a31966a459b/raw/299d122ec0f0871da1dc2e9c1e47cfa3a8c84326/screen-monitor.service
https://gist.github.com/mcmatrix/bb7ae9f72be7ac48e53c6a31966a459b/raw/299d122ec0f0871da1dc2e9c1e47cfa3a8c84326/screen-off.service

copy files
screen-on.sh, screen-off.sh, screen-monitor.sh
to /usr/local/bin/

give execution permission flag for these files
chmod +x screen-on.sh
chmod +x screen-off.sh
chmod +x screen-monitor.sh

copy files 
screen-monitor.service, screen-off.service
to /lib/systemd/system

give needed permissions
sudo chmod 644 screen-monitor.service
sudo chmod 644 screen-off.service

then execute
sudo systemctl daemon-reload
sudo systemctl enable screen-off.service
sudo systemctl enable screen-monitor.service
sudo systemctl start screen-off.service
sudo systemctl start screen-monitor.service

How it works.
  • screen-monitor.sh
    This script will periodically check display status.
    If the screensaver is ON then after 10s it'll turn OFF the backlight.
    When the backlight is OFF then it will check display state on each second.
    If you touch display and screensaver goes OFF it will turn backlight ON again.
  • screen-monitor.service
    It will run the previous script as service.
  • screen-off.service
    This service will turn backlight OFF when you shut down your raspberry pi.
    By default, the backlight is always ON when booting raspberry pi.
  • screen-off.sh
    The script that will turn OFF backlight
  • screen-on.sh
    The script that will turn ON backlight

Sign In or Register to comment.