I have a combination of code via different examples. I was getting the smoothest operation of my stepper using an ir receiver and wanted to translate into a esp8266. I have been able to get it to run, but once I click up or down a single time in the Blynk app the ESP8266 "shuts off" I think I am missing something in the loop command.
Below is the code:
#include <Stepper.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// const int stepsPerRevolution = 32; // change this to fit the number of steps per revolution
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPLt-83w9m6"
#define BLYNK_TEMPLATE_NAME "RollerBlindControl2"
#define BLYNK_AUTH_TOKEN "************************"
#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
//Stepper myStepper(stepsPerRevolution, D8, D4, D6, D5);
Stepper small_stepper(STEPS, D8, D4, D6, D5);
bool Left;// = false;
bool Right;// = false;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*******";
char pass[] = "**************************";
//++ Start Setup +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void setup(){
Serial.begin(9600); // baudrate for serial comunication
Blynk.begin(auth, ssid, pass); // network information
// myStepper.setSpeed(70); // Speed for stepper motor
}
//-- Setup End ---------------------------------------------------------------------------------------------------------------------
BLYNK_WRITE(V2){ // read input from virtual pin V1
Left = param.asInt(); // assigning incoming value from pin V§1 to a variable
}
BLYNK_WRITE(V3){ // read input from virtual pin V0
Right = param.asInt(); // assigning incoming value from pin V0 to a variable
}
//void Stepper1 (int Direction, int Rotation){ // function for stepper motor control with 2 parameters
// for (int i = 0; i < Rotation; i++){ // for loop
//my_Stepper.step(Direction * 200); // 200 is 360 degree => change value if smaller then 360 degree is needing
//Blynk.run();
//}
//}
//++ Start Loop +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void loop() {
Blynk.run();
if (Left){ // if condition
// Stepper1(1, 10); // steppermotor rotates 10 times 360 degree right
//Serial.println("Right Turn");
Serial.println("Right Turn");
// myStepper.step(stepsPerRevolution);
small_stepper.setSpeed(1000); //Max seems to be 500
Steps2Take = -2048; // Rotate CW
small_stepper.step(Steps2Take);
//Left();
}
delay(20); // delay 20ms
if (Right){ // if condition
//Stepper1(-1, 10); // steppermotor rotates 10 times 360 degree left
//Serial.println("Left Turn");
Serial.println("Left Turn");
//myStepper.step(-stepsPerRevolution);
small_stepper.setSpeed(1000);
Steps2Take = 2048; // Rotate CCW
small_stepper.step(Steps2Take);
//Right();
}
delay(20); // delay 20ms
}
//-- Loop End ---------------------------------------------------------------------------------------------------------------------