It does move with costant speed because I set a very high acceleration. Basically if I don't call the move function the motor doesn't move even though I called runSpeed. Moreover move(1) should set the target position one step further, but if it's been called, the motor starts to rotate indefinetely. setAcceleration is there to get to costant speed fastly, which is again strange because runSpeed should just run at a costant speed.
Am I missing something, or is it a bug?
Am I missing something?
The function runSpeed() should work at the speed set by setSpeed()
The functions setMaxSpeed() and setAcceleration() work with the function run().
If you have set the speed at 200 steps per second I cannot understand why the motor is only moving at 1 step per second - unless 200/sec is just too fast and the motor needs to be accelerated to that speed.
What happens if you set the speed at 20 steps per second, or 2 steps per second?
If that does not help you need to provide all the details of your project
a link to the motor datasheet
details of the stepper driver you are using
details of the stepper power supply (volts and amps)
Robin2:
What happens if you set the speed at 20 steps per second, or 2 steps per second?
Nothing, it keeps rotating at about 1 step/s. I cannot understand why too, because if I didn't use library, and used digitalWrite to bring pins up and down, it would work! So it seems really strange to me.
Robin2:
If that does not help you need to provide all the details of your project
a link to the motor datasheet
details of the stepper driver you are using
details of the stepper power supply (volts and amps)
a diagram showing how everything is connected
the complete Arduino program
The motor is this one, and the datasheet seems to be this one even though mine is smaller.
Frank-95:
but, I say it again, it would work if I used the digitalWrite/delay scheme
Are you saying that you have a program that does not use AccelStepper and which does control the motor properly? If so please post that program so we can compare it to the non-working program.
Am I correct to assume that the exact same hardware configuration is used for both tests?
I tried your code from the OP on my Uno with a NEMA17 bipolar stepper and A4988 driver set to single step and indeed the stepper moves at about 1 step per second no matter the set speed.
Then I rearranged the order of setting maxSpeed and speed and it now the speed is controlled by the setSpeed function. The setMaxSpeed function must be there or the motor goes back to 1 step per second no matter the speed setting.
#include <AccelStepper.h>
AccelStepper neutralStepper(AccelStepper::DRIVER, 2, 5); // pins for my setup
const byte enablePin = 8; // my setup needs the enable pin
void setup()
{
pinMode(enablePin, OUTPUT);
digitalWrite(enablePin, LOW);
// swapped order of setting maxSpeed and speed
neutralStepper.setMaxSpeed(2000);
neutralStepper.setSpeed(100);
}
void loop()
{
neutralStepper.runSpeed();
}
groundFungus:
Then I rearranged the order of setting maxSpeed and speed and it now the speed is controlled by the setSpeed function. The setMaxSpeed function must be there or the motor goes back to 1 step per second no matter the speed setting.
Interesting, thanks for taking the trouble. It does not mention that interdependence in the documentation.
The reason that I tried the swap is something that I read in the reference for the moveTo() function.
Caution: moveTo() also recalculates the speed for the next step. If you are trying to use constant speed movements, you should call setSpeed() after calling moveTo().
I wondered if the same thing applied to the setMaxSpeed() function for some reason. It looks to me like setSpeed() should be called right before any constant speed run function.
groundFungus:
I tried your code from the OP on my Uno with a NEMA17 bipolar stepper and A4988 driver set to single step and indeed the stepper moves at about 1 step per second no matter the set speed.
Then I rearranged the order of setting maxSpeed and speed and it now the speed is controlled by the setSpeed function. The setMaxSpeed function must be there or the motor goes back to 1 step per second no matter the speed setting.
Thank you very much, I've realized that max speed is 1 or 0 by default, so calling setSpeed before setMaxSpeed was naive of me.