I am following the physical computing with python tutorial from here: https://projects.raspberrypi.org/en/projects/physical-computing
I have created a python file that contains the following:
from gpiozero import LED, Button
from signal import pause
led = LED(17)
button = Button(2)
button.when_pressed = led.on
button.when_released = led.off
pause()
Also I have the button and led connected to the correct pins and in parallel. When I test the light and button separately directly in the command line, they work fine.
Also I get this message, but I don't know if that has anything to do with this issue:
/home/pi/local/lib/python2.7/site-packages/gpiozero/devices.py:451: PinFactoryFallback: Falling back from rpigpio: No module named RPi
'Falling back from %s: %s' % (name, str(e))))
/home/pi/local/lib/python2.7/site-packages/gpiozero/devices.py:451: PinFactoryFallback: Falling back from rpio: No module named RPIO
'Falling back from %s: %s' % (name, str(e))))
/home/pi/local/lib/python2.7/site-packages/gpiozero/devices.py:451: PinFactoryFallback: Falling back from pigpio: No module named pigpio
'Falling back from %s: %s' % (name, str(e))))
Can someone please help?
Edit1: Ok, I have uninstalled gpiozero, and am left with the default version included for python3. What I am typing now in terminal is python3 gpio_control.py
which includes the name of the file I posted. There isn't any output when I run it and it does not terminate. –
Edit2: I got this to work (light turns on when pressed and off when released) with the following code:
#! /usr/bin/env python3
from gpiozero import LED, Button
led = LED(17)
button = Button(2)
while True:
button.wait_for_press()
led.on()
button.when_released = led.off()