Adding GPIO PWM backlight control to a 5" HDMI screen (and Kodi)

So the screen from here is working in Kodi now, but it draws a lot of power when the backlight is on (~200mA). We want to turn at least the backlight off, leaving the touchscreen active so we can interact and wake it up again. Buuut the LCD has no backlight control which is a pity (would have cost only cents). Good thing is: We can easily add it.

UPDATE: This only needs a wire an NO software tinkering, but for the 5" display you have to take it apart, because the IC is on the back side of the PCB. But this is the most convenient solution!

What you'll need:
  • IRF7104 P-Channel MOSFET
  • 10 kOhm resistor
The displays backlight power supply runs on 5V and already has an on/off switch. We cut the trace leading from the switch to the backlight power supply circuit:

Then solder the IRF7104 there (pin 3 (Source) right, pin 6 (Drain) left). Pin 1 of the MOSFET is the pin next to the little dent. The IRF will switch power to the backlight on and off and should handle currents of up to ~1.5A.
Now we need a circuit to connect the Gate (pin 4) of the MOSFET to the GPIO pin. I used GPIO #18 / PWM0 (pin 12) on my RPi Zero. NOTE: This pin may be connected to the audio out on other RPis, so you might need to choose a different pin...
We connect the Gate pin to a 10k Ohm resistor and connect that to our GPIO pin. The final circuit is in the image below:

Now when you start the RPi it should turn the screen on by default. You can use the commands:

gpio -g mode 18 out
gpio -g write 18 1

to turn the screen off. You need WiringPi for that, so if you don't have it, install it... To control backlight brightness by PWM you can do:

gpio -g mode pwm
gpio -g pwm 18 x (x takes values from 0 (full on), to 1023 (off))

To turn the screen back on do:

gpio -g mode 18 out
gpio -g mode 18 0

For the following instructions, use the home directory of the user you want to run Kodi from. If you make Kodi autostart by editing /etc/default/kodi, this is the user "kodi" (used here), else it is probably the user "pi".

Now to integrate support for the backlight into Kodi, we need to run those commands when the Kodi screensaver starts or ends. For that we need a service addon called "service.xbmc.callbacks". Download the script from the releases section and unzip it into /home/kodi/.kodi/addons. Then create two script files in the /home/kodi directory:
gpio -g mode 18 out
gpio -g write 18 1
gpio -g mode 18 out
gpio -g write 18 0

Make those scripts executable:

chmod +x

Now start Kodi and add those two scripts in the addon configuration for screensaver start / exit:

Your backlight should now turn off / on with the screen saver.


warwolf7 said…
would that allow the backlight to be dimmed?
If i would send
gpio -g mode pwm
gpio -g pwm 18 x
where X = 512
Bim said…
Yes. It would. Note that 1023 does not seem to give me full brightness, only using the input/tristate mode does. If you find out how that can be improved, let me know...
g00de said…
Hi shouldnt you use a p-channel mosfet? currently your drain is directly connected to 5v. currently your load is on source and should be on drain
Bim said…
Oh, yes! You're totally right! Thanks. I corrected the picture and text...
amit patel said…
Hello - I have a question or two, that I was hoping you could answer. But first, I want to apologize in advance if they doltish in any way, as I just started playing around with circuits a few weeks ago.

Do you think an IRLZ44N transistor would work? Only reason I ask, is I have a bunch laying around and won't have to wait for them. I have no idea how to read these datasheets (

Second, are you supplying power directly to the screen then to the pi? If so, this should still work if I use the usb port on my rpi2, correct?

Lastly, what is that attached to your breadboard and what is it used for?

Thank you very much. ap
Bim said…
The IRLZ44N is overkill, but should work.
Power supply via USB should work too.
The Thing on the Prototype Board is a Variable resistor, but a Fixed Value of 4.7k should be Just fine.
amit patel said…
Thank you very much. Most helpful.
Gaijin said…
Hi, I have a few TIP122 as well as a few BC547and BC557 transistors and an assortment of RU3C 1.5A/1000V, RU4A, 6A10 6A/1000V, RU4D, 10A10 10A/1000V, 1N4007 1A/1200V, 1N4004 1A/400V, 1N4002 1A/100V, 1N4001 1A/50V lying around.
I plan on making a similar hack to a 7" Waveshare TFT LCD that uses the same PT4103 White LED Step-Up Converter to your screen, but I also plan to add a rotary pot to control the PWM via an MCP3008 ADC.
Do you think I can substitute the MOSFET and your 1N4148 diode with a combination of what I have to make a similar circuit to yours? Which combination would you suggest?
Thank you in advance!
Bim said…
For switching the backlight use a(ny) logic-level FET. You can try with an NPN-Transistor, but that might not work or require more circuitry. For the diode any general purpose diode should work.
Antje Boe said…
There seems to be an another solution:
Jiří Ráž said…
Hi, sollution with KodiCallback addon has weird behavior. If you touch the screen for deactivation screensaver, it do action under touch place.

So, I modified screensaver addon for official raspberry pi display.
Now it control display backlight over GPIO 12.

There is first version: