Arduino Stepper Drivers-2/2

by R Jordan Kreindler in Circuits > Arduino

18326 Views, 228 Favorites, 0 Comments

Arduino Stepper Drivers-2/2

Arduino Stepper Drivers Tutorial-Cover Photo.jpg
Four-wire stepper.jpg
Four-Wire -1.jpg
Four-wire.jpg
Four-Wire -2.jpg
Four-Wire 1.jpg
Four-Wire 2.jpg
Five-Wire Stepper copy.jpg
Five-Wire Stepper - 2.jpg
28BYJ-48 Pinout.jpg
Five-wire stepper-1.jpg
Five-wire stepper-2.jpg
Five-wire stepper-3.jpg
Six-wire Stepper.jpg
Six-wire stepper-2.jpg
Six-wire steppers.jpg
Six-wire Step Motors-4.jpg
Six-wire.jpg
Six-wire stepper-5.jpg
Six-wire Step Motors-5.jpg
Six-Wire 2.jpg
Six-Wire 1.jpg
Eight-wire stepper.jpg
Eight-wire Steppers.jpg
Eight wire plug.jpg
Eight Wire Stepper.jpg
Frame and length sizes-2.jpg

In Part 1 of this tutorial there was a basic discussion of the type of coils one might find in a stepper motor. Here it is appropriate to be explicit as to what type of stepper motor leads you may find as a Maker, as this information is necessary to appropriately use steppers with stepper driver modules.

Update, November 4, 2016: I just received an email from Instructables.com that they will be promoting this tutorial on Facebook. If you came here as a result of that Facebook promotion, I hope you find this tutorial helpful, interesting, and informative. If after reading this tutorial, you feel you would like to contact me by email, you will find my contact information in the last Step.

There are unipolar and bipolar steppers, and for Makers these can be categorized as 4-wire, 5-wire, 6-wire, and 8-wire. The coils for these steppers can be thought of as shown in the photographs above, which also includes photographs of real world examples of each.

The four wire steppers are bipolar and can be connected to almost any stepper driver, after one determines which leads are attached to each coil. An inexpensive ohmmeter is all that is needed, if data sheets are not available. The ohmmeter is easy to use, as all that's required is to find the lead pairs that are connected to each coil.

We used an example of a five-wire unipolar stepper in Part 1 when we connected one example of a ULN2003 driver module to a five-wire 28BYJ-48 stepper. For the 28BYJ-48 stepper its Red wire is the common wire, and its configuration can be seen above. We can simply leave the Red wire disconnected (see photograph of this stepper disassembled) to obtain a 4-wire bipolar stepper, and thus use each coil's full length, if needed. Please note that although the 28BYJ-48 we used was a five-wire geared stepper, five-wire steppers are not always geared, although many models are (see photographs). Five wire steppers are known as unipolar steppers.

Five-wire steppers without gears are available, some being 6v or 12v rather than 5v. They are usually faster and have fewer steps, but they also have less torque

We will use a 2nd example of a ULN2003 driver board, below, and we will again use a small geared stepper in its five-wire unipolar configuration.

We used an example of a six-wire NEMA 17 stepper where we connected it to the L298N stepper driver in Part 1 of this tutorial. Although there we used it as a bipolar stepper, leaving two wires unattached. A picture of this six-wire stepper is shown above.

The last category of stepper leads, that we are likely to come across, is the eight-wire stepper. This is probably the most flexible category of stepper as it can be employed in unipolar, bipolar series, or bipolar parallel, configurations. Steppers coils for 8-wire steppers can be configured by a user as series or parallel. One of the picture examples showing eight-wire steppers is of a dual (double) shaft stepper, i.e., a stepper with shafts at each end.

If the coils of an eight-wire stepper are placed in series, called bipolar series, the result is a longer coil, and this is the configuration used to obtain the greatest torque. However, it is important to recognize that there is a trade-off between torque and speed. If the coils are placed in a parallel configuration this will result in a higher speed stepper, but one with reduced torque. This is the bipolar parallel configuration.

If we use the parallel approach we might be tempted to assume that the current used will be double . However, most manufacturers recommend that the current, where both coils are in parallel, be set to 1.4 times what it would be for a unipolar configuration, and 0.7 times if the coils are placed in a series configuration. This is likely recommended to avoid damage to the stepper.

Although some sites mention doubling the current, this may prove to be a risky approach for stepper life. A parallel configuration, as it uses more current even if that current is restrained to 1.4 times that used in a unipolar configuration, will result in higher torque and greater speed. However, for most Maker work higher speed is not a requirement, and eight-wire steppers are not usually found in Maker projects.

Before leaving this Introduction I want to mention the idea of "stack(s)". In the first Part of this tutorial I mentioned the NEMA designation. That designation refers to the size of the face plate, or diameter, of a stepper. That is, it is a two dimensional value. However, stepper motors are three dimensional. They have length in addition to face plate dimensions, or diameters. If more torque is desired, a stepper can be "lengthened". For example, NEMA 17 steppers can be found in 1, 2, 3, and 4 stack lengths. A greater "stack" number typically represents both a greater length and a greater torque for the same NEMA size.

Steppers are often selected on the basis of torque requirements and space available. If a longer motor can work, than a greater "stack" size may be appropriate. However, if a longer stepper will not fit, it is possible a larger frame size will do what is needed. A two stack NEMA 17 stepper may have more than 1.5 times the holding torque of a one stack. A three stack NEMA 17 more than 2.5 times, and a four stack more than 3.5 times the holding torque compared to a one stack. Torque ratios for relative stack sizes usually vary with NEMA values. As might be expected, the price of a company's steppers goes up with increases in "stack" size, for the same NEMA size. A company's NEMA 17 1.3" long stepper might list for about $35 while its NEMA 17 stepper 2.6" long might list for almost $300. Thus, the smallest stack size needed should be chosen.

The length of a stepper, its stack size, must be considered when using a stepper driver as current requirements typically differ for different NEMA steppers and stack sizes, and different stepper drivers have different current limitations. (See photographs for steppers of different lengths and frame sizes.)

In Part 1 of this tutorial I presented some general guidelines to follow when using steppers and stepper drivers. Those, guidelines are repeated here, to again bring them together in one place.

1. A stepper should not be disconnected from a stepper motor driver while the driver has current flowing to it, as this may damage the driver module.

2. A separate power supply should be used for a stepper. It should not be driven directly from an Arduino.

3. Do not handle a stepper's case while it is running, or shortly after. Steppers are designed to run hot, some exceeding 175-degrees fahrenheit, and can cause burns if handled inappropriately.

4. In choosing a stepper, select the least costly one that meets your torque requirements, and can move the stepper to the position needed in the time required. "Overspecification" can result in increased cost.

5. It is easy to convert a five-wire or a six-wire unipolar stepper to a four wire bipolar stepper, by not using the center taps, whether these taps are separate or joined. Most stepper drivers will work with four wire bipolar steppers, although many stepper driver modules will also work directly with 5-lead, 6-lead, or 8-lead steppers.

ULN2003 Second Example

ULN2003 Modules.jpg
ULN2003 2nd Example.jpg
ULN2003 2nd Example Weight.jpg
ULN2003 Example 2-3.jpg
ULN2003 Example 2-1.jpg
ULN2003 Example 2-2.jpg
ULN2003 Example 2-4.jpg

