Stepper motor keeps restarting in between

Hi, I need to rotate the stepper motor to 16200 steps over 15 seconds using acceleration and deceleration. Even with basic code, the stepper motor keeps restarting in between as you can in the attached video clip here. I am not sure what is causing this and I would love some guidance how to fix this.

I am using stepper driver DRV8825, Potentiometer Vref is 0.57V. Max current in the stepper motor is 1.2A. Power input to the driver is 12V DC and 2A.

57SHY4301-4A-0 规格书.pdf (276.8 KB)

#include <AccelStepper.h>

// Define pin assignments
#define dirPin 7
#define stepPin 8


// Define stepper motor parameters

const float maxSpeed = 1350; // Max speed (steps per second)
const float setAcceleration = 450; // Acceleration (steps per second^2)

AccelStepper stepper(AccelStepper::DRIVER, stepPin, dirPin);


void setup() {
  Serial.begin(9600);

  stepper.setCurrentPosition(0);
  stepper.setMaxSpeed(maxSpeed); 
  stepper.setAcceleration(setAcceleration); 
  
}

void loop() {

  stepper.moveTo(16200);
  while (stepper.distanceToGo() != 0) {
  stepper.run();
  
  }
  
  }



Great job posting the code! To help us assist you further, please include an annotated schematic that shows exactly how everything is connected. Be sure to include all power, ground, and power sources in the schematic. There is the possibility this is an EMI problem.

Thank you! Attaching images here and also uploaded quick video here

Power supply to Arduino is through laptop, USB connection & Power supply to the bread board is through 12V/2A DC adapter.

Data sheet for the motor says 2.28vdc.

Driver circuit requires 8.2V and higher so I used 12V. I believe only current level is important for the stepper motor to work or I maybe wrong?

You are right

Long rats nest wiring not helping.

Try:

void loop() {

  stepper.moveTo(16200);
  while (stepper.distanceToGo() != 0) {
    stepper.run();
   }
  while(1); // press reset to repeat
  }

Thank you! I tried but still the same problem. I am going to rewire and organize better.

Thank you all for all your input and for helping to fix this! Its finally working now! :slight_smile:

I re-wired the entire circuit and also changed the Arduino board with a new one. I think it was the Arduino board that was creating issues.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.