davros at bellaliant.net
Sun Aug 16 21:40:01 CEST 2015
Hello, all. I am hoping some people here are familiar with the RPi.GPIO
python module for the Raspberry Pi.
Very new to Python and electronics. Not to computing in general though.
I posted for help about accepting key presses and then discovered that
wiring up buttons directly to the Pi was 1/50th as difficult as I thought
it would be so I am going a different route than keyboard emulation and
needing GUI toolkits, etc.
However, I am getting error messages with RPi.GPIO.
I have three buttons, Red, Yellow and Blue in colour, attached to the
Pi. The eventual goal is to have pressing one button result in changing
the colour of an LED lightstrip to that colour and the Pi record how long
the strip spent as each colour.
For development purposes I have the controls near me and my desktop
computer, and the Pi networked to this computer. For now I have each
button press result in a print statement. When I get this working I will
replace the print statements with the code to change colours on the LED
strip using the Blinkstick module.
This is the basic test code.
from blinkstick import blinkstick
import RPi.GPIO as GPIO
led = blinkstick.find_first()
colour = 0
timered = 0
timeyellow = 0
timeblue = 0
timestamp = time.strftime("%H:%M:%S")
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
colour = 1
print "Red Button Pressed"
while colour == 1:
timered += 1
colour = 2
print "Yellow Button Pressed"
while colour == 2:
timeyellow += 1
colour = 3
print "Blue Button Pressed"
while colour == 3:
timeblue += 1
GPIO.add_event_detect(22, GPIO.RISING, callback=red_button,
GPIO.add_event_detect(23, GPIO.RISING, callback=yellow_button,
GPIO.add_event_detect(24, GPIO.RISING, callback=blue_button,
print '\033[0;41;37mRed Team:\033[0m ', timered
print '\033[0;43;30mYellow Time:\033[0m ', timeyellow
print '\033[0;44;37mBlue Time:\033[0m ', timeblue
flog = open('flag1log.text', 'a')
flog.write(timestamp + '\n' + 'Red Team: ' + str(timered) + '\n' +
'Yellow Team: ' + str(timeyellow) + '\n' + 'Blue Team: ' + str(timeblue)
This results in the error message "RuntimeError: Conflicting edge
detection already enabled for this GPIO channel". Running GPIO.cleanup()
in the interpreter results in a message stating the GPIO pins are not
assigned and there is nothing to cleanup.
Removing line 40, the while True: line, removes the error, but the
program does not sit and wait waiting for a button press, it just runs
and ends a second later.
There are other things this script will need, but this is the core
function that I need to get working -pressing a button does what I want
and the script keeps running so I can press another button if I want. If
are familiar with the RPi.GPIO or see a more general Python mistake that
could be affecting everything know I would appreciate your help. Thanks.
More information about the Python-list