1

I have a stepper 288yj-48 and I want it to stop 36 times while completing a 360 degrees revolution. For each of the 36 stops, I need it to pause for 10 seconds before moving to the next position.

Here below the code I’m starting with. You'll see “for in range(14)” where 14 represents 1 of the 36 steps I need the stepper to stop at, but I'm not sure if this is the right way to go.

Any suggestion? Thanks

Here you can find the tutorial I took the code from: https://medium.com/@Keithweaver_/controlling-stepper-motors-using-python-with-a-raspberry-pi-b3fbd482f886

import time

GPIO.setmode(GPIO.BOARD)

control_pins = [7,11,13,15]

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

for i in range(14):
  for halfstep in range(8):
    for pin in range(4):
      GPIO.output(control_pins[pin], halfstep_seq[halfstep][pin])

    time.sleep(0.001)

GPIO.cleanup()

  • I can't see any Pi relevance as this just seems to be a programming question. Neither can I see a question. – joan Apr 6 at 15:33
  • Thanks for your feedback Joan. You're right, this is more of a programming question, if this is not the right space and you'd like to suggest a better direction, I'm happy to follow your say. What I'm looking for is some references on the matter to be able to move forward. Thanks! – cecilia Apr 6 at 15:43
  • tell one of the steppers to stop ... why do you need to "tell" the stepper anything? ... just stop sending a step command – jsotola Apr 6 at 15:59
  • it is actually unclear what the problem actually is .... are you asking how to start the motion from a random position? – jsotola Apr 6 at 16:05
  • I need the stepper to stop 36 times while completing a 360 degrees tour. At each of the 36 positions, I need the stepper to pause for 10 seconds before moving to the next position. The problem is that I don't know how to do it, because it's the first time I work with RPi or Python. Thanks for asking to clarify, I'm going to edit the question :) – cecilia Apr 6 at 16:19
0

The link to the tutorial you gave seems to be broken but I'm guessing it's this one while searching for that tutorial I also found this which has some additional information. First you need to determine how many half steps your motor takes to execute a full 360. From the second link you can see that the datasheet for the 288yj-48 stepper seems to indicate 4096 with a couple of caveats - it might actually be 4076 or if its the Adafruit small reduction gear stepper which uses the same form factor as the 288yj-48 it could be 513. Watching the video in your tutorial link I suspect that this is what they use because the tutorial code has i in range to 512 and the motor appears to make one full revolution.

So for 36 stops you want your stepper to step 10 degrees or 513/36 = 14.25 (4096/36 = 113.77) so the simplest way I can think to do that would be taking the code from the tutorial and modify it slightly - which you've started to do.

...  

for a in range(36):
  for i in range(14):
    for halfstep in range(8):
      for pin in range(4):
        GPIO.output(control_pins[pin], halfstep_seq[halfstep][pin])
      time.sleep(0.001)
  time.sleep(10)

Assuming that you have the 513 version of the stepper its going move 14 steps 36 times for a full revolution.

The problem I can see here is that you can't divide the stepper motor steps equally by 36 with integer values so after the pattern will drift by 9-10 half steps. You might be able to resolve that by changing the looping so that you do more of the halfstep loops for each i loop the trick would be to continue the halfstep sequence on the next i loop where the last i loop left off. If it could work then its something to experiment with.

I didn't see it in the tutorial you are following but please take note of the caution in the second tutorial link provided regarding powering the stepper motors - regardless of Pi or Arduino power the motors separately and not from the Pi/Arduino

| improve this answer | |
0

that's great! Thanks so much for the time you put in being this detailed.

I actually moved forward in another forum where a guy helped me sorting out a solution. We pretty much did what you suggested - dividing 4096 by 36 and rounding up the results - but we re-wrote the code in a slightly different way.

You can see the thread in here: https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=270132&p=1639068#p1639068

I'll have a look at the second link you suggested and thanks for spotting that mine was broken :)

| improve this answer | |
  • If the answer of @Hargrovm helped you, please accept it with a click on the tick on its left side. This will finish your question and it will not pop up again for years. – Ingo Apr 11 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.