In the first part of this Instructable, it was mentioned that there are many versions of ULN2003 stepper driver modules. The first photograph shows three. The second module in that photograph is the driver used in this tutorial's first Part. The third module in that photograph will provide us with a the second example of a ULN2003 module and it will be used below.

This example of a ULN2003 stepper driver module provides pins, so it can be plugged directly into a breadboard, and its associated breadboard sockets used for connections to a stepper and a microprocessor. It does not provide the large LEDs of the first example of the ULN2003 that was used. It is smaller and lighter than the stepper driver module in that example. It weighs approximately 2.7 grams. When run as configured with this ULN2003 module, a 28BYJ-48 stepper motor will get quite hot, and it is advisable if cooler running is desired to include a resistor between the stepper motor and the driver module.

For this example we simply replaced the connections from the first example, and made similar connections to the ULN2003 stepper driver used here. This shows that any ULN2003 stepper driver module is easy to connect, if the example of this driver previously presented was understood when read, or will be reviewed before proceeding.

The connections used ihere are as follows:
Stepper Motor to Driver Module

1. Insert female plug from 28BYJ-48 stepper into male connector on the ULN2003 driver module.

Driver Module (see attached photos to see how this was implemented for this example)

2. Connect In1 (driver module) ---------- Digital socket 2 on the UNO

3. Connect In2 (driver module) ---------- Digital socket 3 on the UNO

4. Connect In3 (driver module) ---------- Digital socket 4 on the UNO

5. Connect In4 (driver module) ---------- Digital socket 5 on the UNO

6. Provide 5 volts power from a wall adapter to pins marked VDD and GND on the driver module.

LCD Module

7. VSS (LCD) ---------- GND

8. VDD (LCD) ---------- 5volts

9. VO (LCD) ------------ Center tap, 10k potentiometer

10. RS (LCD) ---------- Digital socket 13 on the UNO

11. RW (LCD) --------- GND

12. E (LCD) ------------ Digital socket 12 on the UNO

13. D4 (LCD) ---------- Digital socket 11 on the UNO

14. D5 (LCD) ---------- Digital socket 10 on the UNO

15. D6 (LCD) ---------- Digital socket 9 on the UNO

16. D7 (LCD) ---------- Digital socket 8 on the UNO

17. A (LCD) ------------ 5volts

18. K (LCD) ------------ GND. (LCD pins D0 through D3 are left unconnected.)

Power was provided to the potentiometer at both its ends, using 5 volts and ground. Note, the center tap of the potentiometer goes to VO on the LCD.

The 10K potentiometer is used to control the LCD’s contrast. I used a breadboard and connected the 5v and ground connectors on an Arduino UNO to the breadboard’s power rails. I then used these rails to connect to the LCD. Once again, and it is worth repeating, it is not a good idea to power a stepper directly from a UNO. Here a wall adapter was used.

Sketch for Second Example Using a ULN2003 Stepper Motor Driver

ULN2003 2nd Example
UNL2003 with 2nd Stepper

This is the same sketch used in Part 1, but here for a different ULN2003 stepper driver module. The speed of rotation, i.e., RPM, to very close to that in the first example using a ULN2003 module, as is to be expected, since both drivers use the ULN2003 IC for stepper motor control.

The second attached video uses the same ULN2003 stepper driver, but with a different 5-wire geared stepper, a 12v MP24AA. This demonstrates the ULN2003 stepper motor driver can be used with different 5-wire steppers.

Please download the attached text file to see the sketch exactly as written, including white space.

----------Sketch----------

// Sketch by R. Jordan Kreindler, written October 2016, to rotate

// a stepper motor using the Half Step Method and reverse direction

// after approximately a full revolution.

// An LCD is used to show rotation direction, angle(s) turned, and RPM.

int RPM;

unsigned long time;

#include

// LiquidCrystal (RS, E, d4, d5, d6, d7)

LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // For standalone, non-shield, LCD

// Pin assignments

int aPin = 2; //IN1: coil a one end

int bPin = 3; //IN2: coil b one end

int aPrimePin = 4; //IN3: coil aPrime other end of coil a

int bPrimePin = 5; //IN4: coil bPrime other end of coil b

// We do not connect IN5, IN6, or IN7

int degrees = 0;

int delay1 = 2; // The delay between each step in milliseconds

int delay2 = 200; // The delay after each full revolution, in milliseconds

int count = 0; // The number of steps

int numberOfRotations = 1; // The number of times the rotor has

// turned 360 degrees

void setup() {

// Set all pins as output to send output signals from the Arduino

// UNO to the coil windings of the stator

lcd.begin(16, 2); // Sets the size of the LCD in characters and lines

lcd.clear(); // Clear the LCD screen of characters and symbols

pinMode(aPin, OUTPUT);

pinMode(bPin, OUTPUT);

pinMode(aPrimePin, OUTPUT);

pinMode(bPrimePin, OUTPUT);

lcd.setCursor(0, 0);

lcd.print(" Clockwise");

// Start with all coils off

digitalWrite(aPin, LOW);

digitalWrite(bPin, LOW);

digitalWrite(aPrimePin, LOW);

digitalWrite(bPrimePin, LOW);

}

