Backlight Control

The backlight of the 2.8" PiTFT has 4 LEDs in series and it draws ~75mA at all times, controlled by a transistor. The PiTFT 3.5" display has 6 LEDs in a row, and we use a boost converter to get the 5V from the Pi up to the ~20V needed to light up all the LEDs.

There might be times you'd like to save some power and turn off the backlight. The screen and touchplate will still work, you just can't see anything. We designed the board with the STMPE610 touchscreen controller which has 2 extra GPIO and tied one of them to control the backlight. You can use the command line to control the backlight.

By default, the backlight's on...but you can control it in two ways!

PWM Backlight Control with GPIO 18

If you want precise control, you can use the PWM output on GPIO 18. There's python code for controlling the PWM but you can also just use the kernel module and shell commands.

You'll need to make sure the STMPE control is not 'active' as the STMPE GPIO overrides the PWM output.

sudo sh -c 'echo "1" > /sys/class/backlight/soc\:backlight/brightness'

(Or if you are running an old kernel before the backlight object, try sudo sh -c "echo 'in' > /sys/class/gpio/gpio508/direction")

OK now you can set the GPIO #18 pin to PWM mode using WiringPi's gpio command

With these basic shell commands, you can set the GPIO #18 pin to PWM mode with 1000 Hz frequency, set the output to 100 (out of 1023, so dim!), set the output to 1023 (out of 1023, nearly all the way on) and 0 (off)

gpio -g mode 18 pwm
gpio pwmc 1000
gpio -g pwm 18 100
gpio -g pwm 18 1023
gpio -g pwm 18 0

If you'd like to not have #18 control the backlight, simply cut the solder jumper, the tiny trace between the two large gold pads marked Lite #18

On / Off Using STMPE GPIO

Another option is to just turn it on and off using the extra GPIO created by the touchscreen driver

Thanks to the raspberry Pi overlay system, this GPIO is already set up for you in a file called /sys/class/backlight/soc:backlight/brightness

To turn the backlight off run

sudo sh -c 'echo "0" > /sys/class/backlight/soc\:backlight/brightness'

To turn it back on, run

sudo sh -c 'echo "1" > /sys/class/backlight/soc\:backlight/brightness'

For older versions of PiTFT Kernel

On older versions of the PiTFT kernel/overlay, the GPIO was not tied to the backlight device. Start by getting access to the GPIO by making a device link

sudo sh -c "echo 508 > /sys/class/gpio/export"
ls -l /sys/class/gpio

For some really old versions, the GPIO pin was #252 not #508 so substitute that if you're running something from 2014 or earlier

Once you verify that you see GPIO #508, then you can set it to an output, this will turn off the display since it will output 0 by default

sudo sh -c "echo 'out' > /sys/class/gpio/gpio508/direction"

Then turn the display back on with

sudo sh -c "echo '1' > /sys/class/gpio/gpio508/value"

or back off

sudo sh -c "echo '0' > /sys/class/gpio/gpio508/value"
Last updated on 2016-10-19 at 01.19.46 AM Published on 2013-11-29 at 02.19.02 PM