Page 2 of 5
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Wed Apr 15, 2020 2:52 pm
by pcmanbob
Moving goal posts.......
and do you still want the 5 second pause after each the change of direction ?
As 2728 is the last stop in your stop points and the point at which you motor stops , so you are going to stop for 5 + 5 + 5 seconds at the end of each clockwise travel.
and you will have to wait for the next code post I am busy with other users......
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Wed Apr 15, 2020 3:52 pm
by ceciliab
Super! I think I can handle it from here. I'll try by myself and post the reply in case I manage.
Thanks for everything! You've been greatly helpful, supportive and kind.
Byee
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Wed Apr 15, 2020 4:26 pm
by pcmanbob
Well if you cant provide an answer to my question about the delay at then end of each loop , how do you expect me to help , if I post what I think and its wrong , then we will have moving goal posts again to get it right.
and I was only advising you that I was busy with other users so you would not be waiting thinking I was ignoring you.
So I have made the code do as you wanted alternating 18 cycles clockwise with 18 counter clockwise, for each of the cycles I need it to stop 5 times, stopping for 5 seconds.
I have left the 5 second stop in at the end of each travel but it is not active , just follow the instructions in the code to activate it.
Code: Select all
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
control_pins = [7,11,13,15]
stops = [546,1091,1637,2182,2728]
stop_count = 0
for pin in control_pins:
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()
cycle = 1
for L in range(18): #loop for 18 times clockwise 18 counter clockwise
# Clock wise roation including stops
for i in range(2729): # this now the number of steps for a full rotation
print(i)
for pin in range(4):
GPIO.output(control_pins[pin], halfstep_seq[halfstep][pin])
time.sleep(0.001)
halfstep = halfstep + 1
if halfstep == 8:
halfstep = 0
#stops
if i == (stops[stop_count]):
print("stop at ", (stops[stop_count]))
stop_count = stop_count + 1
time.sleep(3)
# End of Clockwise roation
#stop and wait 5 seconds
print ("End of Clockwise roation cycle ", cycle )
#time.sleep(5) # uncoment this line if you want to stop for 5 seconds at the end of the motor travel before stating again
cycle = cycle + 1
stop_count = 4 # reset stops
# roate 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_pins[pin], halfstep_seq[halfstep][pin])
time.sleep(0.001)
halfstep = halfstep - 1
if halfstep == -1:
halfstep = 7
#stops
if i == (stops[stop_count]):
print("stop at ", (stops[stop_count]))
stop_count = stop_count - 1
time.sleep(3)
#End of reverse.
print ("End of Counter Clockwise rotation cycle ", cycle)
#time.sleep(5) # uncoment this line if you want to stop for 5 seconds at the end of the motor travel before stating again
cycle = cycle + 1
stop_count = 0 # reset stops
GPIO.cleanup()
end = time.time()
print (end - start)
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Wed Apr 15, 2020 5:09 pm
by ceciliab
Ok, so the mechanism works perfectly, but now the distance between the stops became wider.
This makes the full rotation taking more than 360 degrees to complete each cycle; instead of 240 degrees as we're declaring and as the previous script was rightly processing.
Should we increase the time delay like we did for the other stepper perhaps?
Everything else is great.
Regarding the seconds of pause: I can't really tell how much of them I need at the moment, because I have to sync this stepper with the other one and the camera. So for now 5 second is a good amount of time for the pause to be evident, therefore: great!
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Wed Apr 15, 2020 5:54 pm
by pcmanbob
That does not make sense, I only changed the number of steps in the first for loop by 1 because I noticed you were not getting to the last stop 2728
The second loop is still as it was.
Edit.
Ok I think I have found the problem, I had to correct the indention because it was getting messy and I think I had the sleep and half step counter indented to far

