santa detector not working in python - Raspberry Pi Forums
i want create motion detector .i tried in scratch -in scratch create brodcast programme , not seeing gpio4 option in sensor block. try in python using command this
*************************************************************
import rpi.gpio gpio
import time
sensor = 4
gpio.setmode(gpio.bcm)
gpio.setup(sensor, gpio.in, gpio.pud_down)
previous_state = false
current_state = false
while true:
time.sleep(0.1)
previous_state = current_state
current_state = gpio.input(sensor)
if current_state != previous_state:
new_state = "high" if current_state else "low"
print("gpio pin %s %s" % (sensor, new_state))
***********************************************************
run programme . python showing this
>>>
traceback (most recent call last):
file "/home/pi/hi.py", line 7, in <module>
gpio.setup(sensor, gpio.in, gpio.pud_down)
runtimeerror: no access /dev/mem. try running root!
>>>
did do. 1 please
*************************************************************
import rpi.gpio gpio
import time
sensor = 4
gpio.setmode(gpio.bcm)
gpio.setup(sensor, gpio.in, gpio.pud_down)
previous_state = false
current_state = false
while true:
time.sleep(0.1)
previous_state = current_state
current_state = gpio.input(sensor)
if current_state != previous_state:
new_state = "high" if current_state else "low"
print("gpio pin %s %s" % (sensor, new_state))
***********************************************************
run programme . python showing this
>>>
traceback (most recent call last):
file "/home/pi/hi.py", line 7, in <module>
gpio.setup(sensor, gpio.in, gpio.pud_down)
runtimeerror: no access /dev/mem. try running root!
>>>
did do. 1 please
the message means have run script accessing gpio needs root permission.
code: select all
runtimeerror: no access /dev/mem. try running root!
code: select all
sudo python hi.py
raspberrypi
Comments
Post a Comment