Posts: 6
Joined: Fri May 22, 2015 4:01 pm

Button press ignored after os.system

Fri May 22, 2015 5:11 pm

Hi all,

I have an odd issue. There are two buttons on my pi, one runs a command to take photos the other shuts the system down. On first run, both commands respond fine to button presses. But, if I press button 1 first, button 2 is always ignored.

Here is the trimmed code, by commenting out line 41

Code: Select all

the issue goes away:

Code: Select all

#!/usr/bin/env python

import os
import time
from time import sleep
import RPi.GPIO as GPIO 
import picamera 
import atexit
import sys
import config

button1_pin 	= 16 # pin for taking photos
button2_pin 	= 7 # pin for button to shutdown the pi

working_path 	= '/home/photobooth/working/'
final_path	 = '/home/photobooth/pics/'

GPIO.setup(button1_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # falling edge detection on button 1
GPIO.setup(button2_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP) # falling edge detection on button 2

def cleanup():
  print('Ended abruptly')

def shut_it_down(channel):  
    print "Shutting down..." 
def start_photobooth(): 
	camera = picamera.PiCamera()
	#sleep(2) #warm up camera
	print "Taking pics" 
	now = time.strftime("%Y-%m-%d-%H_%M_%S") 
	camera.capture(working_path + now + '-' + '.jpg')
	print "Photos taken"
	graphicsmagick = "gm montage -tile 2x2 -geometry +10+10 -density 300 -pointsize 30 -title '' " + working_path + now + "*.jpg " + final_path + now + ".jpg"
	os.system(graphicsmagick) #make the montage

GPIO.add_event_detect(button2_pin, GPIO.FALLING, callback=shut_it_down, bouncetime=300) 

print "Photo booth app running..." 

while True:
        GPIO.wait_for_edge(button1_pin, GPIO.FALLING)
	time.sleep(0.2) #debounce
Pins in use:
7 -> Push Button 2 -> 6
16 -> Push Button 1 -> 20

I am lost as to why it does not like the os.system command?

Return to “Troubleshooting”