#include <AccelStepper.h> // https://github.com/adafruit/AccelStepper/blob/master/AccelStepper.h
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1 // set to 1 when using a driver board
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin); // Create instance of AccelStepper class:
int maxSpeed = 800; // maximum steps per second
int accelRate = 100; // rate of acceleration
void setup() {
stepper.setMaxSpeed(maxSpeed);
stepper.setAcceleration(accelRate);
}
void loop() {
stepper.moveTo(1600); // Set the target position: (blocking)
stepper.runToPosition(); // Run to target position with set speed and accel/decel
delay(1000);
stepper.moveTo(0); // Move back to zero (blocking)
stepper.runToPosition(); // run to target position with set speed and accel/decel
delay(1000);
}
/*
+-------------------------+
LOW=ENBL | ENABLE A4988 VMOT | 8-35vdc ---+ 100uf electro cap
| MS1 GND | gnd -------+ pwr spike protect
| MS2 2B | stepper 2B
| MS3 2A | stepper 2A
SLP | RESET 1A | stepper 1A
RST | SLEEP 1B | stepper 1B
Pin 3 | STEP VDD | 5vdc
Pin 2 | DIR GND | gnd
+-------------------------+
MS1 MS2 MS3 Step resolution
Low Low Low Full step
High Low Low 1/2 step
Low High Low 1/4 step
High High Low 1/8 step
High High High 1/16 step
SET DRIVER CURRENT LIMIT
1. Power A4988 driver (Vdd, GND)
2. Connect RST to SLP
3. Disconnect motor
4. Apply USB power
5. Calculate current limit: Current Limit = Vref ÷ (8 × Rcs)
6. A current limit of 1A (standard) needs Vref of 540mV
7. Adjust POT while measuring Vref at GND to POT (metal screw)
8. If the motor is making a lot of noise, lower the current limit
*/