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