I’ve rewrite the code and now it works!!
//
// max step/s=2000 max accel 40000step/s^2
//
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "xxxx"
#define BLYNK_DEVICE_NAME "Stepper"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
#define USE_WEMOS_D1_MINI
#include <AccelStepper.h>
#include "BlynkEdgent.h"
int LED = 16; //GPIO16 -- D0
int DIR = 4; //GPIO04 -- D2
int STEP = 12; // GPIO12 --D6
int EN = 14; //GPIO14 -- D5;//Enable Pin
double meal = 1.0;
int Totalsteps = 0;
int steps = 7500;
//int Direction = 0;
//int Run = 0;
AccelStepper mystepper(1,STEP, DIR);
BLYNK_WRITE(V0)
{
int pinValue=param.asInt(); //assigning icoming valure from pin V0 to a variable
digitalWrite(LED, pinValue); // low activate led High switch off
}
//BLYNK_WRITE(V1)
//{
// Direction=param.asInt(); //assigning icoming valure from pin V1 to a variable
//}
BLYNK_WRITE(V2)
{
meal=param.asDouble(); //assigning icoming valure from pin V2 to a variable
}
BLYNK_WRITE(V3)
{
int Run=param.asInt(); //assigning icoming valure from pin V3 to a variable
if (Run==1) {
Totalsteps = meal*steps*2;
Serial.println("-----------Led ON Enable ON------");
digitalWrite(LED, HIGH);
digitalWrite(EN, LOW);
Serial.println("--------------------");
Serial.println("RUN");
Serial.println(Run);
Serial.println("meal");
Serial.println(meal);
Serial.println("Totalsteps");
Serial.println(Totalsteps);
Serial.println("--------------------------");
mystepper.move(-Totalsteps);
mystepper.runToPosition();
// Serial.println("steps to go");
// Serial.println(mystepper.distanceToGo());
//while (mystepper.distanceToGo()!=0){
// mystepper.run();
// Serial.println("steps to go");
// Serial.println(mystepper.distanceToGo());
//}
Serial.println("-----------Led OFF Enable OFF------");
digitalWrite(LED, LOW);
digitalWrite(EN, HIGH);
}
}
void setup()
{
pinMode(LED, OUTPUT);
pinMode(DIR, OUTPUT);
pinMode(STEP, OUTPUT);
pinMode(EN, OUTPUT);
Serial.begin(115200);
digitalWrite(EN, HIGH);
delay(100);
mystepper.setMaxSpeed(600); // valore originale 50
mystepper.setAcceleration(1000);
BlynkEdgent.begin();
}
void loop()
{
BlynkEdgent.run();
}
I still need to optimize it but up to now I’m happy thanks for support.
Mario