I'm currently designing a light and sound show for a museum
(Described here: viewtopic.php?f=41&t=116208)
I'm having some trouble with my button commands.
I have several preset buttons connected to the GPIO, and the python script works well to detect button presses.
However,
It runs twice for one button press.
In addition, the shell script that it launches, also works perfectly fine when run over ssh as root,
but when launched from the python script, fails to observe the lighshowpi function (which is also a call to the lightshowpi python script.)
I'm using Raspbian 4.0.7+ on a Pi B+
My code:
I launch these scripts at reboot using cron like so:
(there's alot happening in my cron schedule, so this is just the first few lines.)
Code: Select all
#load shutdown and reboot scripts##########################
@reboot python /home/pi/shutdown.py >/dev/null 2>&1
@reboot python /home/pi/reboot.py >/dev/null 2>&1
@reboot python /home/pi/p51.py >/dev/null 2>&1
@reboot python /home/pi/40mm.py >/dev/null 2>&1
@reboot python /home/pi/display.py >/dev/null 2>&1
#load the rest#############################################
@reboot sh /home/pi/loadclock.sh
# - bugle calls ---------------------------------------------
@reboot mpg321 -g 50 /home/pi/startupchime.mp3 >/dev/null 2>&1
0 12 * * * mpg321 -g 80 /home/pi/reveille.mp3 >/dev/null 2>&1
30 15 * * * mpg321 -g 80 /home/pi/last_post.mp3 >/dev/null 2>&1
# end bugle calls --------------------------------
Yes I know it's messy, I've been experimenting and commented out alot of stuff.
Code: Select all
# Simple script for shutting down the raspberry Pi at the press of a button.
# by Inderpreet Singh
import RPi.GPIO as GPIO
import time
import os
# Use the Broadcom SOC Pin numbers
# Setup the Pin with Internal pullups enabled and PIN in reading mode.
GPIO.setmode(GPIO.BCM)
GPIO.setup(13, GPIO.IN, pull_up_down = GPIO.PUD_UP)
#GPIO.setup(18, GPIO.OUT)
#GPIO.setup(23, GPIO.OUT)
#GPIO.setup(24, GPIO.OUT)
#GPIO.setup(25, GPIO.OUT)
# Our function on what to do when the button is pressed
def Shutdown(channel):
os.system("sudo sh /home/pi/p51.sh")
sleep(5)
# os.system("mpg321 -g 50 /home/pi/p51approaching.mp3")
# os.system("sudo python /home/pi/lightshowpi/py/synchronized_lights.py --file=/home/pi/p51flyby.mp3")
# os.system("sudo python /home/pi/lightson.py")
# GPIO.output(18, True)
# GPIO.output(23, True)
# GPIO.output(24, True)
# GPIO.output(25, True)
# os.system("mpg321 -g 90 /home/pi/p51flyby.mp3")
# os.system("sudo shutdown -h now")
# os.system("reboot")
# os.system("mpg321 -g 50 /home/pi/chimeup.mp3")
# Add our function to execute when the button pressed event happens
GPIO.add_event_detect(13, GPIO.BOTH, callback = Shutdown, bouncetime = 4000)
# Now wait!
while 1:
time.sleep(1)
Code: Select all
sudo mpg321 -g 50 /home/pi/chimeup.mp3
sudo mpg321 -g 50 /home/pi/p51approaching.mp3
sudo python /home/pi/lightshowpi/py/synchronized_lights.py --file=/home/pi/p51flyby.mp3
sleep(5)