, on both loops that would make a mess of the spacing.
try this hope fully I have the indentation sorted out.
Code: Select all
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
control_pins = [7,11,13,15]
stops = [546,1091,1637,2182,2728]
stop_count = 0
for pin in control_pins:
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()
cycle = 1
for L in range(18): #loop for 18 times clockwise 18 counter clockwise
# Clock wise roation including stops
for i in range(2729): # this now the number of steps for a full rotation
print(i)
for pin in range(4):
GPIO.output(control_pins[pin], halfstep_seq[halfstep][pin])
time.sleep(0.001)
halfstep = halfstep + 1
if halfstep == 8:
halfstep = 0
#stops
if i == (stops[stop_count]):
print("stop at ", (stops[stop_count]))
stop_count = stop_count + 1
time.sleep(3)
# End of Clockwise roation
#stop and wait 5 seconds
print ("End of Clockwise roation cycle ", cycle )
#time.sleep(5) # uncoment this line if you want to stop for 5 seconds at the end of the motor travel before stating again
cycle = cycle + 1
stop_count = 4 # reset stops
# roate 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_pins[pin], halfstep_seq[halfstep][pin])
time.sleep(0.001)
halfstep = halfstep - 1
if halfstep == -1:
halfstep = 7
#stops
if i == (stops[stop_count]):
print("stop at ", (stops[stop_count]))
stop_count = stop_count - 1
time.sleep(3)
#End of reverse.
print ("End of Counter Clockwise rotation cycle ", cycle)
#time.sleep(5) # uncoment this line if you want to stop for 5 seconds at the end of the motor travel before stating again
cycle = cycle + 1
stop_count = 0 # reset stops
GPIO.cleanup()
end = time.time()
print (end - start)
finger crossed

Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Wed Apr 15, 2020 7:13 pm
by ceciliab
Bingooooo!
https://www.youtube.com/watch?v=VVRHtUes7go
Well, if you wanna know what I'm doing let me know. It'll be the invention of the century
Thanks so so so so much Bob!!! And congrats for your remarkable patience and dedication.
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Fri Apr 17, 2020 4:13 pm
by ceciliab
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
if and
else, which I don't reckon I need. Am I wrong?
https://github.com/skiwithpete/seenancy ... pper_3a.py
Here's the combined code:
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)
Thanks!
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Fri Apr 17, 2020 5:14 pm
by pcmanbob
As your code is now you have to run through all of the moves/stops of the first stepper motor before you start moving the second stepper motor.
In the linked example he appears to be moving the first stepper motor to a position then move the second them move the third.
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Fri Apr 17, 2020 5:58 pm
by ceciliab
I see, you're right!
Posts around talk about threading / multi-threading, but they say it's quite of a complex one, plus I don't think it's needed for what I like to do.
This post in particular seems useful:
viewtopic.php?t=30340
On the other hand this guy claims to achieve it by simply coping the previous stepper motor code and changing the GPIO pins assignments.
http://jumpstation.co.uk/flog/Mar2014.html#190320142109
It looks like he's using a breadboard, which I don't need as my pi is a 3 Model A+.
Also I don't understand how (and why) he defines 4 different GPIO signals: 2 per stepper, 1 CW, 1CCW.
- Is he doing so by setting the GPIO mode as BCM instead of BOARD?
- Is he doing so for splitting the sequences to call later on?
I'm a lil confused. I need to read through both links with a fresher mind. Might do it in the weekend

)
Thanks!
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Fri Apr 17, 2020 6:42 pm
by pcmanbob
I have no idea what he is using 2 sets of gpio pins for each motor.
Why don't you ask him .
The different between BCM and Board numbering is just that the way the pins are numbered.
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Fri Apr 17, 2020 6:48 pm
by ceciliab
Good idea, will do. Thanks for the BCM info
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Fri Apr 17, 2020 8:10 pm
by pcmanbob
So exactly how are these two motors supposed to interact ?
One seems to travel backwards and forwards while the other just rotates in just one direction.
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Fri Apr 17, 2020 9:11 pm
by ceciliab
So it's going to be a machine for the photogrammetry of insects, in particular bees. The photogrammetry is a technique to create 3D models out of a series of pictures of an object.
The machine is going to be composed by a big a big wheel onto which I'll place the camera plus a central base holding a needle on top of which I'll place the stuffed insect. The wheel will be moved by Stepper X, whereas the central needle will rotate thanks to Stepper Z.
To try describing the movement:
The camera, placed on the big wheel, will move around the bee from left to right, in an area of 240 degrees, stopping 5 times and shooting a picture at each of the 5 stops. During the Stepper X end of the Clockwise cycle 5 seconds pause, the bee (moved by Stepper Z) will move to the second of its 36 positions on the z-axis. Once the second position will be reached, the camera on the wheel will go backwards and start its counter clockwise movement, stopping again for five times and taking 5 pictures. Afterwards, during the Stepper X end of the Counter Clockwise cycle 5 seconds pause, the bee will reach the third of its 36 positions and so on. This will end when the wheel will have completed 18 movement clockwise and 18 counter clockwise, and the central bee will have stopped in all of its 36 positions.
To recap:
1/5 shot > Stepper X move to 2/5 position CW > 2/5 shot > Stepper X move to 3/5 position CW > 3/5 shot > Stepper X move to 4/5 position CW > 4/5 shot > Stepper X move to 5/5 position CW > 5/5 shot > Stepper Z move to 2/36 position > 1/5 shot > Stepper X move to 2/5 position CCW > 2/5 shot > Stepper X move to 3/5 position CCW > 3/5 shot > Stepper X move to 4/5 position CCW > 4/5 shot > Stepper X move to 5/5 position CCW > 5/5 shot > Stepper Z move to 3/36 position > ... > Stepper Z move to 35/36 position > 1/5 shot > Stepper X move to 2/5 position CW > 2/5 shot > Stepper X move to 3/5 position CW > 3/5 shot > Stepper X move to 4/5 position CW > 4/5 shot > Stepper X move to 5/5 position CW > 5/5 shot > Stepper Z move to 36/36 position > 1/5 shot > Stepper X move to 2/5 position CCW > 2/5 shot > Stepper X move to 3/5 position CCW > 3/5 shot > Stepper X move to 4/5 position CCW > 4/5 shot > Stepper X move to 5/5 position CCW > 5/5 shot > End of the loop
I don't know if this is more helpful or confusing ahah hope it's interesting at least
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Fri Apr 17, 2020 11:07 pm
by pcmanbob
Ok it's late here in the UK.
I will read your post again tomorrow and look at your code, and see if I can get it to do what you want but it may be a few days before I get back to you.
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 8:42 am
by ceciliab
Heyy! Yes, no worries at all. Meanwhile I'll try contacting the "changing GPIO" guy and post any news. Thanksss
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 9:01 am
by PiGraham
ceciliab wrote: ↑Fri Apr 17, 2020 5:58 pm
On the other hand this guy claims to achieve it by simply coping the previous stepper motor code and changing the GPIO pins assignments.
http://jumpstation.co.uk/flog/Mar2014.html#190320142109
It looks like he's using a breadboard, which I don't need as my pi is a 3 Model A+.
Also I don't understand how (and why) he defines 4 different GPIO signals: 2 per stepper, 1 CW, 1CCW.
According the topic title you are using 288yj-48 stepper motors. Those are unipolar motors with four phase terminals that will be either on or off.
Typically they are supplied with simple Darlington drivers.
Some good info here
https://lastminuteengineers.com/28byj48 ... -tutorial/
There are other ways of connecting the coils in a stepper motor where you drive each end of a coil high or low to get currents that gow one way or the other. Coild can be on forwards, off or on reverse and you need h-bridge drivers.
So to drive your 288yj-48 you need four gpio that turn on and off in a particular sequence.
To drive two motors you need 8 gpio, four for each motor.
You can use stepper driver boards to do the coil driving in step sequence for you when you provide just two control signals - step and direction.
The you would only need four gpio for two motors. Your code would be simper. The stepper drivers I know of are all for bipolar stepper motors, not unipolar type.
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 9:10 am
by PiGraham
ceciliab wrote: ↑Fri Apr 17, 2020 5:58 pm
On the other hand this guy claims to achieve it by simply coping the previous stepper motor code and changing the GPIO pins assignments.
http://jumpstation.co.uk/flog/Mar2014.html#190320142109
It looks like he's using a breadboard, which I don't need as my pi is a 3 Model A+.
Also I don't understand how (and why) he defines 4 different GPIO signals: 2 per stepper, 1 CW, 1CCW.
Is this the CW / CCW bit you mean?
Code: Select all
StepPins1 = [7,8,25,24] # CCW rotation
StepPins2 = [14,15,18,23] # CW rotation
if (sys.argv[4]=="CCW") :
StepPins2 = [23,18,15,14] # CCW rotation
The different direction is the same pins in a different order.
StepPins1 is for motor 1 and STepPins2 is for motor 2.
The sequence of activation of those pins determines the direction of movement.
Call the motor connections A,B,C,D
The wiring isfor motor 2 is then:
A to gpio 14
B to gpio 15
C to gpio18
D to gpio 23
To turn CW the sequence is: A,B,C,D
TO turn CCW the sequence is: D,C,B,A
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 9:13 am
by pcmanbob
So having looked at the requirements .
you need stepper X to move clockwise stopping 5 times.
at the end of travel you need stepper Z to step to the next stop
then stepper X moves counter clockwise stopping 5 time
at the end of travel you need stepper Z to step to the next stop.
this repeats till all 36 steps of stepper Z have be covered.
is this correct ?
If it is then the requirement will be frozen and no change will be allowed till the code changes are complete ( so we don't have moving goal posts).
now to make this work we need to do several things.
1. change some of the variable names for stepper Z so they don't clash with stepper X
2. change stepper Z code so it runs as a function only moving one stop at a time and not in a loop
3. send step commands from stepper X to stepper Z when its time to move telling it which stop to move to next
4. report stepper Z coil position at the end of each movement so it can be told were to continue from on the next movement
Now this will require a lot of changes to code and errors can and will creep in , I can test the code to make sure it runs without error but I can't test the code against hardware to you will have to do that and report back you results.
Now depending now many errors we have to correct and how much free time I can put in to this it might take more than a couple of days.
If the requirements are correct ( see above) and you are happy with the time scale (hopefully less but , think 7 days ) I will try and make a start today.
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 9:19 am
by pcmanbob
PiGraham wrote: ↑Sat Apr 18, 2020 9:10 am
ceciliab wrote: ↑Fri Apr 17, 2020 5:58 pm
On the other hand this guy claims to achieve it by simply coping the previous stepper motor code and changing the GPIO pins assignments.
http://jumpstation.co.uk/flog/Mar2014.html#190320142109
It looks like he's using a breadboard, which I don't need as my pi is a 3 Model A+.
Also I don't understand how (and why) he defines 4 different GPIO signals: 2 per stepper, 1 CW, 1CCW.
Is this the CW / CCW bit you mean?
Code: Select all
StepPins1 = [7,8,25,24] # CCW rotation
StepPins2 = [14,15,18,23] # CW rotation
if (sys.argv[4]=="CCW") :
StepPins2 = [23,18,15,14] # CCW rotation
The different direction is the same pins in a different order.
StepPins1 is for motor 1 and STepPins2 is for motor 2.
The sequence of activation of those pins determines the direction of movement.
Call the motor connections A,B,C,D
The wiring isfor motor 2 is then:
A to gpio 14
B to gpio 15
C to gpio18
D to gpio 23
To turn CW the sequence is: A,B,C,D
TO turn CCW the sequence is: D,C,B,A
Thanks PiGraham I had not looked at the linked code in any detail , we have working code to drive both stepper motors one travels in both directions and the other in one direction only . we do it by changing the direction we read the list of gpio output states.
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 9:35 am
by PiGraham
pcmanbob wrote: ↑Sat Apr 18, 2020 9:19 am
we do it by changing the direction we read the list of gpio output states.
That is a cleaner way to do it
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 10:20 am
by ceciliab
pcmanbob wrote: ↑Sat Apr 18, 2020 9:13 am
So having looked at the requirements .
you need stepper X to move clockwise stopping 5 times.
at the end of travel you need stepper Z to step to the next stop
then stepper X moves counter clockwise stopping 5 time
at the end of travel you need stepper Z to step to the next stop.
this repeats till all 36 steps of stepper Z have be covered.
is this correct ?
If it is then the requirement will be frozen and no change will be allowed till the code changes are complete ( so we don't have moving goal posts).
now to make this work we need to do several things.
1. change some of the variable names for stepper Z so they don't clash with stepper X
2. change stepper Z code so it runs as a function only moving one stop at a time and not in a loop
3. send step commands from stepper X to stepper Z when its time to move telling it which stop to move to next
4. report stepper Z coil position at the end of each movement so it can be told were to continue from on the next movement
Now this will require a lot of changes to code and errors can and will creep in , I can test the code to make sure it runs without error but I can't test the code against hardware to you will have to do that and report back you results.
Now depending now many errors we have to correct and how much free time I can put in to this it might take more than a couple of days.
If the requirements are correct ( see above) and you are happy with the time scale (hopefully less but , think 7 days ) I will try and make a start today.
The requirements are correct, yes.
And yes, of course there's no rush. If I can help somehow, apart from checking it with the hardware and report back the results just let me know.
Thanks!
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 10:32 am
by ceciliab
PiGraham wrote: ↑Sat Apr 18, 2020 9:10 am
ceciliab wrote: ↑Fri Apr 17, 2020 5:58 pm
On the other hand this guy claims to achieve it by simply coping the previous stepper motor code and changing the GPIO pins assignments.
http://jumpstation.co.uk/flog/Mar2014.html#190320142109
It looks like he's using a breadboard, which I don't need as my pi is a 3 Model A+.
Also I don't understand how (and why) he defines 4 different GPIO signals: 2 per stepper, 1 CW, 1CCW.
Is this the CW / CCW bit you mean?
Code: Select all
StepPins1 = [7,8,25,24] # CCW rotation
StepPins2 = [14,15,18,23] # CW rotation
if (sys.argv[4]=="CCW") :
StepPins2 = [23,18,15,14] # CCW rotation
The different direction is the same pins in a different order.
StepPins1 is for motor 1 and STepPins2 is for motor 2.
The sequence of activation of those pins determines the direction of movement.
Call the motor connections A,B,C,D
The wiring isfor motor 2 is then:
A to gpio 14
B to gpio 15
C to gpio18
D to gpio 23
To turn CW the sequence is: A,B,C,D
TO turn CCW the sequence is: D,C,B,A
Hi! Thanks for explaining this further.
The CW / CCW bit I was referring to is the one you highlighted, but when I mentioned the 4 GPIO, I actually meant this specific line, where he calls 4 of them:
Code: Select all
# Define GPIO signals to use
# GPIO24,GPIO25,GPIO8,GPIO7
As Bob said, in the script he helped me writing, things where placed differently and to me it looked like he wasn't calling 4 of them.
But now i've got it, and looks like you passed info to each other.
Thanks all for the help!!
p.s. another good tutorial I found very helpful to start is this one, maybe you already know:
https://medium.com/@Keithweaver_/contro ... fbd482f886
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 11:06 am
by pcmanbob
OK so rain stopped play here, so with my project abandoned for today.
I put some time in your you code instead .
please can you test this code, it should move stepper Z to the first stop wait 5 seconds then move it to the second stop at this point the program will stop.
Code: Select all
# version 1
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 = [0,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)
for pin in control_pinsZ:
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 Z starting Halfstep
Halfstep = 0
# Stepper X
cycle = 1
def stepperz(Halfstep,cycle):
# Stepper Z
start = stopsZ[cycle - 1]
stop = stopsZ[cycle] + 1
print (start, stop)
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(0.001)
Halfstep = Halfstep + 1
if Halfstep == 8:
Halfstep = 0
#stop
print("stop at ", (stopsZ[cycle]))
return Halfstep
time.sleep(5)
position = stepperz(Halfstep,cycle)
print (position)
Halfstep = position
cycle = 2
position = stepperz(Halfstep,cycle)
print (position)
GPIO.cleanup()
end = time.time()
#print (end - start)
its just a test to see if the code still moves the stepper correctly when called like this, the code will change as we move forward.
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 11:42 am
by ceciliab
Tried it out: it moves Stepper Z to its first position then the program stops.
This is what the terminal prints out:
Code: Select all
(0, 115)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
('stop at ', 114)
3
(114, 229)
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
('stop at ', 228)
6
Re: Stepper 288yj-48 - stop and restart from the latest position
Posted: Sat Apr 18, 2020 11:44 am
by pcmanbob
Does it not move to the second position ?
should move to 114 then wait 5 seconds then move to 228 at this point after 5 seconds program should end.