Site icon AranaCorp

Using a DRV8825 stepper motor controller

In this tutorial, we’ll show you how to drive a bipolar stepper motor using a DRV8825 driver. This tutorial is compatible with stepper motor drivers commonly used in digital milling or 3D printer projects (DRV8825, SilentStepStick, etc.).

Hardware

Operating principle

Stepper motor drivers enable efficient motor control using just two control signals, STEP and DIR. The number of pulses sent to the driver corresponds to the number of steps taken, the pulse frequency to the motor speed, and the dir signal to the direction of motor rotation. The DRV8825 module takes care of sending the sequence to the two motor coils according to the commands received as input.

Technical specifications DRV8825

M0M1M2Microstep resolution
LowLowLowFull step
HighLowLow1/2 step
LowHighLow1/4 step
HighHighLow1/8 step
LowLowHigh1/16 step
HighLowHigh1/32 step
LowHighHigh1/32 step
HighHighHigh1/32 step

Diagram

Before connecting your motor to the driver, please set the current limiter correctly. This requires:

MaxCurrent=Vref x 2 

For example:

If the current value is 1A, the value displayed on the multimeter must be equal to 0.5V.

MaxCurrent=1.0A –> Vref = 0.5V

It is possible to modify the driver step resolution for greater precision. This configuration is defined by setting pins M0, M1 and M2 to HIGH or LOW according to the following logic table.

M0M1M2Microstep resolution
LowLowLowFull step
HighLowLow1/2 step
LowHighLow1/4 step
HighHighLow1/8 step
LowLowHigh1/16 step
HighLowHigh1/32 step
LowHighHigh1/32 step
HighHighHigh1/32 step

Code

To drive the stepper motor driver, we simply send a HIGH or LOW state to the DIR pin and a pulse to the STEP pin.

const int stepPin = 2;
const int dirPin = 3;


const int stepsPerRev=200;
int pulseWidthMicros = 100;  // microseconds
int millisBtwnSteps = 1000;

void setup() {
  Serial.begin(9600);
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
 
  Serial.println(F("A4988 Initialized"));
}

void loop() {
  Serial.println(F("Running clockwise"));
  digitalWrite(dirPin, HIGH); // Enables the motor to move in a particular direction
  // Makes 200 pulses for making one full cycle rotation
  for (int i = 0; i < stepsPerRev; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(millisBtwnSteps);
  }
  delay(1000); // One second delay

  Serial.println(F("Running counter-clockwise"));
  digitalWrite(dirPin, LOW); //Changes the rotations direction
  // Makes 400 pulses for making two full cycle rotation
  for (int i = 0; i < 2*stepsPerRev; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(millisBtwnSteps);
  }
  delay(1000);
}

For more functionality, you can use the AccelStepper.h library.

Applications

Sources

Exit mobile version