0

Clear PiTFT when Pi halted
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Clear PiTFT when Pi halted

by CHFlanker on Tue Jan 31, 2017 10:59 am

Hi,

I've mounted a 3.5" PiTFT 480x320 to my Raspberry Pi 3 runnin Raspbian Jessie.
After using the easy install it works great.

The only thing that bothers me is that the screen isn't cleared when i shutdown the Raspberry. So it just shows the last Image before exiting x which is usually the clicked shutdown button.

Is there a way to clear the screen when the pi is haltetd?

CHFlanker
 
Posts: 2
Joined: Tue Jan 31, 2017 10:52 am

Re: Clear PiTFT when Pi halted

by adafruit2 on Wed Feb 01, 2017 1:03 pm

we don't have a guide or tutorial. the only way we can think of doing it is adding a 'shutdown script' like here
https://www.raspberrypi.org/forums/view ... 63&t=56118
and right when shutting down, turning off the backlight (see the pitft tutorial for how to turn off the backlight on your model!)
let us know if that works!

adafruit2
Site Admin
 
Posts: 18661
Joined: Fri Mar 11, 2005 7:36 pm

Re: Clear PiTFT when Pi halted

by CHFlanker on Thu Feb 02, 2017 4:49 pm

Thank you for your suggestions! Unfortunately I'm a beginner at programming so the method described in the links are a little too much for me. ;-)

Anyway, what i did is write a little bash script basically including the code in the tutorial.
Code: Select all | TOGGLE FULL SIZE
sudo sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'
gpio -g mode 18 pwm
gpio pwmc 1000
gpio -g pwm 18 1023

Then i made my raspi to execute it at startup so the screen is lit but controlled by wiring pi.

Since the GPIOs are terminated when the pi is haltet i have what i wanted :-)

Thank you again for leading me to the right direction!

CHFlanker
 
Posts: 2
Joined: Tue Jan 31, 2017 10:52 am

Re: Clear PiTFT when Pi halted

by phrazelle on Sat Aug 24, 2019 10:59 pm

Sorry to necro a thread, but I just went through this and have a solution that might work for others and didn't see it anywhere else here.

As referenced in this thread and the documentation, this code is the way to turn the backlight off
Code: Select all | TOGGLE FULL SIZE
sudo sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'

My approach was to make a script that would run at shutdown. Shutdown scripts are handled at /lib/systemd/system-shutdown/, so the steps here are (1) make a script that turns the TFT backlight off, (2) put that script in the system-shutdown folder.

Make the script by doing the following:
Code: Select all | TOGGLE FULL SIZE
sudo nano /lib/systemd/system-shutdown/blanktft.sh

Paste in the following code:
Code: Select all | TOGGLE FULL SIZE
#!/bin/bash
mount -oremount,rw /
sudo sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'
mount -oremount,ro /

The "mount -oremount" is for loading and unloading the filesystem. I wasn't having luck getting the script to execute without it, and I believe that's because necessary elements of the filesystem are already off when this script loads.

Save that file, then make it executable by:
Code: Select all | TOGGLE FULL SIZE
chmod +x /lib/systemd/system-shutdown/blanktft.sh

Boom. That's it!

You can test it by running the script as so:
Code: Select all | TOGGLE FULL SIZE
sudo /lib/systemd/system-shutdown/blanktft.sh

You should see the TFT turn off.

Turn it back on with:
Code: Select all | TOGGLE FULL SIZE
sudo sh -c 'echo "1" > /sys/class/backlight/soc\:backlight/brightness'

Reboot or shutdown to see it in action!

phrazelle
 
Posts: 31
Joined: Mon Jan 26, 2015 11:39 pm

Please be positive and constructive with your questions and comments.