I have written a small program that controls two servos: to start the recording process one servo opens a shutter (servo1), then the second one lifts a sky camera out of a housing (servo2). To stop the recording process, the described process has to be completed in the reverse direction.
My issue with code is, that if I only run open_s or close_s, it works fine, but if I run both, the second function does not run correctly (servo1 no longer closes the shutter), but there's also no error message. Any idea why this could be?
Many thanks for any hints!
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
#set up servos
GPIO.setup(12,GPIO.OUT)
servo1 = GPIO.PWM(12,50)
GPIO.setup(13,GPIO.OUT)
servo2 = GPIO.PWM(13,50)
def open_s():
#run servos
servo1.start(0)
servo2.start(0)
servo1.ChangeDutyCycle(6.1)
time.sleep(2)
servo1.stop()
servo2.ChangeDutyCycle(6.5)
time.sleep(2)
def close_s():
servo1.start(0)
servo2.start(0)
servo2.ChangeDutyCycle(5.5)
time.sleep(2)
servo2.stop()
servo1.ChangeDutyCycle(3.4)
time.sleep(2)
servo1.stop()
open_s()
close_s() #<- This function no longer runs servo1, when I run it in combination with open_s()
GPIO.cleanup()