jbutler1962
Posts: 2
Joined: Tue Jan 20, 2015 2:26 am

GPIO Event stops working after external command is executed

Tue Jan 20, 2015 2:57 am

I'm using a pi to control a stepper motor on a camera slider. I created an event to detect the carriage hitting a limit switch.

I create an event detect like GPIO.add_event_detect(7, GPIO.FALLING, callback=LimitSwitch, bouncetime=500). The event works correctly until I execute status = os.system("gphoto2 --set-config eosremoterelease=2 --wait-event=%.3fms --set-config eosremoterelease=4 >> NULL" %duration). Once I run the external CMD it appears to cancel the event.

As a workaround I tried to create and cancel the event detect in the function that spins the motor. Unfortunately it appears that if you create and cancel the event repeatedly, with not enough delay between calls, it causes an error and the python script exits.

def SpinMotor(direction, stepsCapture):
GPIO.add_event_detect(7, GPIO.FALLING, callback=LimitSwitch, bouncetime=500)
GPIO.output(18, direction)
while stepsCapture > 0:
PWM.start(1)
time.sleep(0.01)
stepsCapture -= 1
PWM.stop()
GPIO.remove_event_detect(7)
return True

Ideally I'd like to create the event one time at the beginning of the script. Any ideas what I'm doing wrong?

jbutler1962
Posts: 2
Joined: Tue Jan 20, 2015 2:26 am

Re: GPIO Event stops working after external command is execu

Wed Jan 21, 2015 1:08 pm

I was able to resolve the issue by using subprocess.call() instead of os.system

Return to “Python”