I'm working on a project which will use a PIR motion sensor to turn on a connected HDMI monitor when there's someone in the room, and turn it off when they leave. I'm new to Linux, but not to Python. My code so far is:
import RPi.GPIO as GPIO import time from subprocess import call GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(11, GPIO.IN) while true: i = GPIO.input(11) if i ==0: print("Screen off", i) call("vcgencmd display_power 0") time.sleep(1) elif i ==1: print("Screen on", i) call("vcgencmd display_power 1") time.sleep(30)
If I just type in
vcgencmd display_power 0 or
vcgencmd display_power 1 to a terminal, the commands work fine, but this script produces a
FileNotFoundError: [Errno 2] No such file or directory: 'vcgencmd display_power 1'
I've found questions asking how to turn the screen on and off, and all of these seem to do it from the command line, not a Python script.
How can I run the command from the Python script?