Stepper does slight pause after each step() command


I’m building a small rock tumbler for polishing 3D-prints. I’m using a stepper motor I had lying to drive the thing but it does a small pause after each step command instead of just running smoothly. Is there any way to get it to not do the pause?

The motor is a bipolar luxorparts nema 17 controlled through a Adafruit TB6612, like this one
Libs used are: Button.h, Stepper.h and U8glib.h

I’ve tried with Stepper.h and CustomStepper but couldn’t get AccelStepper to work.

You can see the behaviour here. It’s an earlier version of the code but the problem is the same.

Here’s my code:

#include <Button.h>
#include <Stepper.h>
#include <U8glib.h>

const int potPin = A0;

Button startButton(12);
Button stopButton(13);

const int steps = 200;
const int rpm = 60;
Stepper stepper(steps, 4, 5, 6, 7);

U8GLIB_SSD1306_64X48 oled(U8G_I2C_OPT_NONE);

void setup() {

void loop()
	do {
	} while (oled.nextPage());

	if (startButton.pressed()) {
		long stepsLeft = getTotalSteps();

		while (stepsLeft > 0) {

			if (stopButton.pressed()) {


			stepsLeft = stepsLeft - steps;

// ~convert to hours 
long getTotalSteps() {
	int potValue = getHours();
	long hours = potValue * ((rpm * steps) * 60);
	return hours;

int getHours() {
	int potValue = analogRead(potPin);
	int value = map(potValue, 0, 1023, 1, 24);

	return value;

void drawStartPage(int value) {
	drawPage(value, "Run for");

void drawTimeLeft(int value) {
	int timeLeft = (value / steps) / 60;
	drawPage(value, "Time left");

void drawPage(int value, char text[]) {
	drawLine("Rock Tumbler", 8);
	drawLine("v1.0", 16);

	drawLine(text, 28);

	char time[5];
	sprintf(time, "%dh", value);

	drawLine(time, 44);

void drawLine(char text[], int line) {
	int x = (oled.getWidth() - oled.getStrWidth(text)) / 2;
	oled.drawStr(x, line, text);

Would epreciate any help!

I presume the slight pause is due to the time taken by the function drawTimeLeft().

If all you want to do is show the number of steps remaining then there is no need to update the entire display.

By the way it seems to me you are not counting "steps" but "revolutions" and IMHO it would make your program much easier to understand (for you as well as us) if you used variable names that reflect what is actually happening.


Ah, that may be it. I'll try and just update that row instead and see if the stutter disappears.

By the way it seems to me you are not counting "steps" but "revolutions"

Yeah you're right, the naming is a bit weird. I'm using steps/revolution with rpm to get minutes so I can get an aproximation of how long it will run. I'll try and refactor that to make it clearer.

Thanks for your help!

I recommend looking at the AccelStepper library - easier to combine with other code I reckon.