I have a raspberry pi model B rev 2, with the Adafruit PiTFT 2.8" w/ touchscreen. I'm running the standard raspbian install, after following the instructions on this page.

What I want to do is set up the pi such that when the console blanks from inactivity (the blanking that's inactivity time is set with setterm -blank VALUE) it also disables the backlight of the PiTFT as described here, and when the console awakes due to kbd/mouse input the backlight is re-enabled.

I would also like a way to make a touchscreen press a method apart from kbd/mouse that will trigger the wake up, or if not that then a physical GPIO button.

1 Answer 1


Gathering from the code on github you could edit the drivers/tty/vt/vt.c file. The function you are concerned with is the one that contains the boolean blank_timer_expired. enter image description here

To turn the backlight off through software you could follow this tutorial by adding sudo sh -c "echo 'out' > /sys/class/gpio/gpio508/direction"(see tutorial for full setup). This would be put in the if clause above right after do_blank_screen(0). This would make the screen turn off at the same time that it blanks out. To turn it back on you would put the line sudo sh -c "echo '1' > /sys/class/gpio/gpio508/value" in the function above in the file right after unblank_screen();.

enter image description here

This would ensure that whatever triggers the screen to turn back on from blanking, will also turn the backlight on and whatever triggers the screen to blank will also trigger backlight to turn off. I believe this would include touching the screen.

  • As I understand, I need to recompile the kernel to implement this solution: where can I find the sources the patches for running the PiTFT itself? Or do I need to recompile and then apply patches afterwards. I've had a look in apt.adafruit.com, and couldn't figure it out.
    – crh23
    Commented May 16, 2015 at 20:28
  • Yea...thats a problem, Im not sure but Ill look around and get back to you with my results.
    – NULL
    Commented May 16, 2015 at 22:50
  • On second thought, tell me if I am missing something - couldn't you just copy the "drivers/tty/vt/vt.c" file put it on another computer with a gcc compiler and edit it the file as shown above and recompile it. Then just put it back in your pi, delete the old file and reboot it. Obviously, you would not be able to have the touchscreen but would attach a monitor via HDMI or SSH into the pi.
    – NULL
    Commented May 16, 2015 at 23:04
  • @EinsteinJr.You should never ask a user to check mark an answer - it can seem like bullying. If the answer is a good one it will rise on its own. Commented May 18, 2015 at 12:26
  • Ok...understood.
    – NULL
    Commented May 18, 2015 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.