So comparing V4 to V5 the camera taking function is exactly the same ( they must be because as I said V5 is just V4 with the stepping for stepper X changed ).
So I have only ever posted two versions that had the full picture tasking code in them V5 & V5, so I don't know were you got this code from
Code: Select all
def take_picture(campic):
print("Take picture", campic)
# the following line contains the path and file name that will be use to save file
filename = "/home/pi/" + str(campic) + ".jpg"
with picamera.PiCamera() as camera:
camera.resolution = (1920, 1080)
camera.start_preview()
time.sleep(2)
camera.capture(filename)
time.sleep(0.5)
camera.stop_preview()
time.sleep(0.5)
I suspect its something you put together from V3 and the camtest program I posted.
So please down load V5 again save it to a new file and use that for your project or you are going to end up in a big mess which corrupted code that will fail.
So running V5 on my pi ,
first using python 2 , so at the command line
python twostepv5.py
the code runs as far as asking you to input a file name then it crashers with this error
pi@Desktop-pi:~ $ python twostepv5.py
Program Start
please input a file name for this program run
> abc123def
Traceback (most recent call last):
File "twostepv5.py", line 107, in <module>
name = input ("> ")
File "<string>", line 1, in <module>
NameError: name 'abc123def' is not defined
exactly as I was expecting because of the way input works under python 2.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
now running exactly the same program V5 using python 3 , so at the command line
python3 twostepv5.py
the program runs as I said accepting both letters and numbers.
pi@Desktop-pi:~ $ python3 twostepv5.py
Program Start
please input a file name for this program run
> abc123def
X Moved to 0
Take picture 1
X Moved to 4096
Take picture 2
X Moved to 8192
Take picture 3
X Moved to 12288
which results in 3 jpg files being created ( I stopped the program after 3 pictures had been taken ).
So my program works exactly as required you just have to run it with the right version of python.
that being python3
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
So I have updated V5 of the program to V5.2 , this new version now has a test to check the program is being run with python 3.
So please download this version ( V5.2 ) of the code and use this from now on.
Code: Select all
#!/usr/bin/python3
# final 2 stepper version 5.2
import RPi.GPIO as GPIO
import time
import picamera
import sys
# test python version
version = sys.version.split('.')[0]
if version == "2":
print("This program must be run with python3")
print("python used aborting program ")
sys.exit()
# setup gpio
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
control_pinsX = [7,11,13,15]
control_pinsZ = [19,21,23,29]
for pin in control_pinsX:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
for pin in control_pinsZ:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
# steps lists
# Stops X
stopsX = [0,4096,8192,12288,16384,20480,24567,28672,32768]
stop_countX = 0
# Stops Z
stopsZ = [0,114,228,342,455,569,683,797,910,1024,1138,1252,1365,1479,1593,1707,1820,1934,2048,2162,2275,2389,2503,2617,2730,2844,2958,3072,3185,3299,3413,3527,3640,3754,3868,3982,4096]
stop_countZ = 0
# gpio ouput values list
halfstep_seq = [
[1,0,0,0],
[1,1,0,0],
[0,1,0,0],
[0,1,1,0],
[0,0,1,0],
[0,0,1,1],
[0,0,0,1],
[1,0,0,1]
]
# stepper x starting halfstep value do not change
halfstep = 0
# stepper Z starting Halfstep value do not change
position = 0
# Stepper X cycles starting value
cycle = 1
# stop time after moving stepper Z you can reduce this if you want but not below 0.5
zstop = 5
# cmaera picture count start value
campic = 1
#step timer value adjust this value higher to slow stepping of motors typical values 0.001 0.001007
steptime = 0.001007
# delay for picture taking stop can be reduced once you have your picture taking code added but not below 0.5
picdelay = 5
def take_picture(campic):
print("Take picture", campic)
# the following line contains the path and file name that will be use to save file
filename = "/home/pi/" + name + str(campic) + ".jpg"
with picamera.PiCamera() as camera:
camera.resolution = (1920, 1080)
camera.start_preview()
time.sleep(2)
camera.capture(filename)
time.sleep(0.5)
camera.stop_preview()
def stepperz(Halfstep,stop_countZ):
# Stepper Z
start = stopsZ[stop_countZ]
if stop_countZ > 0:
start = start + 1
stop = stopsZ[stop_countZ + 1] + 1
for I in range(start, stop): # this now the number of steps for one move
#print(I)
for pin in range(4):
GPIO.output(control_pinsZ[pin], halfstep_seq[Halfstep][pin])
time.sleep(steptime)
Halfstep = Halfstep + 1
if Halfstep == 8:
Halfstep = 0
#stop
print("Z moved to", (stopsZ[stop_countZ + 1]))
time.sleep(1)
return Halfstep
# file name entry
print ("Program Start")
print (" ")
print ("please input a file name for this program run")
name = input ("> ")
print(" ")
if name =="":
name = (time.strftime("%d%H%M_"))
# main program loop
start = time.time()
for L in range(18): #loop for 18 times clockwise 18 counter clockwise
# Clock wise rotation including stops
for i in range(32769): # this now the number of steps for a 240 degrees rotation
#print(i)
for pin in range(4):
GPIO.output(control_pinsX[pin], halfstep_seq[halfstep][pin])
time.sleep(steptime)
halfstep = halfstep + 1
if halfstep == 8:
halfstep = 0
#stops
if i == (stopsX[stop_countX]):
print("X Moved to", (stopsX[stop_countX]))
time.sleep(picdelay)
#call to take picure
take_picture(campic)
campic = campic + 1
stop_countX = stop_countX + 1
# End of Clockwise rotation
print ("End of camera clockwise rotation cycle ", cycle )
# call stepper Z
stop_countZ = cycle - 1
Halfstep = position
position = stepperz(Halfstep,stop_countZ)
cycle = cycle + 1
stop_countX = 8 # reset stops
time.sleep(zstop)
# rotate back to start with stops
for i in range(32768, -1, -1): # this now the number of steps for the required rotation
#print(i)
for pin in range(4):
GPIO.output(control_pinsX[pin], halfstep_seq[halfstep][pin])
time.sleep(steptime)
halfstep = halfstep - 1
if halfstep == -1:
halfstep = 7
#stops
if i == (stopsX[stop_countX]):
print("X moved to", (stopsX[stop_countX]))
time.sleep(picdelay)
#call to take picure
take_picture(campic)
campic = campic + 1
stop_countX = stop_countX - 1
#End of counter clockwise rotation
print ("End of counter clockwise camera rotation cycle ", cycle)
# call stepper Z
stop_countZ = cycle - 1
Halfstep = position
position = stepperz(Halfstep,stop_countZ)
cycle = cycle + 1
stop_countX = 0 # reset stops
time.sleep(zstop)
GPIO.cleanup()
end = time.time()
runT = (end - start)
a=str(runT//3600)
b=str((runT%3600)//60)
c=str(round(((runT%3600)%60),3))
print ("End of program run it took {} hours {} mins {} seconds".format(a, b, c))