ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 11:46 am

It doesn't. The hardware only stops once.

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 11:51 am

So were does it stop ?

at 114

or

228 ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 12:03 pm

So, I was assuming 114 considering how short the movement is, but then I tried both 114 and 228 on another stepper and the 228 seems the closest option.

Therefore I say 228 - as the terminal prints out. Hence I think it's missing both the first stop and the 5 seconds pause.

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 12:17 pm

Ok lets test you posted code that I am working from in case there is a problem with that ,

this should do all 36 stops

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 = [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


# 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

    print(I, control_pinsZ[pin], halfstep_seq[Halfstep][pin], Halfstep)
    #stops
    if I == (stopsZ[stop_countZ]):
        print("stop at ", (stopsZ[stop_countZ]))
        stop_countZ = stop_countZ + 1

        time.sleep(5)

GPIO.cleanup()
end = time.time()
#print (end - start)
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 12:31 pm

Yes it works!

Stop 10 looks slightly wider, might be because of the rounding up. This is not a big deal, as it won't affect the result of the photogrammetry.

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 12:37 pm

That's a good result then , now I just have to figure out why the other code does not :? ;)

You can always adjust the stop for position 10 once we have finalised working code , as you only have to change the stop point number in stopsZ.

now you see why I said think 7 days..... :lol: :lol:
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 12:58 pm

I think 7 days is a pessimistic prediction considering how fast you've been so far, and the fact that the codes are there, they just need to communicate. But you're the expert, so can't really say. And again, there's really no rush.

Yep cool, will adjust everything at the end, just said so to report exactly what was happening.
Let me know if you need me to research something in particular that can help, or to try contacting someone. Maybe I should open a new thread or change this thread title?

Just to double checking smth about the camera: is it ok not to consider it at this stage? I'm concerned it will compromise the whole code structure later on.

So far I've been separately testing a very basic camera module through this line, to try out the timing and understand how it works:

Code: Select all

raspistill -o a%04d.jpg -t 645000 -tl 3600
But it was not even a file, just a command in the terminal.

I'm now waiting for a 18MP camera + 25mm lens to arrive from China, so I didn't spend too much time on it yet tbh, as I'll have to test all the settings with the definitive components.

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 1:41 pm

This is just the first step in the process and I have stumbled, lots more steps yet , lots of time to stumble again.

So no don't worry about the camera bit yet, you will be adding it in place of the time.sleep that you currently do on stepper X when you reach a stop so it wont affect the stepping.

opening a duplicate thread will have 2 effects ,
1. mods will jump on you for double posting ,its frowned upon here
2. it will just add confusion when you start getting suggestions from multiple users

So please don't do it .

If you are going to be using a camera module that connects the same as the pi camera does then have a look at this document
https://picamera.readthedocs.io/en/rele ... stall.html

as you are programming in python you need to use the python camera commands, have a look at section 3 Basic Recipes.

But before you do please can you test this code, I am hopping it will drive the stepper motor and stop at the first 10 stop points.

Code: Select all


# version 1.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
position = 0

# Stepper X
cycle = 1

def stepperz(Halfstep,stop_countZ):
    # Stepper Z
    start = stopsZ[stop_countZ]
    if stop_countZ > 0:
        start = start + 1
    stop = stopsZ[stop_countZ + 1] + 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])
            print(control_pinsZ[pin], halfstep_seq[Halfstep][pin])
        time.sleep(0.001)

        Halfstep = Halfstep + 1
        if Halfstep == 8:
            Halfstep = 0

        print(Halfstep)

    #stop
    print("stop at ", (stopsZ[stop_countZ + 1]))
    return Halfstep
    time.sleep(5)


for stop_countZ in range(10): 
    Halfstep = position
    position = stepperz(Halfstep,stop_countZ)
    #print (position)
    print((stop_countZ + 1), "stop completed")
    time.sleep (5)



GPIO.cleanup()
end = time.time()
#print (end - start)
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 2:18 pm

Yes I saw that doc and started to study it, especially chapter 9. Thanks!

I tested the code and it doesn't stop after its 10th position. It runs through all the 36 stops, exactly as it was doing before.

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 2:30 pm

