Learn

A DRV8825 on an Arduino: wiring, code and 1/32 step

Start building free

Or see every lesson.

  • 455parts on the bench
  • 43boards running now
  • 1.00xreal time, on every board
Arduino Uno: a DRV8825 at 1/32 steplive0.000 s 0.00x
Press Run, then click a mode switch to change the step resolution
M0, M1 and M2 are on 5 V, so the DRV8825 is at 1/32 step and 3200 pulses turn the NEMA 17 half a turn.

The DRV8825 is the driver board sold as an upgrade for the A4988: the same 16 pins in the same places, STEP and DIR in, a NEMA 17 out. It goes to 1/32 of a step where the A4988 stops at 1/16, runs its motor from up to 45 V, and works from a 3.3 V board with no logic supply. Three of its pins differ, and those are where a sketch or a diagram copied from an A4988 guide goes wrong.

The circuit above is an Uno sending 3200 STEP pulses on pin 5 to a DRV8825 and a NEMA 17, then 3200 back, with M0, M1 and M2 on three switches, all on 5 V. That is 1/32 step, so 3200 pulses are half a turn, and the board shows "1/32". The program is the one from the two-driver example, so its serial line also names an A4988; only its second pair of pins is wired here.

For an A4988 on the same motor, the A4988 and NEMA 17 tutorial runs both boards side by side. Every number on this page comes from Mokxi’s engine.

What you need

  • An Arduino Uno or Nano
  • A DRV8825 carrier board
  • A NEMA 17 stepper motor
  • A motor supply of 8.2 to 45 V; the circuit uses 12 V
  • Jumper wires

Wiring

Part and pinGoes toNote
DRV8825 STEPPin 5One step on each rising edge
DRV8825 DIRPin 6Which way
DRV8825 RSTDRV8825 SLPLink them, or nothing moves
DRV8825 M0, M1, M25 V or GNDThe step resolution; all three high is 1/32
DRV8825 VMOT12 VMotor supply, 8.2 to 45 V
DRV8825 GNDGNDShared with the Uno
DRV8825 B1, B2Motor coil ABlack and green
DRV8825 A1, A2Motor coil BRed and blue
DRV8825 FLTNothingA fault output, not a supply

How the DRV8825 differs from the A4988

The trap is the mode pins. Wire an A4988 guide’s "all three high" to a DRV8825 and every move is half as long: the 3200 pulses that turn an A4988 once turn this board half a turn, which is what the circuit above does.

The A4988 and the DRV8825, side by side
A4988DRV8825
Finest step1/161/32
Mode pinsMS1, MS2, MS3M0, M1, M2
All three mode pins high1/161/32
Current limitVREF / (8 × RS)VREF / (5 × RS)
VREF for 1 A on 0.1 ohm0.8 V0.5 V
Motor supply8 to 35 V8.2 to 45 V
Pin above the bottom GNDVDD, the logic supplyFLT, a fault output
A logic high0.7 of VDD2.2 V, fixed
STEP ignored after waking1 ms1.7 ms
Shortest STEP pulse1 µs1.9 µs

M0, M1 and M2: the microstep table

The mode pins are pulled low inside the chip, so a board with nothing on them is in full step. Three patterns give 1/32. In the circuit above, switching M0 to ground leaves M1 and M2 high, which is still 1/32; switching all three to ground is full step, and the 3200 pulses then turn the motor 16 times. Every row below was set on Mokxi’s DRV8825 and read off the board.

DRV8825 step resolution, and pulses for one turn of a 200-step motor
M0M1M2ResolutionSteps a turn
LOWLOWLOWFull step200
HIGHLOWLOW1/2400
LOWHIGHLOW1/4800
HIGHHIGHLOW1/81600
LOWLOWHIGH1/163200
HIGHLOWHIGH1/326400
LOWHIGHHIGH1/326400
HIGHHIGHHIGH1/326400

Vref: the formula that differs

The DRV8825’s limit is I = VREF / (5 × RS). Pololu’s carrier has 0.1 ohm sense resistors, so the limit is twice VREF: 0.5 V is 1 A, which is Mokxi’s default, and a motor rated 1.7 A wants 0.85 V or a little under. Measured on Mokxi’s DRV8825 at 0.5 V, each coil carried 0.707 A at rest, one half-step put the whole 1.000 A in one coil, and at 0.25 V each coil carried 0.354 A.

Using the A4988’s formula on a DRV8825 sets the current far too high: the 0.8 V that is 1 A on an A4988 is 1.6 A here.

The code

The plain sketch toggles STEP and needs no library. With all three mode pins high one turn is 6400 pulses. The pulse is held for 2 microseconds because the DRV8825 wants 1.9, and the sketch waits 2 ms before its first pulse because the chip ignores STEP for 1.7 ms after it wakes. On the circuit above it turned the motor once each way.

