OVERVIEW
In the last tutorial I’ve looked at an alternative to the EasyDriver… The L298N.
Although the L298 works, it’s not the best option for driving stepper motors with an Arduino.
One big advantage of the Easy Driver is that it supports multiple Micro Stepping options.
I’ve done many tutorial in the past using the EasyDriver but never really used the micro stepping options.
So in this tutorial I will look at how to switch the type of micro stepping used on the fly and what to keep in mind when switching between options.
PARTS USED
Arduino UNO
EasyDriver Stepper Driver
Analog Slider
OLED Display
These are Amazon affiliate links...
They don't cost you anything and it helps me keep the lights on
if you buy something on Amazon. Thank you!
LET'S LOOK AT THE SPECS
Today we are using the Easy Driver but they are many more available of course.
Another one you might want to use is the Big Easy Driver which support more current to drive bigger stepper motors.
So let’s have a look at the regular Easy Driver first:
Based on the A3867 micro stepping driver
Supports up to Eight steps (Full, 1/2, 1/4, 1/8)
Adjustable current (150mA – 750mA per phase)
Power supply from 6 to 30V
Onboard 5V output (but only around 50mA)
Comes with pins unsoldered
Meant to be used on PCB or a Breadboard
Now let’s have a look at the Big Easy Driver:
Based on the A4988 micro stepping driver
Supports up to Sixteenth steps (Full, 1/2, 1/4, 1/8, 1/16)
Adjustable current (0mA – 2000mA per phase)
Power supply from 8 to 35V
Onboard 5V output (but only around 50mA)
Comes with pins unsoldered
Can be used on PCB or Breadboard
But can also use Screw Terminals for easy connections
So as you can see they are quite similar, but the Big Easy Driver:
Provides more Power (up to 2A instead of only 750mA per phase)
Can support 1/16 steps
Support the use of Screw Terminal blocks for easier connections (like the L298N)
WHEN TO USE MICRO STEPPING?
Most stepper motors are based on 1.8 degrees steps.
This translate to 200 FULL steps per revolution (1 rotation = 360 degrees | 360 / 1.8 = 200)
Now when using FULL steps, the rotation of the stepper motor can be quite choppy,
especially at lower speeds.
The Easy Driver support of course FULL steps per default, but like we saw above also:
Half steps
1/4 steps
and 1/8 steps
For example if you set the micro stepping to 1/4 steps, then you would get 800 steps per revolution, making the rotation of the stepper motor much smoother.
So you might say: “Why not use micro stepping all the time then?”
Good question of course, but here’s a couple of reasons:
Micro Stepping is great but there are some trade-offs…
And most of those have to do with speed… Of both the stepper driver and the micro controller you are using.
You see when you use micro stepping, the stepper driver has to operate at a much faster speed to turn on and turn off power to the stepper motor coils compared to Full stepping.
Also the micro controller (in this case the Arduino UNO) has a speed limit at which it can send the commands to the stepper driver.
In fact, the AccelStepper library has a limit of 4000 steps per second maximum when using the Arduino UNO.
But you’ll never get even close to that in real life, since your Arduino will be doing something else (reading sensors, displaying on lcd, etc…) at the same time that’s it’s driving the stepper motor.
All this affect the maximum speed at which the stepper motor can rotate.
For example using Full steps you might be able to reach close to 4 rotation a second at max speed, well if using 1/4 steps that maximum speed might be reduced to only 1 rotation a second.
This has nothing to do with the Stepper Motor itself, it’s a combination of the stepper driver and the micro controller maximum speed at which it can turn on and off the motor coils.
One other compromise might be about the maximum torque that can be achieve.
Although this is debatable, using Full steps normally will result in higher torque compared to micro stepping.
So in conclusion, if you’re project requires maximum speed, maybe using Full steps is the way to go.
On the other hand if you need more precision, then using micro stepping is a better choice.
Keep in mind that using a faster micro controller and better stepper driver will affect these choices.
CONNECTION DIAGRAM
Here’s the connection that are used in this tutorial:
I’m using a 24V 5A power supply to power the Easy Driver and powering the Arduino using the USB input with a 5V USB power supply.
Arduino Pins A4 and A5 are connected to pins SDA and SCL on Old screen.
Arduino Pin A0 is connected to the Analog OUT pin of the Analog Slider
Arduino Pin 7 is connected to the Tact Switch
Arduino Pin 5 and 6 are connected to the Easy Driver pin MS1 and MS2
Arduino Pin 12 and 13 are connected to the Easy Driver pin STEP and DIR
THE CODE
Like in the last tutorial I’m again using an Analog Slider to move and control the steep of the stepper motor.
Moving the slider slowly to the left will start moving the stepper to the left at a slow speed and the speed will increase the more I moved the Analog Slider.
Moving the slider to the right will do the same but in the opposite direction.
Sliding near the middle will stop the Stepper Motor.
I’m also using a small switch to toggle between the stepping options (Full, 1/2, 1/4, 1/8).
And a small Oled display to show those stepping options.
As always check out the tutorial video for more information.
/* Easy Driver with Analog Slider and Oled Micro Stepping
Created by Yvan / https://Brainy-Bits.com
This code is in the public domain...
You can: copy it, use it, modify it, share it or just plain ignore it!
Thx!
*/
#include <U8glib.h> // Library for OlED display https://github.com/olikraus/u8glib/
U8GLIB_SSD1306_128X32 Oled_Screen(U8G_I2C_OPT_FAST); // Init of the OLED using I2C
#include "AccelStepper.h"
// Library created by Mike McCauley at
// http://www.airspayce.com/mikem/arduino/AccelStepper/
// EasyDriver connections
#define dir_pin 13 // Pin 13 connected to Direction pin
#define step_pin 12 // Pin 12 connected to Step pin
#define MS1 5 // Pin 8 connected to MS1 pin
#define MS2 6 // Pin 9 connected to MS2 pin
// AccelStepper Setup
AccelStepper stepper(1, step_pin, dir_pin);
// 1 = Easy Driver interface
/* Configure type of Steps on Easy Driver:
// MS1 MS2
//
// LOW LOW = Full Step //
// HIGH LOW = Half Step //
// LOW HIGH = A quarter of Step //
// HIGH HIGH = An eighth of Step //
*/
#define Slider_Pin A0 // Arduino A0 Pin connected to the analog out of the Slider
#define change_switch 7 // Tact switch used to select stepping type
int change_switch_state=0; // used to debounce the switch
int current_stepping=0; // Used to store the current stepping type (0-5)
int Slider_Value; // Used to save the current Analog Slider Value
int Stepper_Speed; // Used to set the travel speed of the stepper motor
int Stepper_Direction; // Used to choose the direction of travel
void setup() {
Serial.begin(9600);
Stepper_Direction=stepper.currentPosition(); // Set the starting position of the stepper which is equal to zero at startup
pinMode(change_switch, INPUT_PULLUP);
pinMode(MS1, OUTPUT);
pinMode(MS2, OUTPUT);
pinMode(dir_pin, OUTPUT);
pinMode(step_pin, OUTPUT);
// set stepping type to FULL Steps
digitalWrite(MS1, LOW);
digitalWrite(MS2, LOW);
// Rotate screen 180 degrees on OLED, uncomment if required
//u8gDHT.setRot180();
// Select font to use
Oled_Screen.setFont(u8g_font_unifont);
Oled_Screen.setContrast(100); // Set oled contrast at startup
// Put stuff on OLED at startup
Oled_Screen.firstPage();
do {
Oled_Screen.drawStr( 0, 24, "Stepping = FULL");
}
while( Oled_Screen.nextPage() );
}
void loop() {
// Change Switch - Debounce using a delay() command
if (digitalRead(change_switch) == LOW && change_switch_state == 0) {
delay(100); // The higher the Delay the less chance of bouncing
change_switch_state=1;
current_stepping++;
switch (current_stepping) {
case 1:
digitalWrite(MS1, HIGH);
digitalWrite(MS2, LOW);
Oled_Screen.firstPage();
do {
Oled_Screen.drawStr( 0, 24, "Stepping = HALF");
}
while( Oled_Screen.nextPage() );
break;
case 2:
digitalWrite(MS1, LOW);
digitalWrite(MS2, HIGH);
Oled_Screen.firstPage();
do {
Oled_Screen.drawStr( 0, 24, "Stepping = 1/4");
}
while( Oled_Screen.nextPage() );
break;
case 3:
digitalWrite(MS1, HIGH);
digitalWrite(MS2, HIGH);
Oled_Screen.firstPage();
do {
Oled_Screen.drawStr( 0, 24, "Stepping = 1/8");
}
while( Oled_Screen.nextPage() );
break;
case 4:
digitalWrite(MS1, LOW);
digitalWrite(MS2, LOW);
current_stepping=0;
Oled_Screen.firstPage();
do {
Oled_Screen.drawStr( 0, 24, "Stepping = FULL");
}
while( Oled_Screen.nextPage() );
break;
}
} else {
if (change_switch_state == 1 && digitalRead(change_switch) == HIGH) {
change_switch_state=0;
}
}
Slider_Value=analogRead(Slider_Pin); // Read the value of the analog slider
if (Slider_Value > 575) { // If slider is moved to the Right
Stepper_Speed=map(Slider_Value,575,1023,1,700); // Map the Right value of the slider to a Speed value for the stepper
Stepper_Direction--; // Decrease the position to reach by one which will be used to move the stepper later
} else if (Slider_Value < 350) { // If slider is moved to the Left
Stepper_Speed=map(Slider_Value,350,0,1,700); // // Map the Left value of the slider to a Speed value for the stepper
Stepper_Direction++; // Increase the position to reach by one which will be used to move the stepper later
} else {
Stepper_Speed=0; // If slider is around the middle then don't move the stepper by setting the speed to zero
}
// Move the stepper to new position
stepper.moveTo(Stepper_Direction);
stepper.setSpeed(Stepper_Speed);
stepper.setMaxSpeed(1000);
// Do this until the stepper as reached the new destination
while (stepper.distanceToGo() != 0) { // if stepper hasn't reached new position
stepper.runSpeedToPosition(); // move the stepper until new position reached
}
Serial.println(current_stepping);
}
CONCLUSION
Just keep in mind the speed limit of the Arduino UNO when using micro-stepping.
In future tutorials I will start using more powerful Micro Controllers to see what a higher end setup might be able to achieve.
Of course this will be using more expensive parts, but it might be an interesting option for some projects.
Thanks for stopping by and hope to see you again soon! Cheers!
TUTORIAL VIDEO
DOWNLOAD
Copy and Paste the above code/sketch in your Arduino IDE software.
Link to the libraries used in this tutorial:
AccelStepper Library by Mike Mcauley: https://www.airspayce.com/mikem/arduino/AccelStepper/index
U8glib Library for OlED display https://github.com/olikraus/u8glib/