Steppers on A4988 and DRV8825, on an Arduino Uno
STEP and DIR into an A4988 and a DRV8825, each turning a NEMA 17. The same pulses to both, and the DRV8825 turns half as far. The whole build, an Arduino Uno and 4 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
IntermediateRuns in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Steppers on A4988 and DRV8825: STEP, DIR, and nothing else.
//
// pin 3 the A4988's STEP pin 4 its DIR
// pin 5 the DRV8825's STEP pin 6 its DIR
// both VMOT on 12 V, the grounds to the Uno's GND, RST linked to SLP,
// all three mode pins on 5 V
// A4988 VDD on 5 V; its motor on 1A/1B and 2A/2B
// DRV8825 its motor on A1/A2 and B1/B2
//
// A stepper driver takes two wires from a sketch. DIR says which way; each
// rising edge on STEP moves the motor one step. Everything else, the two coil
// currents and the order they go in, is the driver's job. That is the whole
// reason these boards exist, and why a sketch for one is a loop that toggles
// a pin. This one toggles two, one for each driver, at the same moment, so
// both get exactly the same pulses.
//
// # One pulse, two different steps
//
// Both drivers have their three mode pins tied high. On the A4988 that is
// 1/16 step; on the DRV8825 the same three pins mean 1/32. So 3200 pulses turn
// the top motor exactly once and the bottom one exactly half a turn. Moving a
// sketch from one board to the other without reading the table is a classic
// way to build a printer that prints at half size.
//
// # The link from RST to SLP
//
// RST floats on these boards and a floating reset holds the driver off. Take
// the link away and nothing moves: the outputs stay off and the board shows
// "off".
//
// # How fast
//
// 400 us a pulse at 1/16 is 156 full steps a second for the top motor, well
// under the thousand a NEMA 17 follows from a standstill. Try 20 us and watch
// the rotors fall behind and slip.
const int STEP_A = 3;
const int DIR_A = 4;
const int STEP_B = 5;
const int DIR_B = 6;
const unsigned int PULSES = 3200; // one turn at 1/16, half a turn at 1/32
const unsigned int PERIOD_US = 400;
void turn(bool forward) {
digitalWrite(DIR_A, forward ? HIGH : LOW);
digitalWrite(DIR_B, forward ? HIGH : LOW);
for (unsigned int i = 0; i < PULSES; i++) {
digitalWrite(STEP_A, HIGH);
digitalWrite(STEP_B, HIGH);
delayMicroseconds(4);
digitalWrite(STEP_A, LOW);
digitalWrite(STEP_B, LOW);
delayMicroseconds(PERIOD_US - 4);
}
}
void setup() {
pinMode(STEP_A, OUTPUT);
pinMode(DIR_A, OUTPUT);
pinMode(STEP_B, OUTPUT);
pinMode(DIR_B, OUTPUT);
Serial.begin(115200);
Serial.println("Mokxi Uno: 3200 pulses to an A4988 and a DRV8825");
// The drivers ignore STEP for a millisecond or two after they wake.
delay(10);
}
void loop() {
Serial.println("forward: A4988 one turn, DRV8825 half a turn");
turn(true);
delay(800);
Serial.println("and back");
turn(false);
delay(800);
}
Parts list
14 parts, plus the jumper wires. Every one is in the editor's parts bin.
- 1 × Arduino Uno R3
- 1 × Stepper driver, A4988
- 1 × Stepper driver, DRV8825
- 2 × Stepper motor, NEMA 17
- 2 × Power, 12 V
- 7 × Power
How it is wired
26 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND
- Arduino Uno R3 pin 6; Stepper driver, DRV8825 pin DIR
- Arduino Uno R3 pin 5; Stepper driver, DRV8825 pin STEP
- Arduino Uno R3 pin 4; Stepper driver, A4988 pin DIR
- Arduino Uno R3 pin 3; Stepper driver, A4988 pin STEP
- Supply: Stepper driver, A4988 pin MS1
- Supply: Stepper driver, A4988 pin MS2
- Supply: Stepper driver, A4988 pin MS3
- Stepper driver, A4988 pin RST; Stepper driver, A4988 pin SLP
- 12 V: Stepper driver, A4988 pin VMOT
- Stepper driver, A4988 pin 2B; Stepper motor, NEMA 17 (1) pin A1
- Stepper driver, A4988 pin 2A; Stepper motor, NEMA 17 (1) pin A2
- Stepper driver, A4988 pin 1A; Stepper motor, NEMA 17 (1) pin B1
- Stepper driver, A4988 pin 1B; Stepper motor, NEMA 17 (1) pin B2
- Supply: Stepper driver, A4988 pin VDD
- Ground: Stepper driver, A4988 pin GND
- Supply: Stepper driver, DRV8825 pin M0
- Supply: Stepper driver, DRV8825 pin M1
- Supply: Stepper driver, DRV8825 pin M2
- Stepper driver, DRV8825 pin RST; Stepper driver, DRV8825 pin SLP
- 12 V: Stepper driver, DRV8825 pin VMOT
- Stepper driver, DRV8825 pin B2; Stepper motor, NEMA 17 (2) pin A1
- Stepper driver, DRV8825 pin B1; Stepper motor, NEMA 17 (2) pin A2
- Stepper driver, DRV8825 pin A1; Stepper motor, NEMA 17 (2) pin B1
- Stepper driver, DRV8825 pin A2; Stepper motor, NEMA 17 (2) pin B2
- Ground: Stepper driver, DRV8825 pin GND
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.