fbpixel
Tags: ,
0
(0)

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

Hardware

  • Arduino UNO
  • Stepper driver A4988
  • USB A male to USB B male cable

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 A4988 module takes care of sending the sequence to the two motor coils according to the commands received as input.

Technical specifications A4988

Minimum operating voltage8 V
Maximum operating voltage35 V
Continuous current per phase1.2 A
Maximum current per phase2 A
Minimum logic voltage3 V
Maximum logic voltage5.5 V
Microstep resolutionfull, 1/2, 1/4, 1/8 and 1/16
Reverse voltage protection?No
Dimensions15.5 × 20.5 mm (0.6″ × 0.8″)

Diagram

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

  • supply the Arduino and Shield with Motor voltage.
  • Then place a voltmeter between the potentiometer and GND.
  • Turn the potentiometer with a screwdriver until you obtain the value that follows the following rule.
MaxCurrent=Vref x 2.5 

For example:

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

MaxCurrent=1.0A –> Vref = 0.4V

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.

MS1MS2MS3Résolution Microstepping
LowLowLowPas complet (full step)
HighLowLow1/2 pas
LowHighLow1/4 de pas
HighHighLow1/8 ième de pas
HighHighHigh1/16 ième de pas

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

  • Stepper motor control
  • Controlling multiple motors with a CNC Shield

Sources

https://www.arduinolibraries.info/libraries/accel-stepper

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?