I have a problem with my current project :
I want to make a stepper motor turn and control the speed with a rotary encoder + display the number of turn made by the motor on a i2c oled display.
I use a SSD1306 oled and A4988 stepper driver.
The speed control work great with the non blocking Encoder library + the Accelstepper library.
But the problem i have is when i try to display the number of turn, the time spend by the arduino to print on the oled screen stop the motor a fraction of second so my motor doesn't run smoothly...
How i can fix that ? is it possible to print on a Oled screen while controlling a stepper motor ?
Thanks for your help.
My code :
#include "SSD1306Ascii.h"
#include "SSD1306AsciiAvrI2c.h"
#define I2C_ADDRESS 0x3C
SSD1306AsciiAvrI2c oled;
#define ENCODER_DO_NOT_USE_INTERRUPTS
#include <Encoder.h>
#include <AccelStepper.h>
AccelStepper stepper(1, 9, 8);
Encoder myEnc(2, 3);
b
int TurnsDone = 0;
void setup() {
oled.begin(&Adafruit128x64, I2C_ADDRESS);
oled.setFont(Adafruit5x7);
Serial.begin(9600);
oled.clear();
stepper.setMaxSpeed(1000);
stepper.setSpeed(50);
}
long position = -999;
void loop() {
stepper.runSpeed();
long newPos = myEnc.read();
if (newPos != position) {
position = newPos;
Serial.println(position);
}
stepper.setSpeed(position*10);
if (stepper.currentPosition() == TurnsDone * 200)
{
oled.clear();
oled.print(TurnsDone);
}
TurnsDone = stepper.currentPosition() / 200;
}