Controlling Speed/RPM for Stepper Motors

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
karvis
 
Posts: 2
Joined: Wed Nov 27, 2019 4:24 am

Controlling Speed/RPM for Stepper Motors

Post by karvis »

Hello,

I am controlling 2 stepper motors through an RPI 3. The Stepper motors themselves work fine and I am pleased with the HAT.
https://www.adafruit.com/product/2348

However, I cannot figure out how to control the Speed/RPM of the motors. The code I'm am using is similar to

Code: Select all

from adafruit_motorkit import MotorKit
from adafruit_motor import stepper
kit = MotorKit()
for i in range(200):
    kit.stepper1.onestep(direction=stepper.BACKWARD, style=stepper.DOUBLE)
    kit.stepper2.onestep(direction=stepper.BACKWARD, style=stepper.DOUBLE)
Can anyone please let me know how I can control the speed/RPMs of the motors?

User avatar
dastels
 
Posts: 15829
Joined: Tue Oct 20, 2015 3:22 pm

Re: Controlling Speed/RPM for Stepper Motors

Post by dastels »

Steppers rotate by some angle each time you step them, i.e. each call to `onestep`. That angle is a property of the motor. The more often you step them, the "faster" they rotate.

If you had a motor with 1 degree steps, you'd have to step it 360 times for a full rotation. If you stepped it every ~2.8mS (that's 1/360 S) the motor would be turning at 1 RPM. Stepping it every 1.4mS and it would be rotating at 2RPM.

Dave

User avatar
karvis
 
Posts: 2
Joined: Wed Nov 27, 2019 4:24 am

Re: Controlling Speed/RPM for Stepper Motors

Post by karvis »

Thanks Dave. Appreciate the reply.

Code: Select all

for i in range(200):
    kit.stepper1.onestep(direction=stepper.BACKWARD, style=stepper.DOUBLE)
If I got your explanation, then with this loop, I am essentially running the motor at the "highest" RPM possible (with this motor HAT). I could run it at a lower RPM by introducing a delay within the loop. Is this correct or am I missing something.

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: Controlling Speed/RPM for Stepper Motors

Post by adafruit_support_bill »

Yes. Your delay should be the inverse of the step-rate you are trying to achieve.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”