This is a timelapse script for moving a camera along a dolly. The problem is that when I run the code, sometimes (at iteration 7 exactly, for example) the dolly is moving and the camera snaps a photo at the same time. It's as if the commands aren't blocking before the next one gets executed. As you can see, I've tried scattering sleep's in the code to no avail.
Here is the workflow:
- Raspberry Pi sends commands to camera (snap photo) and Arduino (move dolly)
- The Arduino talks to EasyDriver Stepper Motor Driver, which talks to the stepper and causes dolly to move.
- Repeat.
Here is my Python script.
import os, commands, string, gps
from subprocess import Popen, PIPE
from time import sleep
import serial
ser = serial.Serial('/dev/ttyACM0', 9600)
sleep (5)
for i in range(0, 20):
#To write information
steps = 1000*(i+1)
ser.write('1,'+str( steps )+'/n')
sleep (4)
bashCommand = "sudo /home/mh00h/Timelapse/camerareset.sh"
os.system(bashCommand)
sleep (2)
bashCommand = "sudo gphoto2 --capture-image"
os.system(bashCommand)
sleep (1)