Hello! I'm combining the two scripts, but once they're together StepperZ doesn't react to the code.
They both work if I run them separately, therefore is a problem related to the script. I think i'm missing something?
Here this guy runs 3 steppers simultaneously. I can't really see any major difference from his code to mine, apart from the fact that he uses
, which I don't reckon I need. Am I wrong?
Code: Select all
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
control_pinsX = [7,11,13,15]
control_pinsZ = [19,21,23,29]
# Stops X
stopsX = [546,1091,1637,2182,2728]
stop_countX = 0
# Stops Z
stopsZ = [114,228,341,455,568,683,796,910,1024,1252,1365,1479,1593,1707,1820,1934,2048,2162,2276,2389,2503,2617,2731,2844,2958,3072,3186,3300,3413,3527,3755,3864,3982,4096]
stop_countZ = 0
for pin in control_pinsX:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
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]
]
halfstep = 0
start = time.time()
# Stepper X
cycle = 1
for L in range(18): #loop for 18 times clockwise 18 counter clockwise
# Clock wise rotation including stops
for i in range(2729): # 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(0.001)
halfstep = halfstep + 1
if halfstep == 8:
halfstep = 0
#stops
if i == (stopsX[stop_countX]):
print("stop at ", (stopsX[stop_countX]))
stop_countX = stop_countX + 1
time.sleep(3)
# End of Clockwise rotation
#stop and wait 5 seconds
print ("End of Clockwise rotation cycle ", cycle )
#time.sleep(5) # uncomment this line if you want to stop for 5 seconds at the end of the motor travel before stating again
cycle = cycle + 1
stop_countX = 4 # reset stops
# rotate back to start with stops
for i in range(2728, -1, -1): # this now the number of steps for a full rotation
print(i)
for pin in range(4):
GPIO.output(control_pinsX[pin], halfstep_seq[halfstep][pin])
time.sleep(0.001)
halfstep = halfstep - 1
if halfstep == -1:
halfstep = 7
#stops
if i == (stopsX[stop_countX]):
print("stop at ", (stopsX[stop_countX]))
stop_countX = stop_countX - 1
time.sleep(3)
#End of reverse
print ("End of Counter Clockwise rotation cycle ", cycle)
time.sleep(5) # uncomment this line if you want to stop for 5 seconds at the end of the motor travel before stating again
cycle = cycle + 1
stop_countX = 0 # reset stops
# Stepper Z
for i in range(4096): # this now the number of steps for a 360 degrees rotation
print(i)
for pin in range(4):
GPIO.output(control_pinsZ[pin], halfstep_seq[halfstep][pin])
time.sleep(0.001)
halfstep = halfstep + 1
if halfstep == 8:
halfstep = 0
#stops
if i == (stopsZ[stop_count]):
print("stop at ", (stopsZ[stop_count]))
stop_countZ = stop_countZ + 1
time.sleep(10)
GPIO.cleanup()
end = time.time()
print (end - start)