I'm using AccelStepper for a simple stepper sketch. I don't need the acceleration feature, I would like the stepper to start and stop as fast as possible. I set acceleration to a very high value but ideally I'd like to disable it altogether.
Can someone point me to the right direction?
void setup() {
// set the maximum speed, acceleration factor,
// initial speed and the target position
myStepper.setMaxSpeed(3500);
myStepper.setAcceleration(100000);
myStepper.setSpeed(1500);
myStepper.moveTo(355);
myStepper.runToPosition();
delay(100);
myStepper.moveTo(0);
myStepper.runToPosition();
delay(1000);
pinMode (XTIDE, INPUT);
pinMode (enable, OUTPUT);
Serial.begin(9600);
}
void loop() {
Activity = digitalRead(XTIDE);
if (Activity == 1) {
// Activity = digitalRead(XTIDE);
Seek = random(0, 355);
digitalWrite(enable, 1);
myStepper.moveTo(Seek);
myStepper.runToPosition();
digitalWrite(enable, 0);
Bob = random(10, 500);
delay(Bob);
}
}
Then set the acceleration as high as possible. If you set it higher than possible then the motor will loose steps and will not start and stop as fast as possible.
Poll the motor and step it if a step is due, implementing a constant speed as set by the most recent call to [setSpeed()]. You must call this as frequently as possible, but at least once per step interval,
Returns
true if the motor was stepped.
Right now my sketch does not call for the stepper function more than once. I use runToPosition and the stepper just does that.
runSpeed would need a change in the code, right?
Is there a command similar to runToPosition which does not account for acceleration?
Yes, you answered your own question. Use one pin for direction and pulse another pin for step. As long as you don't pulse the pin too fast (probably keep it under 500 steps/second) that will work.
Executes [runSpeed()] unless the targetPosition is reached. This function needs to be called often just like [runSpeed()] or [run()]. Will step the motor if a step is required at the currently selected speed unless the target position has been reached. Does not implement accelerations.
Returns
true if it stepped
So I need to keep calling until it returns true?
I'm not a developer, please forgive me if I am saying rubbish
well, that's what I am doing so the solution would be in post #1!!!!!!!
I was hoping for a cleaner solution, a library - or a parameter within this library - which allowed to move the stepper without even considering the acceleration - which is my original question.