AccelStepper remowing deceleration

Hi guys,

I’m writing a code, for a focuser, that is controlled with my UNO through serial port. I've managed to write and setup everything, but I have a problem. The motor makes one revolution and then stops, everything is fine, but if I need to stop the motor somewhere in betwen, the motor doesn’t stop immediately, it takes about 1 second to stop. Is it possible to hack the code, so I have just a soft start?

I've tried to turn off the stepping pulse with an optocoupler, it works, but then, the motor doesn’t make just one revolution... If you hit stop, the motor stops, and takes the stopping place for the step 0.

Thank you for your suggestions :slight_smile:

The whole point of a stepper motor is that it can be precisely controlled to a single step.

For it to "take 1 second to Stop" means your code and / or hardware must be wrong.

You need to post your code and circuit diagram and motor details for anyone to be able to help.

Yes of course, here is the code:
I am driving one stepper motor (200 steps per revolution) with an A4988 driver at 1/16 microsteping.

#include <AccelStepper.h>

int motorSpeed=1000; 
int motorAccel = 500;
int LeftTurnUp = 0;
int RightTurnDown = 0;
String incomingByte;   // for incoming serial data


AccelStepper stepper(1, 2, 4); // set up the stepper as 4 wire bipolair on pin 4,5,6,7

void setup()
{
  Serial.begin(9600);
  
  stepper.setMaxSpeed(motorSpeed);
  //stepper.setSpeed(motorSpeed);
  stepper.setAcceleration(motorAccel);
  
  

}

void loop()
{
Serial.setTimeout (10);
  if (Serial.available() > 0) 
  {  
    incomingByte = Serial.readString();
  
    {
      if (incomingByte == "1")
      {
        
        LeftTurnUp = 1;
        RightTurnDown = 0;
      } 
      
      if (incomingByte == "2")
      {
        
        RightTurnDown = 1;
        LeftTurnUp = 0;
      }

      if (incomingByte == "3")
      {
        LeftTurnUp = 0;
        RightTurnDown = 0;
        stepper.stop();     //////////////////////////////when i send 3, the motor still has to deceralate, and makes some steps before it stops. 
       
      
        
      }
      
    }
  }

  if (LeftTurnUp == 1)  //left turn
  {
    stepper.moveTo(3200); //move one rotation
  }

  if (RightTurnDown == 1)  //right turn
  {
    stepper.moveTo(0); //move to starting point
  }


  stepper.run();
}

Should stepper.run( ) be hung out there unconditionally?
Does it execute the last stepper.moveTo( ) always?
Might be OK though, docs are not clear to me at a quick reading.

The stepper.run() was already in the original code, and without it, the steper doesent run :slight_smile:

Well i would just like to remove the soft stop so that the motor stops immediately.

here is a link, it looks the same... Is it even posible to stop the motor immediately?

Why don't you read what I wrote? Your comment does not address my concern.

As I recall, the stepper.moveTo only moves when stepper.run is executed. Quit executing stepper.run when you want it to stop.

The stepper.stop uses the acceleration time to stop the motor slowly. I can see a use if you were using a stepper to drive an big load like a flywheel, I can see the need. Why use the acceleration? Just use the constant speed commands.