void loop() {

// Send current to

// 1. The aPin

// 2. The aPin, and the bPin

// 3. The bPin

// 4. Then to the bPin and the aPrimePin

// 5. Then to the aPrimePin

// 6. Then to the aPrimePin and the bPrime Pin

// 7. Then to the bPrimePin

// 8. Then the bPrimePin and the aPin.

// Thus producing steps using the half step method

//Reversive direction after each turn

if ((numberOfRotations) % 2 == 0) { // Check if number of rotations is even

// if so reverse direction

aPin = 5;

bPin = 4;

aPrimePin = 3;

bPrimePin = 2;

}

else { // If number of rotations is an odd number

aPin = 2;

bPin = 3;

aPrimePin = 4;

bPrimePin = 5;

}

// 1. Set the aPin High

digitalWrite(aPin, HIGH);

digitalWrite(bPin, LOW);

digitalWrite(aPrimePin, LOW);

digitalWrite(bPrimePin, LOW);

// Allow some delay between energizing the coils to allow

// the stepper rotor time to respond.

delay(delay1); // So, delay1 milliseconds

// 2. Energize aPin and bPin to HIGH

digitalWrite(aPin, HIGH);

digitalWrite(bPin, HIGH);

digitalWrite(aPrimePin, LOW);

digitalWrite(bPrimePin, LOW);

// Allow some delay between energizing the coils to allow

// the stepper rotor time to respond.

delay(delay1); // So, delay1 milliseconds

// 3. Set the bPin to High

digitalWrite(aPin, LOW);

digitalWrite(bPin, HIGH);

digitalWrite(aPrimePin, LOW);

digitalWrite(bPrimePin, LOW);

// Allow some delay between energizing the coils to allow

// the stepper rotor time to respond.

delay(delay1); // So, delay1 milliseconds

// 4. Set the bPin and the aPrimePin to HIGH

digitalWrite(aPin, LOW);

digitalWrite(bPin, HIGH);

digitalWrite(aPrimePin, HIGH);

digitalWrite(bPrimePin, LOW);

// Allow some delay between energizing the coils to allow

// the stepper rotor time to respond.

delay(delay1); // So, delay1 milliseconds

// 5. Set the aPrime Pin to high

digitalWrite(aPin, LOW);

digitalWrite(bPin, LOW);

digitalWrite(aPrimePin, HIGH);

digitalWrite(bPrimePin, LOW);

// Allow some delay between energizing the coils to allow

// the stepper rotor time to respond.

delay(delay1); // So, delay1 milliseconds

// 6. Set the aPrimePin and the bPrime Pin to HIGH

digitalWrite(aPin, LOW);

digitalWrite(bPin, LOW);

digitalWrite(aPrimePin, HIGH);

digitalWrite(bPrimePin, HIGH);

// Allow some delay between energizing the coils to allow

// the stepper rotor time to respond.

delay(delay1); // So, delay1 milliseconds

// 7. Set the bPrimePin to HIGH

digitalWrite(aPin, LOW);

digitalWrite(bPin, LOW);

digitalWrite(aPrimePin, LOW);

digitalWrite(bPrimePin, HIGH);

// Allow some delay between energizing the coils to allow

// the stepper rotor time to respond.

delay(delay1); // So, delay1 milliseconds

// 8. Set the bPrimePin and the aPin to HIGH

digitalWrite(aPin, HIGH);

digitalWrite(bPin, LOW);

digitalWrite(aPrimePin, LOW);

digitalWrite(bPrimePin, HIGH);

// Allow some delay between energizing the coils to allow

// the stepper rotor time to respond.

delay(delay1); // So, delay1 milliseconds

count = count + 8;

degrees = (360.0 * (count / 4096.0));

if ((numberOfRotations % 2) == 1) { // Check if number of rotations is odd

lcd.setCursor(0, 0); // Move the cursor to 1th position on 1st line

lcd.print(" Clockwise ");

lcd.setCursor(0, 1); // Move the cursor to 1th position on 2nd line

lcd.print(" "); // Print two spaces, to provide room for a minus

// when the stepper turns counter-clockwise

lcd.print(degrees); // Print angular position in degrees

lcd.print((char)223); // Print degree symbol

lcd.print(" "); // Print a space

}

else { // If numberOfRotations is even number

lcd.setCursor(0, 0); // Move the cursor to 1th position on 1st line

lcd.print(" Anti-Clockwise ");

degrees = 360 - degrees;

lcd.setCursor(0, 1); // Move the cursor to 1th position on 2nd line

lcd.print(" -"); // Print a minus sign

lcd.print(degrees); // Print angular position in degrees

lcd.print((char)223); // Print degree symbol

lcd.print(" "); // Print a space

}

if (count == 4096) {

time = millis();

if ( time > 55000 && time < 65000) { // See how many rotations were made

// in a minute (approximately).

// Print the number of rotations on the LCD, adjusting for fractional

// values not otherwise accounted for. RPM is only approximate.

RPM = numberOfRotations + 1;

lcd.setCursor(7, 1);

lcd.print("RPM: ");

lcd.print(RPM);

}

delay(delay2); // delay2/1000 second(s) after each full rotation

count = 0; // Reset step counter to zero

numberOfRotations = ++numberOfRotations;

}

}

Downloads

EasyDriver Breakout Module, First Use

EasyDrive w Pot Identified.jpg
EasyDriver-3.jpg
EasyDriver Closeup.jpg
Pins Before Soldering.jpg
EasyDriver Pins On.jpg
EasyDriver in Breadboard.jpg

EasyDriver was originally designed to satisfy an educational need, and subsequently released as Open Source. The designer, Brian Schmalz of Schmalz Haus LLC, originally sold his EasyDriver boards through: https://www.sparkfun.com/, http://shop.evilmadscientist.com/, and https://www.seeedstudio.com.

The EasyDriver board went through a number of iterations, e.g., EasyDriver v1, v2, v3, etc. The version used here is v4.4, and there is at least one subsequent version. This breakout stepper board driver turned out to be very popular. Its open source, creative commons, license resulted in its being manufactured by many companies. The open source release requires manufacturers to provide attribution to Schmalz Haus. Unfortunately, this is not always done. (See attached photographs for the Schmalz Haus name on the board here.) I purchased quantities of the EasyDriver board for less than $1.30 each. At the time this tutorial was published, the EasyDriver board was available through Amazon, apparently shipped from China, for less than $3.90 in single quantities, and on eBay, shipped from China, for less than $1.65 each.

This board is based on the highly capable Allegro A3967 microstepping driver IC. It is essentially a breakout board for this IC, and its popularity is due in part to the capabilities of the A3967. Owing to the built-in microstepping capabilities of the Allegro IC, this board can provide excellent positioning accuracy. Its primary problem is its limited current capacity, due to the current capacity of the A3967 IC.

The EasyDriver module can provide from 150mA up to about 750mA. It has an on-board potentiometer which can be adjusted to limit current.

To use the potentiometer.

(1) Set it to its lowest setting.

(2) Gradually increase it until the stepper turns (after loading one the sketches provided in following Steps of this tutorial).

(3) Continue to increase the potentiometer setting (i.e., the current flow) until the stepper motor steps smoothly without hesitations or skipping.

(4) Adjust the potentiometer up and down a little until you find the best setting.

I was able to adjust the potentiometer using a Wiha 261/PH 00x40 flat screw driver, which fortunately did not require the application of too much force. Remember, the on-board potentiometer is very small, so adjust it carefully, and not with brute force. If set too low the stepper will "jerk" or not turn at all. If set too high the stepper will turn, but it is not at the best setting.

As noted above, the board uses the Allgero A3967 IC. This chip is designed for full step, half step, 1/2 microstep, and 1/8 microstep modes. This chip provides circuit support, by providing thermal overload and under voltage protection. The EasyDriver also has an LM317G voltage regulator on-board. This stepper driver module requires a power supply that is reasonably free from noise/ripple. I use the different stepping modes of the Allgero IC in the second example below.

The Allegro chip can get quite hot when current is over 500mA. Thus, I would recommend an IC heat sink, and/or forced air fan, if you decide to run this module at relatively high current. The LM317G three-terminal voltage regulator (in an SOT-223 package) is visible to the left of the Allegro IC. The "G" indicates it is "Halogen Free and Lead Free". (The attached photographs show how the A3967 and LM317G are placed on the EasyDriver PCB.)

The EasyDriver module is often provided on a PCB, with breakable header pins to solder into the provided openings in the board. I first show this module without any pins soldered, and in the second example with all pins soldered in. (See photographs for how this board is frequently sold.)

There are 17 connections along the edges of the EasyDriver Module, but only nine are needed for the circuit used in the first example. The needed connections are identified in the first attached photograph. Thus, only nine pins need to be soldered to the board for use in the first example of this stepper driver board, as discussed in this tutorial.

The easiest way to solder the header pins to the EasyDriver, is to insert them into a breadboard before soldering. (See photographs). Another attached photograph shows the header pins soldered to the EasyDriver, with a subsequent photograph showing the EasyDriver inserted into a breadboard and circuit ready.

EasyDriver First Circuit

NEMA 14-7.jpg
NEMA 14-7 Coils.jpg
NEMA 14-5.jpg
Circuit-1.jpg
Breadboard EasyDriver-1.jpg
Stepper Connections.jpg
LEDs.jpg
GND Connection.jpg
Arduino Pins.jpg

Here we used a NEMA 14 stepper whose data sheet was not available. So a resistance matrix, as was done in Part 1 of this tutorial, for all lead pairs was prepared with the help of an ohmmeter. That matrix, is shown in the attached photographs. From that matrix it was determined that the stepper had two coils. The leads to these coils are Green and Yellow, and Black and Red. The Orange and Purple leads were the common taps, and they were not connected in the construction of this circuit. An illustration of the coil assignments can be found in one of the attached photographs.

