Arduino MKR WiFi 1010 - DRV8825 Stepper Motor Driver

In this guide, we will look at the DRV8825 Stepper Motor Driver and learn how to use it with the Arduino MKR WiFi 1010 to control the stepper motor. We will explain:

Arduino MKR WiFi 1010 DRV8825 module

Hardware Preparation

1×Arduino MKR WiFi 1010
1×Micro USB Cable
1×Stepper Motor Nema 17
1×DRV8825 Stepper Motor Driver
1×Expansion Board for DRV8825 Motor Driver
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires

Or you can buy the following kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of DRV8825 Stepper Motor Driver

The DRV8825 is a well-known module that controls bipolar stepper motors. You'll see it used in CNC machines, 3D printers, and robots. It lets you adjust the current, protects against getting too hot, and offers different stepping options, from full-steps to small 1/32 steps. It can handle up to 2.2A per motor coil with proper cooling and works with voltages between 8.2V and 45V, making it suitable for many stepper motors.

To learn about stepper motor basics like full-step, microstepping, unipolar stepper, and bipolar stepper, visit the Arduino MKR WiFi 1010 - Stepper Motor guide.

With only two pins on an Arduino MKR WiFi 1010 board, you can easily control how fast a NEMA 17 bipolar stepper motor moves and which way it turns.

DRV8825 Stepper Motor Driver Pinout

DRV8825 module Pinout

The DRV8825 Stepper Motor Driver has 16 pins. Here is a common pin layout for the DRV8825 board. Remember that some versions might use slightly different names for the pins, but their functions remain the same.

Pin Name Description
VMOT Motor power supply (8.2 V to 45 V). This powers the stepper motor.
GND (for Motor) Ground reference for the motor power supply. Connect this pin to the GND of the motor power supply
2B, 2A Outputs to Coil B of the stepper motor.
1A, 1B Outputs to Coil A of the stepper motor.
FAULT Fault Detection Pin. This is an output pin that drives LOW whenever the H-bridge FETs are disabled as the result of over-current protection or thermal shutdown.
GND (for Logic) Ground reference for the logic signals. Connect this pin to the GND of Arduino MKR WiFi 1010
ENABLE Active-Low pin to enable/disable the motor outputs. LOW = Enabled, HIGH = Disabled.
M1, M2, M3 Microstepping resolution selector pins (see table below).
RESET Active-Low reset pin - pulling this pin LOW resets the driver.
SLEEP Active-Low sleep pin - pulling this pin LOW puts the driver into low-power sleep mode.
STEP Step input - a rising edge on this pin advances the motor by one step (or one microstep, depending on microstepping setting).
DIR Direction input - sets the rotation direction of the stepper motor.

A small adjustable knob is included that allows you to set the current limit. This helps prevent the stepper motor and driver from overheating.

To sum up, these 16 pins are divided into groups based on what they do:

  • Wires connected to the stepper motor: 1A, 1B, 2A, 2B.
  • Wires connected to the Arduino MKR WiFi 1010 for controlling the driver: ENABLE, M1, M2, M3, RESET, SLEEP.
  • Wires connected to the Arduino MKR WiFi 1010 for controlling motor direction and speed: DIR, STEP.
  • Wire for sending error messages to the Arduino MKR WiFi 1010: FAULT.
  • Wires connected to the motor’s power source: VMOT, GND (motor power ground).
  • Wire connected to the Arduino MKR WiFi 1010’s ground: GND (logic ground).

The DRV8825 board does not need power from the Arduino MKR WiFi 1010 board for its logic because it gets power from the motor’s source through its own 3.3V voltage regulator. However, you must connect the Arduino MKR WiFi 1010 board's ground to the DRV8825 board's GND (logic) pin to ensure both share a common ground and work properly.

Microstep Configuration

The DRV8825 driver lets you divide each step into smaller parts, which is called microstepping. It works by sending different amounts of current to the motor coils.

For example, a NEMA 17 motor that moves 1.8 degrees at a time, taking 200 steps to go all the way around.

  • Full-step mode: The motor moves 200 times for one complete turn.
  • Half-step mode: The motor moves 400 times for one complete turn.
  • Quarter-step mode: The motor moves 800 times for one complete turn.
  • Eighth-step mode: The motor moves 1600 times for one complete turn.
  • Sixteenth-step mode: The motor moves 3200 times for one complete turn.
  • Thirty-second-step mode: The motor moves 6400 times for one complete turn.

When you increase the microstepping, the motor works more smoothly and accurately, but it needs more steps for a full rotation. If you keep the step pulse rate the same, each complete rotation will take longer, slowing down the motor.

