|
Edited by aaapee at 2015-10-29 11:51
Hello
Trying to make my pir sensors work. How can i read gpio rising ? Connector gpio1p11 is this pin number 11.
Thanks
#!/usr/bin/python
# Import required Python libraries
import os
import sys
import time
if not os.getegid() == 0:
sys.exit('Script must be run as root')
from time import sleep
from pyA20.gpio import gpio
from pyA20.gpio import connector
from pyA20.gpio import port
#led = connector.gpio1p38 # This is the same as port.PH2
#button = connector.gpio1p17 #CHOW
PIR_PIN = connector.gpio1p11
"""Init gpio module"""
gpio.init()
"""Set directions"""
#gpio.setcfg(led, gpio.OUTPUT)
#gpio.setcfg(button, gpio.INPUT)
#gpio.pullup(button, gpio.PULLUP)
#gpio.pullup(button, gpio.PULLDOWN)
gpio.setcfg(PIR_PIN, gpio.INPUT)
# Set pin as input
#gpio.setup(button,gpio.INPUT) # Echo
def MOTION(PIR_PIN):
print "Motion Detected"
print "PIR Module Test (CTRL+C to exit)"
time.sleep(1)
print "Ready"
try:
state = gpio.input(PIR_PIN)
gpio.add_event_detect(PIR_PIN, GPIO.RISING, callback=MOTION)
while 1:
time.sleep(100)
except KeyboardInterrupt:
print "Quit"
|
|