Two LEDs were added to show when the stepper turns in a clockwise (Blue) or counter-clockwise (Green) direction.

The connections used in the example here are as follows:

Stepper Motor to EasyDriver Module (see attached photos to see how this was implemented for this example)

1. Connect Yellow and Green leads from stepper to Motor A on EasyDriver Module

2. Connect Black and Red leads from stepper to Motor B on EasyDriver Module

Note: Side of EasyDriver for these connections is away from Arduino.

External 5v wall adapter

3. Connect both wires from 5v wall adapter to EasyDriver PWR In, GND and M, on the side of EasyDriver away from Arduino.

Driver Module (see attached photos to see how this was implemented for this example)

4. Connect wire from GND on EasyDriver (EasyDriver side toward Arduino) to GND power rail on Arduino.

5. Connect wire from Step on EasyDriver (EasyDriver side toward Arduino) to digital socket 3 on Arduino

6. Connect wire from DIR on EasyDriver to digital socket 2 on Arduino. (EasyDriver side toward Arduino.)

Breadboard (see attached photos to see how this was implemented for this example)

7. Connect wire from GRN rail on breadboard to GND on Arduino

8. Connect positive side of Blue LED to digital socket 6 on the Arduino

9. Connect negative side of Blue LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail

10. Connect positive side of Green LED to digital socket 7 on the arduino.

11. Connect negative side of Green LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail.

The attached photographs show how this was implemented, i.e., the circuit connections, for this project.

First Sketch Using EasyDrive Stepper Motor Module

EasyDriver and NEMA 14
EasyDriver and 28BYJ 48

In this example the NEMA 14 stepper, whose coils and leads to these coils were found earlier, is used. When the stepper rotates in a clockwise direction the Blue LED is turned on, and when it turns in a counter-clockwise direction the Green LED lights.

The sketch was modified by me, from a sketch by bildr (c) 2011. It rotates the stepper at less than its maximum speed for a full 360 degree revolution clockwise, and then a full revolution counter-clockwise. It uses colored LEDs to show the direction of rotation. The stepper then rotates/steps 360 degrees clockwise and then 360 degrees counter-clockwise at its maximum speed. The sketch repeats this clockwise then counter-clockwise pattern until power is removed.

In the second video, the circuit is the same as above. The sketch was adjusted to account for the difference in angular rotation for a step of the NEMA 14 step motor and the 28BYJ-48 stepper. The 28BYJ-48 was used here as a bipolar stepper, only four leads, the Orange and Pink leads and the Blue and Yellow leads, were used. The common Red tap was left unconnected. This second video shows the EasyDriver driving the 28BYJ-48 stepper. Although the 28BYJ-48 had more steps in a full revolution than the NEMA 14, the EasyDriver experienced no issues in controlling this stepper.

The EasyDriver module has a default of microstepping with 8 steps, i.e. it will move one eight of what it would step in the full step mode.That is, it acts as if MS1 and MS2 were set to high. See next Step, and my sketch for the configuration shown in that Step, for an example where MS1 and MS2 are changed to allow various stepping modes.

Please download the attached text file in this Step to see the sketch, for the NEMA 14, exactly as written, including whitespace.

----------Sketch----------

//////////////////////////////////////////////////////////////////

//©2011 bildr

//Released under the MIT License - Please reuse change and share

//Using the easy stepper with your arduino

//speed is any number from .01 -> 1 with 1 being the fastest

//Modified by R.J. Kreindler Oct 2016

// Rotate 360 degrees clockwise, pause 1 second

// then reverse direction and rotate 360 degrees

// First use rotateDeg to specify degrees to rotate

// then use rotate to specify the number of steps to rotate

/////////////////////////////////////////////////////////////////

#define DIR_PIN 2

#define STEP_PIN 3

int clockwiseLED = 6;

int counterclockwiseLED = 7;

void setup() {

pinMode(DIR_PIN, OUTPUT);

pinMode(STEP_PIN, OUTPUT);

pinMode(clockwiseLED, OUTPUT);

pinMode(counterclockwiseLED, OUTPUT);

}

void loop(){

//Rotate 360 degrees clockwise then 360 degrees counter clockwise

// Rotate at 1/10 maximum speed

digitalWrite(clockwiseLED, HIGH);

//rotate 360 degrees

rotateDeg(360, .1);

digitalWrite(clockwiseLED, LOW);

delay(1000);


// Rotate less than the maximum speed

digitalWrite(counterclockwiseLED, HIGH);

rotateDeg(-360, .1); //Reverse direction, rotate 360-degrees

digitalWrite(counterclockwiseLED, LOW);

delay(1000);

//Rotate 360 degrees clockwise then 360 degrees counter clockwise

// The specific number of microsteps can be determined

// using (8 microsteps per step)

// A 200 step stepper, has per 360 degree revolution 1600 micro steps

// Rotate at the fastest speed

digitalWrite(clockwiseLED, HIGH);

rotate(1600, 1);

digitalWrite(clockwiseLED, LOW);

delay(1000);

// Rotate at the fastest speed

digitalWrite(counterclockwiseLED, HIGH);

rotate(-1600,1); //reverse

digitalWrite(counterclockwiseLED, LOW);

delay(1000);

}

// Functions rotate() and rotateDeg() used in this sketch

void rotate(int steps, float speed){

//rotate a specific number of microsteps (8 microsteps per step) - (negitive for reverse movement)

//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger

int dir = (steps > 0)? HIGH:LOW;

steps = abs(steps);

digitalWrite(DIR_PIN,dir);

float usDelay = (1/speed) * 70;

for(int i=0; i < steps; i++){

digitalWrite(STEP_PIN, HIGH);

delayMicroseconds(usDelay);

digitalWrite(STEP_PIN, LOW);

delayMicroseconds(usDelay);

}

}

void rotateDeg(float deg, float speed){

//rotate a specific number of degrees (negitive for reverse movement)

//speed is any number from .01 -> 1 with 1 being fastest - Slower is stronger

int dir = (deg > 0)? HIGH:LOW;

digitalWrite(DIR_PIN,dir);

int steps = abs(deg)*(1/0.225);

float usDelay = (1/speed) * 70;

for(int i=0; i < steps; i++){

digitalWrite(STEP_PIN, HIGH);

delayMicroseconds(usDelay);

digitalWrite(STEP_PIN, LOW);

delayMicroseconds(usDelay);

}

}


EasyDriver Second Circuit

MS1 and MS2.jpg
EasyDriver Example 2.jpg
EasyDriver soldered pins.jpg
Second EasyDriver circuit.jpg
EasyDriver Example2-1.jpg
EasyDriver Example2-2.jpg
EasyDriver Example2-3.jpg

In this second example, we will solder pins for MS1 and MS2 on the EasyDriver PCB. We use the boolean values in the attached table, derived from the data sheet for the Allegro A3967 IC, to change the stepper step modes through Full Step, Half Step, 1/4 Microstep, and 1/8 Microstep.

Stepper Motor to EasyDriver Module (see attached photos to see how this was implemented).
1. Connect coil 1 from stepper to Motor A on EasyDriver Module

2. Connect coil 2 from stepper to Motor B on EasyDriver Module

Note: Side of EasyDriver for these connections is away from Arduino.

External 5v wall adapter

3. An external 5v wall adapter was used. Connect both wires from 5v wall adapter to the two terminals for the EasyDriver PWR In (GND and M+) on the side of EasyDriver away from Arduino Driver Module (see attached photos to see how this was implemented for this example). I used a two screw adapter with a female barrel socket to interface to a 5v wall adapter with a male barrel connector.