ceciliab wrote:
Sat Apr 18, 2020 2:18 pm

I tested the code and it doesn't stop after its 10th position. It runs through all the 36 stops, exactly as it was doing before.
Are you running the right code ?

when I test ran it it stopped at 10 because the line for stop_countZ in range(10): only goes up to 10.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 2:34 pm

Oopsyyy - looks like I've been the stumbling block. Sorry!

It works!

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 2:38 pm

ceciliab wrote:
Sat Apr 18, 2020 2:34 pm
Oopsyyy - looks like I've been the stumbling block. Sorry!

It works!
welcome to the club :lol: :lol: :lol: :lol: :lol: :lol:

glad it works now , think I will stop for today at this point and attack it again tomorrow with a fresh set of eyes..... :shock:
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sat Apr 18, 2020 2:40 pm

Yes sure! Thanks so much. And again no rush. No need to do it on a Sunday.

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sun Apr 19, 2020 1:33 pm

Hi..

So can you test this code to check it works correctly.

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

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 the required 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



GPIO.cleanup()
end = time.time()
print (end - start)
and I have a question about its operation

so when turning clockwise we start at 0 with no stop ,
we stop at 546,1091,1637,2182,2728

but on counter clockwise travel
we stop at 2728,2182,1637,1091,546

but again we do not stop at 0

is this correct ?
because if you intend to take pictures at these stops you will never get a picture at 0 , but you will get pictures in both directions at all other stops
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sun Apr 19, 2020 1:54 pm

Hey! :)

The script works. It's stopping in all of 5 positions, going back and forth for 36 times.

To reply to your question: you're right, this way we're not considering stop 0.
It is important though that we shoot at stop 0 as well. Stop 0 and stop 2728, in fact, are the extremities of our photo shoot, and without one of them some details of the animal we'll be missed.

We can add a 6th stop - one more stop would only increase the number of pics and consequently the level of details - therefore it's not a bad thing. Otherwise we can divide the 240 degrees by 4.

I made the math for the latter case:
0, 682, 1364, 2046, 2728

Just choose whichever option you reckon fits best with the code as it is at the moment.

Thanks!

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sun Apr 19, 2020 2:16 pm

OK not a problem we can add a 0 stop.

but I was testing a first copy of the program with both steppers and there is another problem.

if you include 0 there are only 35 positions for your stepper Z but we run stepper X 36 times so on the last clockwise travel when we reach the end there is no step for the stepper Z for the counter clockwise travel, but I would guess you want the stepper X to return to 0.

so as I see it we have 3 options

1. we just run the counter clockwise travel without moving stepper Z so you end up with the last 2 sets of pictures being the same.

2. we just drive stepper X counter clockwise and don't stop to take pictures

3. you add another stop for stepper Z

Edit....

does stepper Z do a full rotation when it gets to 4096 or do we need to move it further to get back to 0 ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sun Apr 19, 2020 2:25 pm

Sure, right!

So I'd opt for adding another stop for Stepper Z, but it is important that the last cycle of Stepper X moves counter clockwise so that the camera on the wheel will return to its initial position, ready for the next set of shootings to start the same way.

If this involves driving back stepper X counter clockwise and don't stop to take pictures, that's ok.

super thanks!

Edit:

Back to 0 if this means bringing it back to its initial position at the very end of the shooting.

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sun Apr 19, 2020 2:33 pm

Right so when stepper Z is rotated we start with it a 0,

it then rotates clockwise only till it reaches step 4096,

when it gets to step 4096 is it back at the same point in its rotation as it was at step 0

in other words is 0 and 4096 the same point
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sun Apr 19, 2020 2:51 pm

0 and 4096 can be the same point, as long as the bee on the Z axis stops for 36 times.

Therefore, I'm assuming that, considering 0 as its first position, we need to divide 4096 by 35. This way stop 1 will become 117.
Correct? If so, let me know if you need me to redo the math.

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sun Apr 19, 2020 3:06 pm

May be you did not understand what I was asking .

So if you mark your stepper motor and then run this code does the mark end up back at the starting position.

