Thank you for your donation


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Idea: [Tut] How to turn off Backlight of a Waveshare 7" HDMI LCD using GPIO and screensaver
3rd Feb, 2017, 08:54 AM
Post: #1
Lightbulb [Tut] How to turn off Backlight of a Waveshare 7" HDMI LCD using GPIO and screensaver
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.

Find all posts by this user
Quote this message in a reply
3rd Feb, 2017, 05:23 PM (This post was last modified: 8th Feb, 2017 09:09 AM by rikardo1979.)
Post: #2
RE: [Tut] How to turn off Backlight of a Waveshare 7" HDMI LCD using GPIO and screensaver
Well done Wink
Great work and thank you for share and this tutorial post here

~~~~>>>Please always follow rules and read before you post<<<~~~~
Find all posts by this user
Quote this message in a reply
8th Feb, 2017, 08:25 AM
Post: #3
RE: [Tut] How to turn off Backlight of a Waveshare 7" HDMI LCD using GPIO and screensaver
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.

Please read rules and do a search before you post! | FAQs | How to post log file? | Can't find an answer? Contact us.
Visit this user's website Find all posts by this user
Quote this message in a reply
8th Feb, 2017, 09:02 AM
Post: #4
RE: [Tut] How to turn off Backlight of a Waveshare 7" HDMI LCD using GPIO and screensaver
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.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: