I want to run my NEMA 17 stepper motor (using A4988 driver) at a very low speed like 0.4 rev/sec.
How can i do this using the code?
Anyone can provide any code regarding speed controlling?
have a look at the (no longer supported) VarSpeedServo library
alternatively, you can just take a step when a step is due. it's simple math and use of millis()
Look at the examples that come with the AccelStepper library.
The MobaTools stepper library is, I think, easier to learn and use than AccelStepper.
MobaTools allow setting speed in either steps per second or in RPM.
The MobaTools library is available via the IDE library manager.
Documentation is included in the library.
Here is a sample code using the MobaTools stepper library. I used my Uno with CNC shield, A4988 driver and stepper to test (real hardware). I timed one rotation with a stopwatch and it is very close to 150 seconds for 1 rotation.
#include <MobaTools.h>
const byte stepPin = 2;
const byte dirPin = 5;
const byte enablePin = 8;
const unsigned int motorStepsPerRev = 200;
const unsigned int microstepMultiplier = 4;
const int STEPS_REVOLUTION = motorStepsPerRev * microstepMultiplier;
MoToStepper stepper( STEPS_REVOLUTION, STEPDIR );
void setup()
{
Serial.begin(115200);
stepper.attach( stepPin, dirPin );
stepper.attachEnable(enablePin, 5, 0);
stepper.setSpeed(4); // = 0.4 RPM speed in rpm /10
stepper.setRampLen(2);
stepper.setZero();
}
void loop()
{
stepper.rotate(1); // turn CW 4e4
}
user @ahmedmukit wants 0.4 rev/second.
which is 0.4 * 60 = 24 rpm
An A4988-driver can do 1/16 microstepping.
Using the microstepping will smooth the rotation.
Usually a stepper-motor has 200 full-steps per revolution
With using 1/16 microstepping you have 200 * 16 = 3200 steps/rev.
If you want to rotate at 0.4 rev/second
With 1/16 microstepping this means 3200 * 0.4 = 1280 steps per second.
To achieve 0.4 rev/second this means
#include <MobaTools.h>
const byte stepPin = 2;
const byte dirPin = 5;
const byte enablePin = 8;
const unsigned int motorStepsPerRev = 200;
const unsigned int microstepMultiplier = 16; // maximum microstepping possible on a A4988
const unsigned int STEPS_REVOLUTION = motorStepsPerRev * microstepMultiplier;
const unsigned int STEPS_0_4steps_PER_Second = motorStepsPerRev * microstepMultiplier * 4; // (0.4 rev/second = 4 rev/ ten_seconds)
MoToStepper stepper( STEPS_REVOLUTION, STEPDIR );
void setup()
{
Serial.begin(115200);
stepper.attach( stepPin, dirPin );
stepper.attachEnable(enablePin, 5, 0);
//stepper.setSpeed(4); // = 0.4 RPM speed in rpm /10
//stepper.setSpeedSteps(12800); // the number is steps per TEN seconds (not steps per 1 second)
stepper..setSpeedSteps(STEPS_0_4steps_PER_Second);
stepper.setRampLen(32);
stepper.setZero();
}
void loop()
{
stepper.rotate(1); // turn CW 4e4
}
best regards Stefan
Oops.
stepper..setSpeedSteps(STEPS_0_4steps_PER_Second);
Extra . ?
good catch of the typo
Thanks. corrected it.
Why are the types different ?
The capitalisation feels weird.
Careful on 16 bit maths when doing multiplications and I’ve not read the full explanation but it feels weird to see microstepMultiplier being used twice
It's running but the movement is not smooth at all.
WHich code did you test? The code with the 1/16 microstepping?
Is the speed as expected 0.4 rev / second?
If it is not smooth enough the A4988 can't do any better.
If you want a real smooth rotation you will have to use a TMC2209-stepper-driver
The TMC2209 is very similar to the TMC2208 shown in this video
best regards Stefan
I've just bought the TMC2209. But couldn't find how to wire it. Can you help?
If you post a picture of the TMC2209-board you have bought.
A TMC2209-board is very similar to a A4988 but to make it really shure post a picture and the link where you have bought it.
This is how a silentstep-stick-board is looking like.
best regards Stefan
What about the link from where you bought it?
Does the seller provide a datasheet for downloading?
Unfortunately, no.
I have bought it from a shop. Not from online.
He didn't give any spreadsheet for this.
Here is a tutorial on how to control Nema17 stepper motor speed with Arduino using A4998.
If you need some more basic info about the A4998, you can see here.
Bro, thank you. but this driver is not appropriate for my project. I am now trying to use TMC2209.
The Pins on your TMC2209-board are named with the standard-names.
And they are almost the same as for most other stepper-driver boards.
There is one thing that is really important:
connect / disconnect the motor-wires only if the power-supply is switched OFF !
If you do connect / disconnect the motorwires while powersupply is switched on
you are in danger to destroy the TMC2209 through the high-voltage-spikes that occur in the moment of dis-connecting. The stepper-motor-coils are inductive loads which produce high-voltage-spikes.
So make sure you use very very reliable connections between the 1B 1A, 2A 2B pins and the stepper-motor.
A breadboard is prone to disconnect accidently.
You should use a whole-matrix PCB and screwterminals or direct soldered wires.
Post a picture of your setup what you have you are using.
best regards Stefan
Here is a datasheet from a similar TMC2209-board.
TMC2209_SilentStepStick_datasheet_Rev1.20.pdf (981.4 KB)