/* Example sketch to control a stepper motor
with DRV8825/DRV4498 stepper motor driver, AccelStepper library
and Arduino: acceleration and deceleration.
More info: https://www.makerguides.com */
#include "AccelStepper.h"
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 1
#define stepPin 2
#define motorInterfaceType 1
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
// Set the maximum speed and acceleration(for Halfstepp ca. 70/min) :
stepper.setMaxSpeed(470);
stepper.setAcceleration(400);
}
void loop() {
// Set the target position (8 Revolutions for and Back):
stepper.moveTo(3200);
// Run to target position with set speed and acceleration/deceleration:
stepper.runToPosition();
delay(300);
// Move back to zero:
stepper.moveTo(0);
stepper.runToPosition();
delay(300);
}