4. Connect wire from GND on EasyDriver (EasyDriver side toward Arduino) to GND on Arduino.

LEDs (see attached photos to see how this was implemented)

5. Connect positive side of Red LED to digital socket 6 on the Arduino. When on this will show that the stepper is in the default basic step.

6. Connect negative side of Red LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail

7. Connect positive side of Yellow LED to digital socket 7 on the arduino. When on this will show that the stepper is in the 1/2 step mode.

8. Connect negative side of Yellow LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail.

9. Connect positive side of Blue LED to digital socket 8 on the Arduino. When on this will show that the stepper is in the 1/4 step mode.

10. Connect negative side of Blue LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail.

11. Connect positive side of Orange LED to digital socket r on the Arduino. When on this will show that the stepper is in the 1/8 step mode.

12. Connect negative side of Orange LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail.

Driver Module (see attached photos to see how this was implemented)

13. Connect MS1 on EasyDriver to Arduino digital socket 10.

14. Connect MS2 on EasyDriver to Arduino digital socket 11.

15. Connect STEP on EasyDriver to Arduino digitsl socket 12.

16. Connect DIR on EasyDrivet to Arduino digital socket 13.

Breadboard (see attached photos to see how this was implemented)

17. Connect wire from GRN rail on breadboard to GND on Arduino

The attached photographs show how this was implemented for this second EasyDriver example.

Second EasyDriver Sketch

EasyDriver Example 2
OKI Stepper.jpg

In the sketch that follows, I used stepping modes available on the EasyDriver module Full, 1/2, 1/4, and 1/8. That is, the stepper, for each full 360 degree rotation, can turn at the basic step angle, or can take two steps, four steps or eight steps in one basic step length. For a full rotation, it will take either the number of basic steps in that rotation or a multiple of that amount. Obviously, if we choice microstepping with 1/8 the basic step, we get 8 times the resolution of the stepper, compared to it rotating at its basic step angle. I programmed this sketch using the truth table shown and addressed in the previous step.

I use an OKI printer (OKI is a Japanese company with annual revenue exceeding 490 billion yen) circular 42mm four-wire bipolar stepper motor in the video (please see attached photograph). This stepper has a basic step of 7.5 degrees, i.e., 48 steps per revolution. It is rated at 0.5A, and has a magnetic filter around the leads.

In the program below, I use for loops, e.g.,

for (i = 1; i <= numSteps*rotations; ++i)

for each rotation where "rotations" indicates the number of rotations a rotor takes before moving to the next stepping mode and changing direction. For 1/2 step the value numSteps*rotations is multiplied by two, for 1/4 microstepping this value is multipilied by four, and for 1/8 microstepping this value is multiplied by eight. This adjusts the for loops for the appropriate number of steps in a complete 360 degree rotation, for each step mode.

In this sketch the delay between coil activations is 3ms. The number of full rotations at each stepping mode is set at four to provide four rotations before changing direction, and thus make the turning of the rotor. easier to follow.

The DIR pin on the EasyDriver module is set alternately at HIGH then LOW to reverse direction. For example,

digitalWrite(dirPin, HIGH);

The rotations might possibly have been too fast to see properly, if the direction was not changed after each step mode. Four LED are used in this circuit, Red, Yellow, Blue, and Orange to show respectively when the rotor is turning at the full step, half step, quarter step, or eight step stepping mode.

Please download the attached text file to see the sketch exactly as written, including whitespace.

----------Sketch----------

// ******************************

// Sketch by R. Jordan Kreindler, written October 2016

// to work with EasyDriver stepper driver module

// Rotates stepper in full, 1/2, 1/4, and 1/8 step modes

// with the parameter "rotations" specifying how many times to

// rotate for each stepping mode

// ******************************

int oneLED = 6; // Full step LEDMS1

int onehalfLED = 7; // 1/2 step LED

int onequarterLED = 8; // 1/4 step LED

int oneeighthLED = 9; // 1/8 step LED

int ms1Pin = 10; // EasyDriver MS1 to Arduino digital pin 10

int ms2Pin = 11; // EasyDriver MS2 to Arduino digital pin 11

int stepPin = 12; // EasyDriver STEP pin to Arduino digital pin 12

int dirPin = 13; // EasyDriver DIR pin to Arduino digital pin 13

int numSteps = 48; // Number of steps in 360 degree rotation

int rotations = 4; // Number of rotations of the rotor in each mode

int delay1 = 3; // Delay between coil activations (ms)

int delay2 = 500; // Delay between subsequent rotations

int i; // For loop index

//------------------------------

void setup() {

pinMode(ms1Pin, OUTPUT); // MS1 set to receive Arduino signals

pinMode(ms2Pin, OUTPUT); // MS2 set to receive Arduino signals

pinMode(stepPin, OUTPUT); // stepPin set to receive Arduino signals

pinMode(dirPin, OUTPUT); // DIR set to receive Arduino signals

pinMode(oneLED, OUTPUT); // Full step LED

pinMode(onehalfLED, OUTPUT); // 1/2 step LED

pinMode(onequarterLED, OUTPUT); // 1/4 step LED

pinMode(oneeighthLED, OUTPUT); // 1/8 step LED

digitalWrite(dirPin, HIGH);

}

//------------------------------

