Ok this is how I got my stepper to work smoothly.
ESP8266 D1 Mini Code
/*
AquArt Blynk StepperMotor_Esp
WRITTEN BY MARIANO PROIETTI
16 CRANE AVENUE
ISLEWORTH
MIDDLESEX, TW7 7JL
TEL. 07771 528 969
*/
/*BLYNK APP
* V0 TIME TAG
* V1 DATE TAG
* V5 TITLE TAG
* V6 STEP MODE SELECTION
* V7 SPEED GAUGE
* V8 TIME INPUT
* V9 SPEED INPUT
*/
//LIBRARIES//
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h> //For OTA w/ ESP8266
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <TimeLib.h>
#include <WidgetRTC.h>
BlynkTimer timer;
WidgetRTC rtc;
//PIN ASSIGNMENTS//
#define ACTIVE D1
#define SPEED D2
#define M0 D5
#define M1 D6
#define M2 D7
#define LEDON D4
//WIFI GLOBALS//
char modulename[] = "AquArt IntelliPUMP 1"; //Insert app name
int ReCnctFlag; //Reconnection Flag
int ReCnctCount = 0; //Reconnection counter
char auth[] = "";
char ssid[] = "";
char pass[] = "";
char server[] = "blynk-cloud.com"; //URL for Blynk Cloud Server
int port = 8080;
//GLOBALS//
int Mode;
int Speed;
int svSpeed;
//RTC & TIME IMPUT ATTRIBUTES & VARIABLES
char currentTime[9]; //RTC time
char currentDate[11]; //RTC date
//CONNECT TO BLYNK SERVER//
BLYNK_CONNECTED()
{
Blynk.syncAll();
rtc.begin();
ReCnctCount = 0;
ArduinoOTA.setHostname(modulename);
ArduinoOTA.begin();
}
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, pass);
Blynk.config(auth, server, port);
Blynk.connect();
setSyncInterval(30);
Blynk.virtualWrite(V5, "IntelliPUMP 1");
pinMode(M0, OUTPUT);
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(DIR, OUTPUT);
pinMode(ACTIVE, OUTPUT);
pinMode(SPEED, OUTPUT);
pinMode(LEDON, OUTPUT);
timer.setInterval(1000L, ClockDisplay);
}
void loop()
{
timer.run();
ArduinoOTA.handle();
if (Blynk.connected())
{
Blynk.run();
digitalWrite(LEDON, HIGH);
}
else if (ReCnctFlag == 0)
{
ReCnctFlag = 1;
timer.setTimeout(5000L, []()
{
ReCnctFlag = 0;
ReCnctCount++;
Blynk.connect();
digitalWrite(LEDON, LOW);
});
}
}
//BLYNK FUNCTIONS////////////////////////////////////////////////////////////////////
BLYNK_WRITE(V6)
{
Mode = param.asInt();
{
switch (Mode)
{
case 1: //FULL STEP
{
digitalWrite(M0, LOW);
digitalWrite(M1, LOW);
digitalWrite(M2, LOW);
break;
}
case 2: //1/2 STEP
{
digitalWrite(M0, HIGH);
digitalWrite(M1, LOW);
digitalWrite(M2, LOW);
break;
}
case 3: //1/4 STEP
{
digitalWrite(M0, LOW);
digitalWrite(M1, HIGH);
digitalWrite(M2, LOW);
break;
}
case 4: //1/8 STEP
{
digitalWrite(M0, HIGH);
digitalWrite(M1, HIGH);
digitalWrite(M2, LOW);
break;
}
case 5: //1/16 STEP
{
digitalWrite(M0, LOW);
digitalWrite(M1, LOW);
digitalWrite(M2, HIGH);
break;
}
case 6: //1/32 STEP
{
digitalWrite(M0, HIGH);
digitalWrite(M1, LOW);
digitalWrite(M2, HIGH);
break;
}
case 7: //CALIBRATION MODE CODE STILL TO BE WRITTEN
{
}
}
}
}
BLYNK_WRITE(V8)
{
TimeInputParam t(param);
StTime = (t.getStartHour() * 3600) + (t.getStartMinute() * 60);
SpTime = (t.getStopHour() * 3600) + (t.getStopMinute() * 60);
int dayadjustment = -1;
if(weekday() == 1)
{
dayadjustment = 6;
}
if (t.isWeekdaySelected((weekday() + dayadjustment)))
{
if(t.hasStartTime())
{
digitalWrite(ACTIVE, HIGH);
}
else if(t.hasStopTime())
{
digitalWrite(ACTIVE, LOW);
}
}
else
{
digitalWrite(ACTIVE, LOW);
}
}
BLYNK_WRITE(V9)
{
Speed = param.asInt();
svSpeed = map(Speed, 0, 100, 0, 1023);
analogWrite(SPEED, svSpeed);
Blynk.virtualWrite(V7, Speed);
}
//CLOCK FUNCTIONS////////////////////////////////////////////////////////////////////
void ClockDisplay()
{
sprintf(currentTime, "%02d:%02d:%02d", hour(), minute(), second());
sprintf(currentDate, "%02d/%02d/%04d", day(), month(), year());
Blynk.virtualWrite(V0, currentTime); //Send time to TIME widget
Blynk.virtualWrite(V1, currentDate); //Send date to DATE widget
}
Arduino Nano Code
/*
AquArt Blynk StepperMotor_Nano
WRITTEN BY MARIANO PROIETTI
16 CRANE AVENUE
ISLEWORTH
MIDDLESEX, TW7 7JL
TEL. 07771 528 969
*/
//LIBRARIES//
#include <AccelStepper.h>
//PIN ASSIGNMENTS//
#define DIR 2
#define STP 3
#define M0 4
#define M1 5
#define M2 6
#define ACTIVE 7
#define svM0 9
#define svM1 10
#define svM2 11
//ACCELSTEPPER GLOBALS//
#define motorInterfaceType 1
AccelStepper stepper = AccelStepper(motorInterfaceType, STP, DIR);
//GLOBALS//
int Speed;
int SpeedValue;
int ActiveValue;
void setup()
{
stepper.setMaxSpeed(1000);
pinMode(M0, INPUT);
pinMode(M1, INPUT);
pinMode(M2, INPUT);
pinMode(ACTIVE, INPUT);
pinMode(svM0, OUTPUT);
pinMode(svM1, OUTPUT);
pinMode(svM2, OUTPUT);
}
void loop()
{
StepResolution();
ActiveValue = digitalRead(ACTIVE);
if (ActiveValue == HIGH)
{
SpeedValue = analogRead(A0);
Speed = map(SpeedValue, 0, 1023, 300, 1000);
stepper.setSpeed(Speed);
stepper.runSpeed();
}
else
{
stepper.stop();
}
}
void StepResolution()
{
if (digitalRead(M0) == LOW && digitalRead(M1) == LOW && digitalRead(M2) == LOW)
{
digitalWrite(svM0, LOW);
digitalWrite(svM1, LOW);
digitalWrite(svM2, LOW);
}
else if (digitalRead(M0) == HIGH && digitalRead(M1) == LOW && digitalRead(M2) == LOW)
{
digitalWrite(svM0, HIGH);
digitalWrite(svM1, LOW);
digitalWrite(svM2, LOW);
}
else if (digitalRead(M0) == LOW && digitalRead(M1) == HIGH && digitalRead(M2) == LOW)
{
digitalWrite(svM0, LOW);
digitalWrite(svM1, HIGH);
digitalWrite(svM2, LOW);
}
else if (digitalRead(M0) == HIGH && digitalRead(M1) == HIGH && digitalRead(M2) == LOW)
{
digitalWrite(svM0, HIGH);
digitalWrite(svM1, HIGH);
digitalWrite(svM2, LOW);
}
else if (digitalRead(M0) == LOW && digitalRead(M1) == LOW && digitalRead(M2) == HIGH)
{
digitalWrite(svM0, LOW);
digitalWrite(svM1, LOW);
digitalWrite(svM2, HIGH);
}
else if (digitalRead(M0) == HIGH && digitalRead(M1) == LOW && digitalRead(M2) == HIGH)
{
digitalWrite(svM0, HIGH);
digitalWrite(svM1, LOW);
digitalWrite(svM2, HIGH);
}
else
{
digitalWrite(svM0, LOW);
digitalWrite(svM1, LOW);
digitalWrite(svM2, LOW);
}
}
//END//
Hope this is of some help to you.