Hallo,
erstes RPi Projekt, erste Frage ans Forum.
Ich baue ein custom-Küchenradio mit dem Pi. Ich habe auch schon alle Bausteine beisammen und es hakt nur noch an einer Stelle.
Mit diesem Python script fange Ich die Hardwareschalter ab die am GPIO hängen
Code
#!/usr/bin/env python2.7
# script by Alex Eames http://RasPi.tv/
# http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio
import RPi.GPIO as GPIO
import time
import subprocess
GPIO.setmode(GPIO.BCM)
# setting up GPIOs
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
#GPIO.wait_for_edge(17, GPIO.FALLING)
subprocess.call("whoami")
#subprocess.call(["radio","next"])
def my_callback17(channel):
print "P17 A"
def my_callback27(channel):
print "P27 hell+"
def my_callback22(channel):
print "P22 hell-"
def my_callback24(channel):
print "P24 B"
GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback17, bouncetime=1000) # add rising edge detection on a channel
GPIO.add_event_detect(27, GPIO.FALLING, callback=my_callback27, bouncetime=1000)
GPIO.add_event_detect(22, GPIO.FALLING, callback=my_callback22, bouncetime=1000)
GPIO.add_event_detect(24, GPIO.FALLING, callback=my_callback24, bouncetime=1000)
try:
print "Python interrupt script is running"
GPIO.wait_for_edge(23, GPIO.RISING)
print "Rising edge detected on port 24. Here endeth the third lesson."
except KeyboardInterrupt:
GPIO.cleanup() # clean up GPIO on CTRL+C exit
GPIO.cleanup() # clean up GPIO on normal exit
Alles anzeigen
Dieses script muß Ich als root ausführen damit Ich die GPIOs setzen kann (richtig?).
Das script für Internetradio läuft über xmms und kann NICHT als root gestartet werden. Jetzt möchte ich den
als User "Pi" ausführen. Kann mir jemand helfen? Kleine Codebeispiel vielleicht?