Hello, Have you already solved this issue? I am with the same idea, I have the PIR, a 3.3V relay and a python script so that, when it detects presence, the relay is activated and makes contact on the button to turn the screen on or off.
The sript I’m using is this:
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN)
GPIO.setup(25, GPIO.OUT)
GPIO.setwarnings(False)
while True:
if GPIO.input(22):
GPIO.output(25, GPIO.HIGH)
else:
GPIO.output(25, GPIO.LOW)
PIR output is connected on pin 22 (BCM). Relay input is connected on pin 25 (BCM).
This simple script works correctly, but I want to go one step further. With this crypt, the screen is turned on or off when detecting presence.
My idea is that (when the screen is off), when detecting presence, the screen will turn on for a while (for example 5 minutes), and then turn off again.
For that purpose, I made this modification on the original script:
import RPi.GPIO as GPIO
import time
import commands
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN)
GPIO.setup(25, GPIO.OUT)
GPIO.setwarnings(False)
while True:
if GPIO.input(22):
GPIO.output(25, GPIO.HIGH)
commands.getoutput('vcgencmd display_power 1')
time.sleep (300)
commands.getoutput('vcgencmd display_power 0')
else:
GPIO.output(25, GPIO.LOW)
But this modification doesn’t work. Could someone help me with this? My knowledge in python is very elementary