Source: https://mokxi.com/learn/arduino-drv8825

Learn

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

Written by the Mokxi team

Start building free

Or see every lesson.

- 455 parts on the bench
- 43 boards running now
- 1.00x real time, on every board

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 pin | Goes to | Note

DRV8825 STEP | Pin 5 | One step on each rising edge

DRV8825 DIR | Pin 6 | Which way

DRV8825 RST | DRV8825 SLP | Link them, or nothing moves

DRV8825 M0, M1, M2 | 5 V or GND | The step resolution; all three high is 1/32

DRV8825 VMOT | 12 V | Motor supply, 8.2 to 45 V

DRV8825 GND | GND | Shared with the Uno

DRV8825 B1, B2 | Motor coil A | Black and green

DRV8825 A1, A2 | Motor coil B | Red and blue

DRV8825 FLT | Nothing | A 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
| A4988 | DRV8825

Finest step | 1/16 | 1/32

Mode pins | MS1, MS2, MS3 | M0, M1, M2

All three mode pins high | 1/16 | 1/32

Current limit | VREF / (8 × RS) | VREF / (5 × RS)

VREF for 1 A on 0.1 ohm | 0.8 V | 0.5 V

Motor supply | 8 to 35 V | 8.2 to 45 V

Pin above the bottom GND | VDD, the logic supply | FLT, a fault output

A logic high | 0.7 of VDD | 2.2 V, fixed

STEP ignored after waking | 1 ms | 1.7 ms

Shortest STEP pulse | 1 µs | 1.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
M0 | M1 | M2 | Resolution | Steps a turn

LOW | LOW | LOW | Full step | 200

HIGH | LOW | LOW | 1/2 | 400

LOW | HIGH | LOW | 1/4 | 800

HIGH | HIGH | LOW | 1/8 | 1600

LOW | LOW | HIGH | 1/16 | 3200

HIGH | LOW | HIGH | 1/32 | 6400

LOW | HIGH | HIGH | 1/32 | 6400

HIGH | HIGH | HIGH | 1/32 | 6400

## 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

## 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

## 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.

Related

## Keep going

Arduino A4988 and NEMA 17 Stepper: Wiring and Code A4988 Pinout: Pins, Microstep Table and Vref AccelStepper Arduino Library: Examples and Homing Stepper Motor Vibrating but Not Turning: Fixes Stepper Motor Wiring: 4, 5 and 6 Wire Motors How the A4988 and DRV8825 are modeled The Arduino Nano simulator The stepper motor simulator

Sources

## Where the facts on this page come from

- Pololu DRV8825 carrier: the mode table, the current limit, FLT and its resistor, 8.2 to 45 V
- Texas Instruments DRV8825 datasheet

## Build this for real

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

Start building free Open the editor
