I have just gotten a raspberry pi 3 model b for x-mas. In a short time I have come a long way. In a python script that I am making, I need to control two buttons (sense what one is pressed) so button.wait_for_press wont work. From my understanding, you can only wait for one gpio input at a time with this. In my research, I have found GPIO.event_detected(2) or whatever input you need. The problem is, I have to use: import 'RPI.GPIO as GPIO' at the start. However, my python cant find the module. I get this error: Traceback (most recent call last): File "/home/pi/python project/Simon.py", line 4, in import RPI.GPIO as GPIO ImportError: No module named RPI.GPIO
I have done some research and found that rpi.gpio is not installed properly. I looked up many tutorials and I have done what they said. I have done console commands and manually downloading it but python gives the same error. The weird thing is, it is supposed to come installed on raspbian and that is what I am running. My script is almost working and pretty much done. I will be so happy and so proud of myself when i finally get it working because it is amazing for my level of skill. Please help.
The first thing that I need help with is installing RPI.GPIO properly and in the right file. I have tried many things so if it doesn't work, I would appreciate knowing this fact: If I re install Raspbian, would I loose my current files and scripts. I would like to know that because it might come down to re installing Raspbian if nothing works. For if nothing works, I would like to know if you have any ideas to replace what I have below. It is not my script but it uses the same function.
from time import sleep
import RPI.GPIO as GPIO
while True:
if GPIO.event_detected(2):
print "You Pressed Button 1"
sleep(1)
if GPIO.event_detected(4):
print "You Pressed Button 2"
sleep(1)
I have an idea, would this work?:
from time import sleep
from gpiozero import button
while True:
button = Button(2)
button.when_pressed = print "you pressed button 1"
sleep(1)
button = Button(4)
button.when_pressed = print "you pressed button 1"
Thank you so much for your help and info ahead of time! -Rymazon