3rd Feb, 2017, 08:54 AM
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
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:
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
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.
4. In order to turn on the display during boot, we need to create a script.
and paste following lines:
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.
Paste these three lines BEFORE exit 0
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.
Add this line right after the other imports
Scroll down and search for self.log("Screensaver starting") . Add these three lines after it and make sure to maintain the indentation:
Scroll down and look for self.log('Exit requested') and place this line under it:
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.
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...
Notice: When you boot up, it can take up to 20 seconds before the backlight turns on.
Hope it works out for you
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 So value above represents max brightness to mostly off. A 100 Ohm one might work as wll.
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
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
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
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...
Notice: When you boot up, it can take up to 20 seconds before the backlight turns on.
Hope it works out for you
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 So value above represents max brightness to mostly off. A 100 Ohm one might work as wll.