void loop(){

digitalWrite(dirPin, HIGH);

digitalWrite(oneLED, HIGH);

// Rotate stepper a full revolution, using full step method

digitalWrite(ms1Pin, LOW);

digitalWrite(ms2Pin, LOW);

for (i = 1; i <= numSteps * rotations; ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

delay(delay2);

digitalWrite(oneLED, LOW);

digitalWrite(dirPin, LOW);

digitalWrite(onehalfLED, HIGH);

// Rotate stepper a full revolution, using half step method

digitalWrite(ms1Pin, HIGH);

digitalWrite(ms2Pin, LOW);

for (i = 1; i <= numSteps * 2 * rotations; ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

digitalWrite(onehalfLED, LOW);

digitalWrite(dirPin, HIGH);

digitalWrite(onequarterLED, HIGH);

// Rotate stepper a full revolution, using quarter stepping

digitalWrite(ms1Pin, LOW);

digitalWrite(ms2Pin, HIGH);

for (i = 1; i <= numSteps * 4 * rotations; ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

digitalWrite(onequarterLED, LOW);

// Rotate stepper a full revolution, using microstepping

// 8 steps/step

digitalWrite(oneeighthLED, HIGH);

digitalWrite(ms1Pin, HIGH);

digitalWrite(ms2Pin, HIGH);

digitalWrite(dirPin, LOW);

for (i = 1; i <= numSteps * 8 * rotations; ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

digitalWrite(oneeighthLED, LOW);

}

A4988 Stepper Driver Module

MS1 MS2 MS3 copy.jpg
A4988 Module Weight.jpg
A4988 Topside-3.jpg
A4988 Underside.jpg
A4988 Heat Sinked.jpg

These are relatively inexpensive modules manufactured in the style of the popular "Pololu Robotics & Electronics" stepper motor driver. At the time of this tutorial, "Made in China" versions of these stepper driver modules, apparently two-layer boards, were available for less than $0.75 each, shipping included, in quantity one. They are designed to work with bipolar steppers. The Pololu versions of this board are available on eBay for less than $1.50 each, with shipping included. Amazon has similar StepStick, RepRap Champion, versions of an A4988 stepper driver board for only slightly more in quantities of five.

This stepper motor driver is useful for handling bipolar steppers, and it has the ability to use one of five stepping modes.

In this example, we use the MS1, MS2, and MS3 pins on the A4988's stepper driver PCB. In keeping with the information on Allegro's data sheet. We use the boolean values in the attached table, to change the stepper's step modes. That is, the "MS" pins allow us to, in accordance with the truth table attached here, set the driver to one of the five step modes we want, from full step, half step, quarter step, eighth step, to sixteenth step.

When we send a single pulse (a transition from LOW to HIGH) we move the stepper one step. With this driver we only need one pin to control direction and one pin to control stepping.

This board is essentially a breakout, carrier, board for Allegro's highly capable A4988 "DMOS Microstepping Driver with Translator and Overcurrent Protection" IC. The board is relatively lightweight, and weighs only about 2.15 grams (see attached photograph).

As with the EasyDriver A3967 IC, the A4988 IC has thermal overload (over temperature), over current, and under voltage protection. This IC can perform within a range of voltages from 8 to 35v. Whatever voltage we select, it is connected to the GRD and VMOT pins on the A4988 module. This driver has a, relatively delicate, on-board potentiometer that allows us to limit the current to the stepper.

Regardless of the current the stepper draws, it is a good idea to use a chip heat sink on the A4988. This IC can handle a considerable amount of current, 2A for a biplolar stepper. However, it is prudent to have it heat sinked even for lower current, and it definitely needs to be heat sinked for current 1A and higher. It should probably be heat sinked even for lower current.

That is, we need to improve this chip's thermal dissipation regardless of the current required by the stepper. A fan will prove useful if this stepper driver is placed inside an enclosure. There is a Pololu "Black Edition" four layer version that handles slightly more current without a heat sink, but it is somewhat more expensive.

The manufacturer's data indicates that the A4988 IC will operate correctly in a temperature range from a low of -20 degrees Celsius to a high of 85 degrees Celsius, i.e., -4 to 185 degrees Fahrenheit.

It is also important to recall Ohm's Law, as the driver module adjusts its output. Therefore, the current through the stepper coil is likely not the same as the current through the power supply. The current to the coil depends on the output from the stepper driver module to the coil, and this will likely differ from that provided by the power supply.

If you want to find the stepper current directly: set MS1=MS2=MS3=LOW and measure the current from the driver module to the stepper, but without stepping, i.e., without moving to another step. Current will always flow into a stepper, from a powered driver board, and since the "MS" pins were set to the full step mode two coils will be active.

Circuit Using A4988 Stepper Driver Board

A4988 Circuit-0.jpg
A4988 Circuit-1 copy.jpg
A4988 Circuit-2.jpg
A4988 Circuit-3.jpg
A4988 Circuit-4.jpg
A4988 Circuit-5.jpg
A4988 Circuit-6.jpg
A4988 Circuit-7.jpg

The A4988 stepper drive module is connected in the example circuit as follows:

Stepper Motor to A4988 Module (see attached photos)

1. Connect leads from first stepper coil to 1A and 1B on the A4988 Module

2. Connect leads from second stepper coil to 2A and 2B on the A4988 Module

Wall Power Adapter

3. Connect both wires from a 5v wall adapter to A4988 Module to the GRD and VMOT pins on the stepper motor driver. (I used a female barrel connector adapter with two screws to connect to the male barrel connector from the 5v "wall wart".)

LEDs, used to show the step mode with which the stepper is rotating

4. Connect positive side of Red LED to digital socket 4 on the Arduino

5. Connect negative side of Red LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail.

6. Connect positive side of Yellow LED to digital socket 4 on the Arduino
7. Connect negative side of yello LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail

8. Connect positive side of Blue LED to digital socket 6 on the Arduino

9. Connect negative side of Blue LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail

10. Connect positive side of Orange LED to digital socket 7 on the Arduino.

11. Connect negative side of Orange LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail.

12. Connect positive side of White LED to digital socket 8 on the Arduino.
13. Connect negative side of White LED to 470 ohm resistor, and connect the remaining side of the resistor to breadboard GND power rail.

A4988 Stepper Motor Driver Module
14. Connect the SLEEP and RESET pins together, as recommended by the manufacturer.

15. Connect wire from Step on A4988 to digital socket 12 on Arduino

16. Connect wire from DIR on A4988 to digital socket 13 on Arduino.

17. Connect wire from MS1 Pin on A4988 to digital socket 9 on the Arduino.

18. Connect wire from MS2 Pin on A4988 to digital socket 10 on the Arduino.

19. Connect wire from MS3 Pin on A4988 to digital socket 11 on the Arduino.

20. Connect VDD to 5v socket on Arduino.

21 Connect GND (next to VDD) on A4988 module to GND on Arduino.

22. There is no need to connect the ENABLE pin, as this pin enables the stepper motor driver by default. Its default value is LOW.

If we had left the MS1, MS2, and MS3 pins unconnected, the stepper would operate in the full step mode. Running this drive only in full step mode, allows for a considerably shorter sketch, but resolution will be affected.

Some users place a 100 microfarad capacitor across the power input pins for the stepper; I did not find I needed one for the circuit here, with the 5v wall adapter. However, it probably is appropriate to use a 50 to 100 microfarad capacitor (where its voltage depends on the power supply used) near the A4988 driver module, to ensure that ripple and voltage spikes do not prevent the driver from working as intended, or possibly damage the board, and it is always a good idea to use decoupling capacitors.

In particular, if a higher voltage wall adapter is used, it is possible that transient voltage spikes might exceed the highest voltage the driver module, i.e., the A4988 IC can handle. This could result in a board that is permanently damaged. The appropriate capacitor across the stepper's power inputs, and close to the board, will prevent this possibility.

Sketch Using A4988 Stepper Motor Driver

A4988 in use

The sketch below is for the circuit in the Step above. In this sketch the direction of rotor rotation is reversed between full, half, quarter, eighth, and sixteenth stepping modes. There is a delay of 15ms between each subsequent coil activation, and 2,000ms pauses between step modes, with a longer pause before starting the stepping mode cycle again. The sketch implements the truth table shown earlier and selects in turn the five different step modes available with this stepper driver.

It uses a 15ms delay between coil activations to give observers a chance to see the rotor turn. A delay shorter that 15ms should work without issue for this stepper motor, but direct observation would be harder.

Please download the attached text file to see the sketch, including whitespace, exactly as written.

----------Sketch----------

// ******************************

// Sketch by R. Jordan Kreindler, written October 2016

// to work with A4988 stepper driver module

// Rotates stepper in full, 1/2, 1/4, 1/8, and 1/16 step modes

// with the parameter "rotations" specifying how many times to

// rotate for each stepping mode

// ******************************

int oneLED = 4; // Full step LED

int onehalfLED = 5; // 1/2 step LED

int onequarterLED = 6; // 1/4 step LED

int oneeighthLED = 7; // 1/8 step LED

int onesixteenthLED = 8; // 1/16 step LED

int ms1Pin = 9; // A4988 MS1 to Arduino digital pin 9

int ms2Pin = 10; // A4988 MS2 to Arduino digital pin 10

int ms3Pin = 11; // A4988 MS3 to Arduino digital pin 11

int stepPin = 12; // A4988 STEP pin to Arduino digital pin 12

int dirPin = 13; // A4988 DIR pin to Arduino digital pin 13

int numSteps = 48; // Number of steps in 360 degree rotation

int rotations = 4; // Number of rotations of the rotor for each

int delay1 = 15; // Delay between coil activations (ms)

int delay2 = 2000; // Delay between subsequent rotations

int i; // int to use in for loop

//------------------------------

void setup() {

pinMode(ms1Pin, OUTPUT); // MS1 set to receive Arduino signals

pinMode(ms2Pin, OUTPUT); // MS2 set to receive Arduino signals

pinMode(ms3Pin, OUTPUT); // MS3 set to receive Arduino signals

pinMode(stepPin, OUTPUT); // stepPin set to receive Arduino signals

pinMode(dirPin, OUTPUT); // DIR set to receive Arduino signals

pinMode(oneLED, OUTPUT); // Full step LED

pinMode(onehalfLED, OUTPUT); // 1/2 step LED

pinMode(onequarterLED, OUTPUT); // 1/4 step LED

pinMode(oneeighthLED, OUTPUT); // 1/8 step LED

pinMode(onesixteenthLED, OUTPUT); // 1/16 step LED

}

//------------------------------

void loop() {

delay(delay2);

digitalWrite(dirPin, LOW);

digitalWrite(oneLED, HIGH);

// Rotate stepper rotatations revolutions, using full step method

digitalWrite(ms1Pin, LOW);

digitalWrite(ms2Pin, LOW);

digitalWrite(ms3Pin, LOW);

for (i = 1; i <= (numSteps * 1 * rotations); ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

delay(delay2);

digitalWrite(oneLED, LOW);

digitalWrite(dirPin, HIGH);

digitalWrite(onehalfLED, HIGH);

// Rotate stepper rotatations revolutions, using half step method

digitalWrite(ms1Pin, HIGH);

digitalWrite(ms2Pin, LOW);

digitalWrite(ms3Pin, LOW);

for (i = 1; i <= (numSteps * 2 * rotations); ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

digitalWrite(onehalfLED, LOW);

delay(delay2);

digitalWrite(dirPin, LOW);

digitalWrite(onequarterLED, HIGH);

// Rotate stepper a rotatations revolutions, using quarter stepping

digitalWrite(ms1Pin, LOW);

digitalWrite(ms2Pin, HIGH);

digitalWrite(ms3Pin, LOW);

for (i = 1; i <= (numSteps * 4 * rotations); ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

digitalWrite(onequarterLED, LOW);

// Rotate stepper rotations revolution, using microstepping

// 8 steps/step

delay(delay2);

digitalWrite(dirPin, HIGH);

digitalWrite(oneeighthLED, HIGH);

digitalWrite(ms1Pin, HIGH);

digitalWrite(ms2Pin, HIGH);

digitalWrite(ms3Pin, LOW);

for (i = 1; i <= (numSteps * 8 * rotations); ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

digitalWrite(oneeighthLED, LOW);

// Rotate stepper rotations revolution, using microstepping

// 16 steps/step

delay(delay2);

digitalWrite(onesixteenthLED, HIGH);

digitalWrite(dirPin, LOW);

digitalWrite(ms1Pin, HIGH);

digitalWrite(ms2Pin, HIGH);

digitalWrite(ms3Pin, HIGH);

for (i = 1; i <= numSteps * 16 * rotations; ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

digitalWrite(onesixteenthLED, LOW);

}

Downloads

DRV8825 Stepper Driver Module

DRV8825-1.jpg
DRV8825-2.jpg
MS1(0) MS2(1) MS3(2) Stepstick.jpg
DRV8825-1.jpg
DRV8825-2.jpg
DRV8825-3.jpg
DRV8825-4.jpg
DRV8825-5.jpg
DRV8825-6.jpg
DRV8825-7.jpg
IM483.jpg
IM483 Stepper Driver-2.jpg

The relatively inexpensive DRV8825 module is extremely capable, and can provide excellent resolution. This stepper driver module is essentially a breakout board for the DRV8825. This IC can handle a considerable amount of current. However, as with the A4988 it is prudent to have it heat sinked even for low current. Here I used a heat sink on the top of the chip. Regardless of the current the stepper draws from this driver, it is a good idea to use a chip heat sink on the Stepstick DRV8825.

The design of this module places a thermal pad on the bottom (reverse of the component side). Attaching a heat sink to the bottom thermal pad will result in the greatest chip cooling, but may interfere with placing the module fully into the breadboard socket or may, although unlikely, lead to shorting.

Fortunately, this module comes with pins that are slightly taller than usual to mitigate these potential issues. The lengthened pins help the module attach to the breadboard, even if a heat sink is attached to the module's underside, and they allow a user to easily see if any potential shorts may be present. If you are planning to use this stepper driver with high current, it is recommended that you place the heat sink on the underside of the board.

This chip has over temperature, over current, and under voltage protection. The DRV8824 has six step modes, full, two, four, eight, sixteen, and 32 steps per basic step. Whereas, the A4988 driver only has five, missing the 32 step mode. To invoke various step modes the MS pins are set in accordance with the table attached here. As with the A4988 this driver has easy to use DIR and STEP pins.

The circuit here is connected in a similar fashion to the A4988 driver used in earlier Steps. This DRV88 stepper driver example has MS pins designated MS0, MS1, and MS2 instead of MS1, MS2, and MS3. However, some other versions of this stepper driver start with MS1 rather that MS0. Thus, for the circuit here I treated the MS pins as follows: MS0=MS1, MS1=MS2, MS2 = MS3. This allowed me to alter the previous sketch with fewer changes. This approach allows the sketch below to run with boards that start their MS pin assignments at MS1, without any change.

An IC with 3 input pins, that each have two possible values: HIGH and LOW, has 2 x 2 x 2 = 8 possible truth table entries. The EasyDriver used four (but only had two input pins), the A4988 uses five, and the DRV8824 uses six of their possibilities, both having three pins for selecting the step mode. Thus, if I can forecast what is to come, we should see an inexpensive stepper driver providing seven or possibly all eight possibilities.

If the same microstepping series as used in the ICs just mentioned is implemented, we might expect to see a driver that provides microstepping down to a resolution of 1/128th of a full step. This is, obviously, highly speculative, and only time will tell if my forecast comes to fruition. I do expect to see a relatively inexpensive microstepping driver that uses seven or eight possibilities, but perhaps it will not go to 1/128th of a full step, as intermediate values might be used, and might possibly be of more benefit.

Of course, if you need more resolution now, you may want to consider an industrial driver, which is much more expensive, such as Schneider Electric's IM483, which as an aside - can handle 3A normally with a 4A peak current, and voltages between 12 and 48DC (see attached photographs). It can use a microstep resolution of 51,200 steps per revolution, and has fourteen step resolutions, rather than the six of the DRV8825, but as mentioned earlier it is considerably more expensive (typically selling, e.g., on eBay, from $100 to over $225 a piece, including shipping).

We can easily calculate the steps in a full revolution by taking the basic full steps/revolution x microsteps/step.

The circuit used here, with the DRV8825 stepper driver, is shown in the attached photos. The LCD is attached as in our previous sketches. I used a 5v wall adapter. However, steppers can be somewhat different; so, you may find your stepper will not turn with a lower voltage power adapter connected. If so, you may need 9, 12, or a higher voltage wall adapter, with sufficient amperage, even if your stepper is rated for a relatively low voltage The manufacturer's data sheet, indicates that the IC on this module can handle 8.2 to 45v (although I would recommend that for this stepper driver, voltage should not exceed 35v).

TI specifies that the DRV8825 can handle a maximum current of 2.5A at 24v, at a nominal 77 degrees Fahrenheit ambient temperature. If a 9 volt or higher voltage adapter is needed, you may need to limit current to the stepper, either through the on-board potentiometer or via an external resistor or both, to keep the stepper from becoming too hot, and of course do not forget the capacitor mentioned in a previous Step.

You can use the trim potentiometer as follows. Set it to its midpoint. This should be about 1.25 A. You can then adjust it clockwise (to raise the current) and counter clockwise to reduce it. Under no circumstances should the current exceed the stepper motor's maximum acceptable current rating. Alternatively, you can follow the procedure mentioned in an earlier Step: To use the potentiometer. (1) Set it to its lowest setting. (2) Gradually increase it until the stepper turns (after loading the sketch provided in the Step that follows). (3) Continue to increase the potentiometer setting (i.e., the current flow) until the stepper motor steps smoothly without hesitations or skipping. (4) Adjust the potentiometer up and down a little until you find the best setting.

Sketch for the DRV8825 Driver

Example of Stepper with DRV8825

In this sketch the stepper is placed, in turn, through six step modes: full, 2 steps, 4 steps, 8 steps, 16 steps and 32 steps, i.e., steps in a basic step. Because this driver has a 32 step mode, the delay between steps was reduced to 10ms, so the time for a rotation at the 1/32 mode was more reasonable. The delay between step modes and direction changes was kept at 2,000 ms.

The MS pins were written to, in keeping with the table in the previous Step. This allowed all six stepping modes to be invoked. An additional section of code was added to handle the 32 step mode, which is not available to the A4988 stepper driver. An LCD is used here, as opposed to the LEDs previously used. It shows the current step mode of the motor.

In this video the stepper used is a 42mm, 48 steps/revolution, OKI stepper motor, run at 5v with a current of about 0.5 A.

Please download the text file to see the code as written, including whitespace.

----------Sketch----------

// ******************************

// Sketch by R. Jordan Kreindler, written October 2016

// to work with DRV8825 stepper driver module

// Rotates stepper in full, 1/2, 1/4, 1/8, 1/16, and 1/32 step modes

// with the parameter "rotations" specifying how many times to

// rotate for each stepping mode

// ******************************

#include

// LiquidCrystal (RS, E, d4, d5, d6, d7)

LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // For standalone, non-shield, LCD

int ms1Pin = A0; // Stepstick MS0 to Arduino digital pin 9

int ms2Pin = A1; // Stepstock MS1 to Arduino digital pin 10

int ms3Pin = A2; // Stepstick MS2 to Arduino digital pin 11

int stepPin = A3; // Stepstick STEP pin to Arduino digital pin 12

int dirPin = A4; // Stepstick DIR pin to Arduino digital pin 13

int numSteps = 48; // Number of steps in 360 degree rotation

int rotations = 3; // Number of rotations of the rotor for each

int delay1 = 10; // Delay between coil activations (ms)

int delay2 = 2000; // Delay between subsequent rotations

int i; // int to use in for loop

//------------------------------

void setup() {

pinMode(ms1Pin, OUTPUT); // MS1 set to receive Arduino signals

pinMode(ms2Pin, OUTPUT); // MS2 set to receive Arduino signals

pinMode(ms3Pin, OUTPUT); // MS3 set to receive Arduino signals

pinMode(stepPin, OUTPUT); // stepPin set to receive Arduino signals

pinMode(dirPin, OUTPUT); // DIR set to receive Arduino signals

lcd.begin(16, 2); // Sets the size of the LCD in characters and lines

lcd.clear(); // Clear the LCD screen of characters and symbols}

lcd.setCursor(0,0);

lcd.print(" Stepstick");

lcd.setCursor(0,1);

lcd.print(" Mode: ");

}

//------------------------------

void loop() {

delay(delay2);

digitalWrite(dirPin, LOW);

lcd.setCursor(7, 1); // Move the cursor to 1th position on 1st line

lcd.print("Full Step ");

// Rotate stepper rotatations revolutions, using full step method

digitalWrite(ms1Pin, LOW);

digitalWrite(ms2Pin, LOW);

digitalWrite(ms3Pin, LOW);

for (i = 1; i <= (numSteps * 1 * rotations); ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

delay(delay2);

digitalWrite(dirPin, HIGH);

// Rotate stepper rotatations revolutions, using half step method

digitalWrite(ms1Pin, HIGH);

digitalWrite(ms2Pin, LOW);

digitalWrite(ms3Pin, LOW);

lcd.setCursor(7, 1); // Move the cursor to 1th position on 1st line

lcd.print("2 Step ");

for (i = 1; i <= (numSteps * 2 * rotations); ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

delay(delay2);

digitalWrite(dirPin, LOW);

// Rotate stepper a rotatations revolutions, using quarter stepping

digitalWrite(ms1Pin, LOW);

digitalWrite(ms2Pin, HIGH);

digitalWrite(ms3Pin, LOW);

lcd.setCursor(7, 1); // Move the cursor to 1th position on 1st line

lcd.print("4 Step ");

for (i = 1; i <= (numSteps * 4 * rotations); ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

// Rotate stepper rotations revolution, using microstepping

// 8 steps/step

delay(delay2);

digitalWrite(dirPin, HIGH);

digitalWrite(ms1Pin, HIGH);

digitalWrite(ms2Pin, HIGH);

digitalWrite(ms3Pin, LOW);

lcd.setCursor(7, 1); // Move the cursor to 1th position on 1st line

lcd.print("8 Step ");

for (i = 1; i <= (numSteps * 8 * rotations); ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

// Rotate stepper rotations revolution, using microstepping

// 16 steps/step

delay(delay2);

digitalWrite(dirPin, LOW);

digitalWrite(ms1Pin, LOW);

digitalWrite(ms2Pin, LOW);

digitalWrite(ms3Pin, HIGH);

lcd.setCursor(7,1);

lcd.print("16 Step ");

for (i = 1; i <= numSteps * 16 * rotations; ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

// Rotate stepper rotations revolution, using microstepping

// 32 steps/step

delay(delay2);

digitalWrite(dirPin, HIGH);

digitalWrite(ms1Pin, HIGH);

digitalWrite(ms2Pin, HIGH);

digitalWrite(ms3Pin, HIGH);

lcd.setCursor(7,1);

lcd.print("32 Step ");

for (i = 1; i <= numSteps * 32 * rotations; ++i) {

digitalWrite(stepPin, LOW); // Prepare to take a step

digitalWrite(stepPin, HIGH) ; // Take a step

delay(delay1); // Allow some delay between energizing

// the coils to allow stepper rotor time to respond.

}

//

}

Afterwards

Four-Wire Steppers.jpg

If you have come to this point congratulations. You should now have a basic understanding of some of the important elements of the stepper motor drivers covered in this tutorial: what stepper driver and stepper motor parameters are important, the general rules to know when dealing with stepper motors and their drivers, how to adjust stepper speed in your sketch, how some driver modules allow you to limit the current to the stepper, and how a stepper motor can be driven by the stepper driver modules discussed in this tutorial.

I hope you found this tutorial interesting, informative, and enjoyable. If so, please let me know in the comments below. If you have any questions about stepper motor drivers not covered in this tutorial, or would like to send some photographs, I would be pleased to hear from you via email. You can contact me at transiintbox@gmail.com. (Please replace the second 'i' with an 'e' to contact me. The very best.)