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);
}