Hi
Habe ein problem mit ein skript unter Raspbmc.
Ich wollte das der Pi mit ein druck auf ein Taster runterfährt und habe folgendes gefunden.
# This script will wait for a button to be pressed and then shutdown
# the Raspberry Pi.
# The button is to be connected on header 5 between pins 6 and 8.
# http://kampis-elektroecke.de/?page_id=3740
# http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio
# https://pypi.python.org/pypi/RPi.GPIO
import RPi.GPIO as GPIO
import time
import os
# we will use the pin numbering of the SoC, so our pin numbers in the code are
# the same as the pin numbers on the gpio headers
GPIO.setmode(GPIO.BCM)
# Pin 31 (Header 5) will be input and will have his pull up resistor activated
# so we only need to connect a button to ground
GPIO.setup(11, GPIO.IN, pull_up_down = GPIO.PUD_UP)
# ISR: if our button is pressed, we will have a falling edge on pin 31
# this will trigger this interrupt:
def Int_shutdown(channel):
# shutdown our Raspberry Pi
os.system("sudo shutdown -h now")
# Now we are programming pin 31 as an interrupt input
# it will react on a falling edge and call our interrupt routine "Int_shutdown"
GPIO.add_event_detect(11, GPIO.FALLING, callback = Int_shutdown, bouncetime = 2000)
# do nothing while waiting for button to be pressed
while 1:
time.sleep(1)
Alles anzeigen
Ich habe die kommentare mal so gelassen wie es im Original ist habe nur den GPIO port 31 auf 11 geändert.
Habe es erst unter Raspbian getestet und als crontab wie folgt eingetragen
crontab -e
@reboot sudo python /pfad/shutdown.py
Es macht auch das was es soll nur leider klappt es unter Raspbmc nicht.
Zum testen habe ich folgende zeile geändert
# shutdown our Raspberry Pi
os.system("sudo shutdown -h now")
nach
# shutdown our Raspberry Pi
os.system("sudo python /pfad/zu/led.py")
Sobald ich auf den Taster drücke startet er mein skript und die LED fängt an zu blinken.
Meine Idee war jetzt mein LED skript und das Shutdown skript zu Kombinieren damit ich seh ob er was macht. Also habe ich Folgendes hinzugefügt
import os
os.system("sudo shutdown -h now")
Die LED blinkt und danach sollte der shutdown befehl kommen aber die led blink ein 2tes mal und er fährt nicht runter.
Habe den Crontab mit -r wieder gelöscht und mit putty das Skript per Hand gestartet und dann macht er was er soll er fährt mit den druck auf den taster runter bzw meine LED blinkt und dann kommt der Shutdown befehlt und er fährt runter
Der einzige fehler der mir einfällt ist das was mit den Crontab nicht stimmt.
Hoffe ihr könnt mir helfen.
MfG
Phobos