Dear Blynkers,
i am new in this community and looking for help for my ongoing project:
I am successfully controlling 4 stepper motors in realtime with the Accelstepper library on an Arduino DUE, using a local Blynk Server. For every stepper, I have two Widgets on the app, one for running the stepper clockwise when pushed, one for running counterclockwise (see code below). The project is working really fine as long as I keep the Arduino connected to my Android Device via Bluetooth (HC-05). All steppers are running smoothly with acceleration. To make things easier to understand, this is a working sketch for only one stepper:
#include <AccelStepper.h>
#include <BlynkSimpleSerialBLE.h>
#define BLYNK_PRINT Serial
AccelStepper stepper1(1, 4, 7);
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
char auth[] = "******************************"; //
#define boardEnable 8 // defines pin 8 for enabeling CNC Shield when set to low.
void setup()
{
pinMode(boardEnable, OUTPUT);
digitalWrite(boardEnable, LOW); // IMPORTANT!!! Enables CNC-Shield to work
// Debug console
Serial.begin(9600);
Serial1.begin(9600);
Blynk.begin(Serial1, auth);
Serial.println("Waiting for connections...");
delay(50);
stepper1.setMaxSpeed(1000);
stepper1.setAcceleration(5000);
}
BLYNK_WRITE(V1) // Button to move Z Axis forward
if(param.asInt() == 1)
{
stepper1.moveTo(200); // Full speed Z axis forward while button is pushed
}
else if (param.asInt() == 0)
{
stepper1.stop(); // Stop as fast as possible
stepper1.runToPosition();
}
}
BLYNK_WRITE(V2) // Button to move Z Axis backwards
if(param.asInt() == 1)
{
stepper1.moveTo(102000); // Full speed Z axis backwards while button is pushed
}
else if (param.asInt() == 0)
{
stepper1.stop(); // Stop as fast as possible
stepper1.runToPosition();
}
}
void loop()
{
Blynk.run();
stepper1.run();
}
Now I want to run the exact same project with the Arduino DUE connected to an ESP8266 as WIFI shield (need increased range). I only changed parts of the code that are necessary for the Arduino to talk with the ESP8266, and of course to connect to the local Server. After uploading, the WIFI connection is stable, and all other functions in the project besides moving the steppers are working when the connection via 8266 is established (like switching valves and stuff, not mentioned in the code below), BUT: The stepper motors are moving very, very slow, with a strange noise, almost stuttering. Changes in stepper1.setMaxSpeed(1000) don´t affect on the actual speed… like this they will be not usable for my project! Here is the sketch with WIFI connection:
#include <AccelStepper.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#define BLYNK_PRINT Serial
AccelStepper stepper1(1, 4, 7);
// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1
char auth[] = "**********************************";
char ssid[] = "***************";
char pass[] = "***********";
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define boardEnable 8 // defines pin 8 for enabeling CNC Shield when set to low.
void setup()
{
pinMode(boardEnable, OUTPUT);
digitalWrite(boardEnable, LOW); // IMPORTANT!!! Enables CNC-Shield to work
// Debug console
Serial.begin(9600);
//Serial.println("Waiting for connections...");
//Serial1.begin(9600);
EspSerial.begin(ESP8266_BAUD);
delay(50);
Blynk.begin(auth, wifi, ssid, pass, "XXX.XXX.XX.X", 8080); // including IP-Adress
pinMode(boardEnable, OUTPUT);
digitalWrite(boardEnable, LOW);
stepper1.setMaxSpeed(1000);
stepper1.setAcceleration(5000);
}
BLYNK_WRITE(V1) // Button to move Z Axis forward
{
if(param.asInt() == 1)
{
stepper1.moveTo(200); // Full speed Z axis forward while button is pushed
}
else if (param.asInt() == 0)
{
stepper1.stop(); // Stop as fast as possible
stepper1.runToPosition();
}
}
BLYNK_WRITE(V2) // Button to move Z Axis backwards
{
if(param.asInt() == 1)
{
stepper1.moveTo(102000); // Full speed Z axis backwards while button is pushed
}
else if (param.asInt() == 0)
{
stepper1.stop(); // Stop as fast as possible
stepper1.runToPosition();
}
}
void loop()
{
Blynk.run();
stepper1.run();
}
As there was no change made in the void loop () compared to the working Bluetooth version, I guess something of the library for the ESP8266 is maybe blocking blynk.run or the stepper.run?
I already tried out a lot for a week now and did a lot of research on the web but without success. Would be so glad for every hint from the community to make my project run properly with the ESP8266!
Cheers!
Andreas