A DRV8825 at 1/32 step, one turn each way
const int STEP_PIN = 5;
const int DIR_PIN = 6;
const int STEPS_PER_TURN = 6400;   // 200 full steps x 32

void setup() {
  pinMode(STEP_PIN, OUTPUT);
  pinMode(DIR_PIN, OUTPUT);
  delay(2);   // STEP is ignored for 1.7 ms after the driver wakes
}

void turn(bool forward) {
  digitalWrite(DIR_PIN, forward ? HIGH : LOW);
  for (int i = 0; i < STEPS_PER_TURN; i++) {
    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(2);   // at least 1.9 us high
    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(150);
  }
}

void loop() {
  turn(true);
  delay(500);
  turn(false);
  delay(500);
}

With AccelStepper

AccelStepper drives a DRV8825 in DRIVER mode, STEP first, and setMinPulseWidth(2) gives the longer pulse. At 1/32 a speed of 1600 is a quarter turn a second. With an acceleration of 3200 steps a second squared, this sketch printed "6400 at 4549 ms" at the end of its first turn, then turned back the other way. The arithmetic says 4.5 seconds: half a second up to speed, 3.5 at 1600, half a second to stop. AccelStepper on an Uno tops out near 3900 steps a second in Mokxi, close to the 4000 its notes give for the board, so 1600 leaves room; the AccelStepper guide has that, and run(), homing and MultiStepper.

AccelStepper with a DRV8825
#include <AccelStepper.h>

AccelStepper stepper(AccelStepper::DRIVER, 5, 6);   // STEP, DIR

void setup() {
  Serial.begin(115200);
  stepper.setMinPulseWidth(2);    // the DRV8825 wants 1.9 us
  stepper.setMaxSpeed(1600);      // a quarter turn a second at 1/32
  stepper.setAcceleration(3200);
  stepper.moveTo(6400);           // one turn
}

void loop() {
  if (stepper.distanceToGo() == 0) {
    Serial.print(stepper.currentPosition());
    Serial.print(" at ");
    Serial.print(millis());
    Serial.println(" ms");
    stepper.moveTo(-stepper.currentPosition());
  }
  stepper.run();
}

Arduino Nano, and 3.3 V boards

A Nano has the Uno’s ATmega328P, so it takes the same sketches. With the driver on D5 and D6, the plain sketch above, built for a Nano, turned the motor once in the first turn as it does on the Uno.

The DRV8825 reads a high at 2.2 V whatever its supply, because it has no logic supply pin and makes its own from VMOT. So an ESP32 drives it directly: on an ESP32-C3 the 50 pulses that an A4988 with VDD on 5 V ignored turned the DRV8825’s motor 90 degrees.

FLT sits where the A4988’s VDD is, so a board wired for an A4988 puts 5 V on it. Pololu’s carrier has a 1.5 k resistor in series with FLT, which makes that safe, and in Mokxi FLT never reports a fault, so the motor turned with FLT on 5 V just as it did with FLT on nothing.

Waking up takes 1.7 ms, not 1

After SLP goes high the DRV8825 ignores STEP for 1.7 ms while its charge pump comes up, where the A4988 waits 1 ms. A sketch that wakes a driver and steps at once loses its first step, and on a DRV8825 it loses it for longer. We drove SLP and RST of both boards from one pin and sent the first of 50 pulses 1.2 ms after waking: the A4988 took it, and the DRV8825’s motor ended one step, 1.8 degrees, short of the A4988’s. Sent 2 ms after waking, both took it.

Questions

What is the difference between the DRV8825 and the A4988?

The DRV8825 goes to 1/32 step, runs its motor from 8.2 to 45 V instead of 8 to 35, has no logic supply pin and reads 3.3 V logic directly, and limits the current at VREF / (5 × RS) instead of VREF / (8 × RS). All three mode pins high is 1/32 on a DRV8825 and 1/16 on an A4988.

What is the DRV8825 Vref formula?

I = VREF / (5 × RS). With the 0.1 ohm sense resistors on Pololu’s board that is twice VREF, so 0.5 V is a 1 A limit.

Do I connect FLT to 5 V on a DRV8825?

You do not need to. FLT is a fault output where the A4988 has VDD. Pololu’s carrier puts a resistor in series with it so that an A4988 wiring with 5 V on that pin is safe.

Does the DRV8825 work with a 3.3 V board?

Yes. Its inputs read 2.2 V as high whatever the supply, so an ESP32 or a Raspberry Pi Pico drives STEP and DIR directly.

Which library works with a DRV8825?

Any STEP and DIR library. AccelStepper in DRIVER mode, with setMinPulseWidth(2), and BasicStepperDriver are both built into Mokxi.

Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.