May-11-2017, 09:29 PM
Hi All!
I'm fairly new to programming, and am currently trying to build a 'magic mirror' for my partners 21st birthday present. As part of this i'm trying to incorporate a PIR sensor with a raspberry pi. My hope is that by default the screensaver (which is just a black screen) is on. When a user swipes the PIR sensor, the screensaver is turned off for 30 minutes. Once the 30 minutes is up, the screensaver comes back on again. This needs to then loop constantly. My code so far is this...
Massive thanks in advance!
I'm fairly new to programming, and am currently trying to build a 'magic mirror' for my partners 21st birthday present. As part of this i'm trying to incorporate a PIR sensor with a raspberry pi. My hope is that by default the screensaver (which is just a black screen) is on. When a user swipes the PIR sensor, the screensaver is turned off for 30 minutes. Once the 30 minutes is up, the screensaver comes back on again. This needs to then loop constantly. My code so far is this...
import os #for OS program calls import sys #For Clean sys.exit command import time #for sleep/pause import RPi.GPIO as GPIO #read the GPIO pins GPIO.setmode(GPIO.BCM) pir_pin = 11 # Sensor pin 11 for data out of the PIR sensor GPIO.setup(pir_pin, GPIO.IN) print("Motion Activated (PIR) Screen Saver") print("less than 30 seconds to leave the sensor area...") time.sleep(20) os.system("xscreensaver-command -activate") #OS command for Xscreensaver program = Activate, turns on screensaver instantly while True: # endless loop, waiting for nothing. Use Control+C to exit if GPIO.input(11): # Waits for motion signal from PIR on GPIO pin 25, then com[plete rest and exit print ("working") os.system("xscreensaver-command -deactivate") ##OS command for Xscreensaver program = Activate, turns on screensaver instantly print("PIR Screen Saver Deactivated") GPIO.cleanup() #reset GPIO GPIO.setup(pir_pin, GPIO.IN)The code successfully starts the screensaver, however, quickly stops it and returns the error....
Error:"Traceback (most recent call last):
File "/home/pi/test.py", line 17, in <module>
if GPIO.input(11): # Waits for motion signal from PIR on GPIO pin 25, then com[plete rest and exit
RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM) "
Can anyone help me to finish off this code and solve the error? Massive thanks in advance!