If your microcontroller sends pulses quickly enough to match the higher number of steps, you can maintain or even increase the speed. The real limit is how fast both the driver and the microcontroller can process these pulses without skipping any steps.

DRV8825 Microstep Selection Pins

The DRV8825 has three input pins called M0, M1, and M2 for selecting the microstep resolution. By changing these pins to high or low signals, you can choose from six different microstepping resolutions.

M0 Pin M1 Pi M2 Pi Microstep Resolution
Low Low Low Full step
High Low Low Half step
Low High Low 1/4 step
High High Low 1/8 step
Low Low High 1/16 step
High Low High 1/32 step
Low High High 1/32 step
High High High 1/32 step

These small pins for choosing steps have built-in resistors that keep them naturally set to a low state. If you do not connect them, the motor will operate in full-step mode.

How it Works

To use a stepper motor with the DRV8825 board, you need at least two pins from the Arduino MKR WiFi 1010 board. One pin is used for direction and another for steps. The DRV8825 board reads these signals from the Arduino to move the motor correctly.

  • STEP Pin: Every pulse on this pin makes the motor move by one small step. Sometimes it makes a full step, based on the microstepping setup.
  • DIR Pin: This pin determines the direction in which the motor rotates.

The driver takes these signals and its own settings to send commands to the motor through the 1A, 1B, 2A, and 2B pins.

You can also configure extra pins on the DRV8825 module (ENABLE, M1, M2, M3, RESET, SLEEP) using three different methods.

  • Leave them unconnected so the driver uses its normal settings.
  • Hook them directly to GND or VCC for a constant mode.
  • Connect them to the Arduino MKR WiFi 1010 pins so you can control them with your code.

Wiring Diagram between Arduino MKR WiFi 1010, DRV8825 module and Stepper Motor

The diagram below shows how to connect the Arduino MKR WiFi 1010, the DRV8825 module, and the stepper motor. The DRV8825 driver works in its normal mode, called full-step.

The wiring diagram between Arduino MKR WiFi 1010 DRV8825 stepper motor driver

This image is created using Fritzing. Click to enlarge image

With all the details:

  • VMOT: Connect this to the motor's power supply (for example, 12V).
  • GND (for Motor): Connect this to the ground of the motor's power supply.
  • 1A, 1B, 2A, 2B: Attach these to the stepper motor coils.
  • STEP: Connect this to digital pin D4 on the Arduino MKR WiFi 1010.
  • DIR: Connect this to digital pin D3 on the Arduino MKR WiFi 1010.
  • GND (for Logic): Connect this to the Arduino MKR WiFi 1010's ground pin.
  • Other pins: Leave these not connected.

Arduino MKR WiFi 1010 Code

/* * This Arduino MKR WiFi 1010 code was developed by newbiely.com * * This Arduino MKR WiFi 1010 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-drv8825-stepper-motor-driver */ // Include the AccelStepper Library #include <AccelStepper.h> // Define pin connections #define DIR_PIN 3 #define STEP_PIN 4 // Creates an instance AccelStepper stepper(AccelStepper::DRIVER, STEP_PIN, DIR_PIN); void setup() { // set the maximum speed, acceleration factor, // initial speed and the target position stepper.setMaxSpeed(1000); stepper.setAcceleration(200); stepper.setSpeed(200); stepper.moveTo(200); } void loop() { // Change direction once the motor reaches target position if (stepper.distanceToGo() == 0) stepper.moveTo(-stepper.currentPosition()); stepper.run(); // Move the motor one step }

Detailed Instructions

New to Arduino MKR WiFi 1010? Complete our Getting Started with Arduino MKR WiFi 1010 tutorial first to set up your development environment.

  • Connect the components to the Arduino MKR WiFi 1010 board as depicted in the diagram
  • Plug your Arduino MKR WiFi 1010 into your computer's USB port
  • Launch the Arduino IDE on your computer
  • Select the Arduino MKR WiFi 1010 board and its COM port
  • Copy the code and open it in the Arduino IDE.
  • Click on the Libraries icon on the left side of the Arduino IDE.
  • Type AccelStepper in the search box, then find the AccelStepper library by Mike McCauley.
  • Click the Install button to add the AccelStepper library.
Arduino MKR WiFi 1010 AccelStepper library
  • Copy the code and paste it into the Arduino IDE.
  • Click the Upload button in the Arduino IDE to transfer the code to your Arduino MKR WiFi 1010.
  • You will see the motor turn back and forth.

When you use the motor in full-step mode, its movement might feel a bit rough, which is common. To make it move more smoothly, switch on microstepping by configuring the M1, M2, and M3 pins.

Video Tutorial

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!