Forum

Full Version: [Tut] How to turn off Backlight of a Waveshare 7" HDMI LCD using GPIO and screensaver
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello partypeople,

i wanna show you how to easily turn off your Waveshares Backlight by using Kodis screensaver function and bring it back on with the power of a touch/key Wink
You can also use this to just "dim" the backlight.

Waveshares are cheap, so they are missing some crucial functions like "standby" mode. Luckily, they have a Backligt On / Off switch that is going to be very useful for us.

We need:
  • Raspi running recent Xbian
  • LCD that allows us to easily control its backlight circuit
  • A relais or similar circuit we can trigger using GPIOs
  • Basic knowledge of using a text editor / ssh
  • Basic knowledge of soldering and electronics

Installation:

1. Running Xbian on Raspi, with working LCD and maybe touch input

2. We need Software! pip will help us to install RPi.GPIO library

Terminal
kodi stop
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install python-dev gcc python-pip
sudo pip install RPi.GPIO

3. We have to add this group to grant python access to the GPIO pins, as Kodi addons have no root privileges. Than, add user Xbian to the group gpio.

Terminal
sudo addgroup gpio
sudo adduser xbian gpio

4. In order to turn on the display during boot, we need to create a script.

Terminal
nano /home/xbian/TurnDisplayOn.py

and paste following lines:

Code:
import RPi.GPIO as GPIO

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(07, GPIO.OUT)

GPIO.output(07, GPIO.LOW)

5. We have to update the GPIOs device ownership during boot, because the system will reset it on startup. We need to call our TurnOnDisplay.py script as well.

Terminal
sudo nano /etc/rc.local

Paste these three lines BEFORE exit 0

Code:
chown root.gpio /dev/gpiomem
chmod g+rw /dev/gpiomem
python /home/xbian/TurnDisplayOn.py

6. Now we need to install the screensaver addon that will help us to do the trick. In Kodi go to:
System > Add-Ons> Kodi Add-on repository > Look and feel > Screensaver > I used "Unary Clock Screensaver"

7. Back in terminal, we need to place our GPIO code within the add-on. If you are using another screensaver, the correct places will vary.

Terminal
nano ~/.kodi/addons/screensaver.unaryclock/resources/lib/gui.py

Add this line right after the other imports

Code:
import RPi.GPIO as GPIO

Scroll down and search for self.log("Screensaver starting") . Add these three lines after it and make sure to maintain the indentation:

Code:
GPIO.setmode(GPIO.BOARD)
GPIO.setup(07, GPIO.OUT)
GPIO.output(07, GPIO.HIGH)

Scroll down and look for self.log('Exit requested') and place this line under it:

Code:
GPIO.output(07, GPIO.LOW)

Save and exit the file.

8. The file we just edited is the actual screensaver script Kodi calls.. In order to be able to control the GPIOs without being root, we have to add it to the GPIOs group.

Terminal
sudo chown xbian:gpio ~/.kodi/addons/screensaver.unaryclock/resources/lib/gui.py

9. Back in Kodi go to:
System > Apperance > Screensaver > Screensaver Mode > Choose "Unary Clock Screensaver" > Set the desired time

10. Shutdown your Rasperry Pi

11. Connect the control circuit to the raspberry. In my case, i'm using a Saintsmart 2 Relais Module.
In our code, Pin 7 (GPIO 4) will control the relais. I connected mine like this:

Relais > Raspi
VCC > 5V PWR
GND > GND
IN1 > Pin 7 (GPIO 4)



12. Let's solder two wires to the Waveshares Backlight Switch...



13. and connect it to the relais.


Click here for a bigger picture

14. Fire up your raspi and wait for the screensaver to kick in... Wink
Notice: When you boot up, it can take up to 20 seconds before the backlight turns on.

Hope it works out for you Smile
Feel free to comment and improve the tutorial.





[Some thoughts]

Poti for Display dimming
You can add a poti or resistor to dimm your display. Be aware: The poti WILL turn warm/hot. This is not a very efficient way. Consider using a poti with a transistor or whatever you feel comfy with. The "hot" poti works for me. The potis value should be 200 or 500 Ohm. The 50k poti in the picture was the last one i had and works.... quite fragile Big Grin So value above represents max brightness to mostly off. A 100 Ohm one might work as wll.

Well done Wink
Great work and thank you for share and this tutorial post here
That is a nice way to interface with the switch.

I don't think undervolting the display is the right way to go about dimming it but I don't know of another way.
As far as I can tell, the display control circuit is not affected by the backlight switch. The touchscreen keeps definitely working, even with switched off backlight and there is no kind of "resync " process when turned on. However, its true that the backlight leads react sensitive to very low voltage as it might happen, that it doesn't turn on at all if you dim it till the point it turns off by itself. Meanwhile I replaced the relay with a transistor for smoother dimming. It works really good as long I don't dim too much. Though, it is possible to drive it at very low brightness. As I said , the downside is, that it won't tuRn on again until you give it more power. I suspect there is another transistor in the backlight circuit that needs a specific voltage to kick in.

The more i think about it, you might be right. Probably, even though its claiming "Backlight" on the PCB, the switch controls the whole display electronics excluding the touchscreen, which would be a much more reasonable explanation to the "doesnt turn on anymore" than the transistor theory i had before. I just checked the LCD with a bright flashlight and there is absolutely no image displayed, if the backlight is turned of. Interesting, that the electronics are able to be undervolted that far and still continue working. I think i will try to find the actual leads that are responsible for the backlight leds. Thanks for the hint.
(8th Feb, 2017 08:25 AM)f1vefour Wrote: [ -> ]That is a nice way to interface with the switch.

