1

I connected my rpi3 to a 10" touchscreen. I connected the backlight of the touchscreen to a relay which I'm controlling via the GPIO pins. This is working fine for the first couple of minutes. But after for a while (>15 minutes) there seems to go something wrong: the backlight turns on/off unexpectetly.

I have a python script running on the background with a timer. Of you touch the touchscreen, the backlight turns on. After 120 seconds of not touching the screen, the backlight turns off again. It remains off until you touch the screen again.

This is my source code:

touch.py

#!/usr/bin/env python

from threading import Timer
import os
import time
import evdev
from evdev import InputDevice,categorize,ecodes

def blank_screen():
    global backlight
    backlight = 0
    #print 'Backlight OFF (', time.ctime(), ')'
    os.system("/home/pi/scripts/gpio_off.py")

# Call blank_screen in 120 seconds
backlight = 1
timeout = 120
t = Timer(timeout,blank_screen)
t.start()

device = InputDevice('/dev/input/event0')

for event in device.read_loop():
    if (backlight == 0):
        backlight = 1
        #print 'Backlight ON'
        os.system("/home/pi/scripts/gpio_on.py")
    else:
        t.cancel()
    t = Timer(timeout,blank_screen)
    t.start()

gpio_on.py

#!/usr/bin/env python

import time
import RPi.GPIO as GPIO

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

GPIO.setup(17, GPIO.OUT)
GPIO.output(17, GPIO.HIGH)

time.sleep(0.25)

gpio_off.py

#!/usr/bin/env python

import time
import RPi.GPIO as GPIO

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

GPIO.setup(17, GPIO.OUT)
GPIO.output(17, GPIO.LOW)

time.sleep(0.25)

The script touch.py is started automatically when booting the rpi. I tried to debug it. But if it's running in the background and only failing after a while, it's difficult to find my problem. Some support would be highly appreciated.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.