Code: Select all


# master code

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,4096]
stop_countZ = 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 X
cycle = 1



for i in range(4097):  # 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_countZ]):
        print("This is stop at ", (stopsZ[stop_countZ]))
        stop_countZ = stop_countZ + 1

        time.sleep(10)

GPIO.cleanup()
end = time.time()
print (end - start)
it only stops at 0 and 4096
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sun Apr 19, 2020 3:10 pm

So if you mark your stepper motor and then run this code does the mark end up back at the starting position.
Yes it does

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Sun Apr 19, 2020 3:45 pm

Right, so how does this look for stops with the extra 1, in the actual program we don't stop at 0 but its there because we need to have a start and end point for the program to work.

Code: Select all


# master code

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]
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

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 X
cycle = 1



for i in range(4097):  # 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_countZ]):
        print("This is stop at ", (stopsZ[stop_countZ]))
        stop_countZ = stop_countZ + 1

        time.sleep(10)

GPIO.cleanup()
end = time.time()
print (end - start)

should step 113.7777 but as we can't we step 114 ,

there are 8 points that are 1 less to make it end up at 4096

If you have a better idea or another list of stop points you prefer then please post them.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Sun Apr 19, 2020 4:08 pm

Ok I tried this updated set of points. Let's go for this one!

pcmanbob
Posts: 9467
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Stepper 288yj-48 - stop and restart from the latest position

Mon Apr 20, 2020 9:01 am

Good morning.

So here is the first test of the program that moves both stepper motors.

now its only a test as there are still some inconstancies in the timing and I need to make the screen output more readable.

Code: Select all


# final 2 stepper version 1.2

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
control_pinsX = [7,11,13,15]
control_pinsZ = [19,21,23,29]

# Stops X
stopsX = [0,546,1091,1637,2182,2728]
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

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
position = 0

# Stepper X
cycle = 1


def stepperz(Halfstep,stop_countZ):
    # Stepper Z
    start = stopsZ[stop_countZ]
    if stop_countZ > 0:
        start = start + 1
    stop = stopsZ[stop_countZ + 1] + 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) #0.001007

        Halfstep = Halfstep + 1
        if Halfstep == 8:
            Halfstep = 0


    #stop
    print("Z stop at ", (stopsZ[stop_countZ + 1]))
    return Halfstep
    time.sleep(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("X stop at ", (stopsX[stop_countX]))
            stop_countX = stop_countX + 1
            time.sleep(5)
        # End of Clockwise rotation

    #stop and wait 5 seconds
    print ("End of Clockwise rotation cycle ", cycle )
    
    
    # call stepper Z
    stop_countZ = cycle - 1
    Halfstep = position
    position = stepperz(Halfstep,stop_countZ)
    
    cycle = cycle + 1
    stop_countX = 4 # reset stops
    time.sleep(5)  # uncomment this line if you want to stop for 5 seconds at the end of the motor travel before stating again
    
    # rotate back to start with stops
    for i in range(2728, -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(0.001)
        halfstep = halfstep - 1
        if halfstep == -1:
            halfstep = 7

        #stops
        if i == (stopsX[stop_countX]):
            print("X stop at ", (stopsX[stop_countX]))
            stop_countX = stop_countX - 1
            time.sleep(5)

    #End of reverse
    print ("End of Counter Clockwise 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(5)  # uncomment this line if you want to stop for 5 seconds at the end of the motor travel before stating again    



GPIO.cleanup()
end = time.time()
print (end - start)
As you are going to be taking many picture on each run of this program have you thought about how you are going to number them ?
do you want a simple counter included to number each picture ?
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

ceciliab
Posts: 56
Joined: Thu Apr 02, 2020 2:51 pm
Location: London

Re: Stepper 288yj-48 - stop and restart from the latest position

Mon Apr 20, 2020 9:48 am

Good morning,

Just tested and it works great. Well done, you've done amazingly!

Concerning the pictures numbering, I was thinking about writing something like -o a%04d.raw but if you have anything better in mind, please feel free to go for it! I'll be shooting raw pictures if this is useful info.

Thanks!!

Return to “Python”