not working fine... NEMA 11, 2DM542 Driver, Arduino Uno

So I need to make a code that makes the stepper motor go to one set direction and then come back.

Then it need to accelerate to one direction and decelerate to a set point and the same back.

Then I need to accelerate and quick stop at one point.

The Motor is NEMA 11
the driver 2DM542
The power supply 24V 8A

I cannot even make it go fast. I am just staring at it for 5 hours rotating very slowly whatever change I make to the code.

#include <AccelStepper.h>

#define STEPPER_X_DIR_PIN 4
#define STEPPER_X_STEP_PIN 3

// 1mm = (no. of steps per rev)/(linear distance moved per rev)
// 1/16th resolution so 1mm = 3200/38 = 84.2 steps

int distanceToMove = 1000; //(mm)
int numberOfSteps = distanceToMove*84.2;

// Define a stepper and the pins it will use
AccelStepper stepper;
AccelStepper stepperX(AccelStepper::DRIVER, STEPPER_X_STEP_PIN, STEPPER_X_DIR_PIN);

void setup() {
// put your setup code here, to run once:
stepper.setMaxSpeed(30000);
stepper.setAcceleration(1000);

}

void loop() {
// put your main code here, to run repeatedly:

// go forwards
stepper.move(numberOfSteps);
stepper.runToPosition(); // stepper shall start from speed 200, but it starts from speed 0;

delay(1000);

// Now go backwards
stepper.move(-numberOfSteps);
stepper.runToPosition();

delay(1000);

}

Images from Original Post so we don't have to download them. See this Simple Image Guide

...R

Post a link to the datasheet for your stepper driver.

Start by getting the motor moving at a very slow speed - perhaps a max of 100 steps per second and acceleration of 10 steps per second per second.

if that does what it should then gradually try higher speeds and also gradually try higher accelerations. AFAIK the AccelStepper library is incapable of 30,000 steps per second.

...R
Stepper Motor Basics
Simple Stepper Code