I don't think undervolting the display is the right way to go about dimming it but I don't know of another way.

Well, you sort of can fake it by doing it programmatically. When the command comes, put a black rectangle on the top of the screen and gradually change the opacity, making it all the way from transparent to fully black. Only after that is done, make the relay do its job.
Thank you for good communication.
192.168.l.0
So I found your thread via a google search and after much research and a little bit of soldering I figured out how to properly adjust the backlight for this screen. I created an account just to post a reply.

After a bunch of research and translating various hardware supplier websites I couldn't find a pinout for the 50-pin connector on the LCD screen itself (HJY1088 printed in the bottom left). I stumbled upon a pinout for a different 50-pin LCD and thought maybe the wiring would be the same. It listed pins 1-2 as LCD anode and 3-4 as LCD cathode. Looking at the connector on the waveshare 7" you can actually see those are wired together and run up to a group of components in the top right of the board.

With a magnifying glass I read the IC in the corner to be a "4103" which led me to this pdf http://www.micro-bridge.com/data/CRpowtech/PT4103E.pdf. Pin #4 of said IC is the EN pin which is a signal pin for the IC to control the output. There is a 10k ohm resistor sitting between the power and that pin for the board. BUT.... page 6 of the pdf says you can control the dimming using a PWM signal.

The following picture shows the area in question:



The yellow trace is pin 1-2, orange is 3-4, red is power (connects to a run on the other side of the pcb), the green oval is the 10k ohm resistor and the purple square is the 4103 IC. The pin #1 of the IC is in the bottom left, so the EN pin is top right. Pin #4 connects to the resistor on the other side of the pcb.

So I carefully removed that resistor, scrapped some of the solder mask off nearby to expose the ground plane, soldered a wire to the EN pin and hooked it up to the a PWM pin of the rpi3. It worked first try using the gpio command from the wiringpi package (https://projects.drogon.net/raspberry-pi/wiringpi/download-and-install/).

Here is a picture of the soldering job:



I connected the ground to GPIO pin #6 and then the EN pin to GPIO #12 (BCM 18) then I can issue commands like this:

Code:
# gpio -g mode 18 pwm
# gpio -g pwm 18 1000

1024 is the default brightness, 945 is the cutoff when the screen turns off. My guess is that with a proper resistor between the two devices I could get it so 0 turns off the screen and 1024 is full brightness but this is good enough for me. I am content with controlling the brightness entirely in software.

I hope someone else finds my post useful and thanks for the inspiration to do this myself.
Very well written information. Keep up the good work. Thanks.
(Link removed)
nice tut
To get the screen to display Volumio GUI you need to install the plug-in. If the screen is on but the touch function is not.
removed
I found this post and have made a few improvements/modifications

The version of the Waveshare 7" I have had a capacitor to ground just below the removed resistor (see attached photo) connected to the Enable pin of the the LED controller, I removed this as well to get a proper PWM signal to the enable pin, otherwise it becomes a triangle wave. Also, if you're using a raspberry pi, you don't need to add another ground, the panel is already grounded through the USB and HDMI cables.



Also, I used pigpio instead of wiring pi, gpioHardwarePWM(18, 1000, 1000000) means to use BCM pin 18 (pin 12 on the PI), at 1000Hz (from the 4103 manual), and 1000000 is 100% duty factor, and 500000 would be a 50% duty factor.

The attached code cycles back and forth between 100% on and 50% on, I was using it to test power consumption changes.

Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>

#include <pigpio.h>


int main(int argc, char *argv[])
{

    if (gpioInitialise()<0) return 1;

    for (int h = 0; h<30; h++){
        printf("%d",gpioHardwarePWM(18, 1000, 1000000));
        printf("\n%d\n",1000000);
        gpioDelay(5000000);
        printf("%d",gpioHardwarePWM(18, 1000, 500000));
        printf("\n%d\n",500000);
        gpioDelay(5000000);
    }
    gpioTerminate();
}
(10th Oct, 2018 11:02 PM)newto Wrote: [ -> ]I found this post and have made a few improvements/modifications

Nice work newto - kudos to you for taking your time to post it for all as well.

Thanks!
(11th Oct, 2018 05:41 PM)Skywatch Wrote: [ -> ]
(10th Oct, 2018 11:02 PM)newto Wrote: [ -> ]I found this post and have made a few improvements/modifications

Nice work newto - kudos to you for taking your time to post it for all as well.

Thanks!

+1 Smile
I am sorry for posting this here. But it was the only thread i could find about moding a waveshare screen. I also have a waveshare screen, but not the 7" but the 13.3" with case.
I am looking for a same solution which is made here, but than for the 13.3" screen.
Unfortunally for me waveshare doesn't added the modification on his website, which the did for the other non case screens (https://www.waveshare.com/wiki/File:PWM_control_backlight_manual.pdf).

On the other boards the LED driver is located. But my board is different and i don't know where to start where the LED driver is located. I know a few things of electronics, but need help from the experiance guys. Is there somebody wo can help me?

This is the top side of my board


When i flip it, there are the buttons to control the menu and the soldering for setting the voltage for the board
Hi, I have just registered as I was looking for switching of my backlight as well. Obviously my Display has a new revision (3.1) so the PCB looks a bit different. Maybe you can help me to identify the pin to which I need to solder the cable and the capacitor which should be removed. There are two. The resistor I can see.
From what I see I think it should be the left pin and the left capacitor beside the resistor. Is that correct.
Is it also correct that I just need to solder that 1 cable and gnd is coming over HDMI?

thx F.



Pages: 1 2
Reference URL's