Search This Blog

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!

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 outgpio -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:

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:

screen_off.sh:#!/bin/shgpio -g mode 18 outgpio -g write 18 1

screen_on.sh:#!/bin/shgpio -g mode 18 outgpio -g write 18 0

Make those scripts executable:

chmod +x screen_on.sh screen_off.sh

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

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 (http://www.infineon.com/dgdl/irlz44npbf.pdf?fileId=5546d462533600a40153567217c32725)

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?

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!

Post a Comment

Popular Posts

Installing newer gcc/g++ versions is easy: sudo apt-get install gcc-4.7 g++-4.7
If your system does not provide the new versions, you might still be able to get them via a different repository. Add the toolchain repository to your system and update your sources:sudo add-apt-repository ppa:ubuntu-toolchain-r/testsudo apt-get update
Now you should be able to install gcc/g++. The real problem comes after that. How to make use of the newer versions?

Option #1 - Uninstall older versions
This is sometimes not an option, because lots of dependencies will be uninstalled which you might need, or you want to keep those versions around for compiling stuff that still uses them.

Option #2 - Use update-alternatives to switch versionsThis informative post describes it pretty well. I'll sum it up here. First remove all update-alternatives:sudo update-alternatives --remove-all gccsudo update-alternatives --remove-all g++
Now add update-alternatives for 4.6 and 4.7 and make the g++ configuration a s…

Wow. This was a royal pita. I wanted to build this wake-up-light-alarm-clock-media-thingy for my girlfriend. Well, I got my hands on a RPi Zero and needed an LCD display. I found this nice-looking "WaveShare 4" IPS display" on Ebay and spent days trying to get it to work properly. You want a hint? DONT DO IT! BUY A HDMI SCREEN! Refresh rate sucks, Kodi is not working with hardware-acceleration, Framebuffer copying never worked. Short: It sucked!

So. Next chapter: Bought a 5" HDMI screen here. It has an HDMI input and connects to the RPi GPIO pins for power and touch functionality... and works ALMOST out of the box on a fresh Raspbian install (from 5/2016). Nice!

Sometimes you are in the need to read back the OpenGL backbuffer, or other framebuffers. In my case the question was how to read back a downsampled framebuffer resp. its texture to system memory. There are different methods for this and I wrote a small benchmark to test them on various systems.

UPDATE #1: A thing I've totally overlooked is that you can actually blit the backbuffer to the downsampled framebuffer directly, saving you the FBO overhead (memory, setup, rendering time). I've updated the page and the code reflecting that.UPDATE #2: The code now works on Windows and Linux (via GLX). Maybe I'll port it to GLES2 for the Raspberry Pi too... :)UPDATE #3: The code works on the Raspberry Pi now using OpenGL ES 2.0. Reading the framebuffer is quite slow though even with an overclocked device. It's not the actual reading that is slow, but that we have to render to another framebuffer first and back to the screen. Atm all buffers and textures use RGBA8888, which might s…