Stepper does slight pause after each step() command

Hi!

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() {
	stepper.setSpeed(rpm);
}

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

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

		while (stepsLeft > 0) {
			stepper.step(steps);

			if (stopButton.pressed()) {
				break;
			}

			drawTimeLeft(stepsLeft);

			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[]) {
	oled.setFont(u8g_font_04b_03);
	drawLine("Rock Tumbler", 8);
	drawLine("v1.0", 16);

	oled.setFont(u8g_font_helvB08);
	drawLine(text, 28);

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

	oled.setFont(u8g_font_helvB12);
	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!
/Peter

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.

...R

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

Robin2:
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.