Accelstepper: Issues when updating working project from Bluetooth to WIFI ESP8266

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. :slight_smile: 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

Isn’t pin 1 the TX pin for the Serial port (UART1) ?

Pete.

Hi Pete,

i´m highly appreciating your help!

In this definition, numbers describing the following, according to the Accelstepper documentation:
1 = Type of Driver
4 = pin for step
7 = pin for direction

https://www.airspayce.com/mikem/arduino/AccelStepper/classAccelStepper.html#a3bc75bd6571b98a6177838ca81ac39ab
So pin 1 is not occupied by the Accelstepper library in my current setup… if it were, it wouldn´t work with the Bluetooth version either, would it?
Any other hints for why steppers are not running properly when connectetd to WIFI?
Thanks for your help,
Andreas

What sort pf ping time are you seeing reported in the serial monitor when Blynk connects?

Have you checked all of your wiring?

Pete.

Blynk’s use of BT/BLE was always a lower “call it priority?” setup then via WiFi. As BT/BLE was only a link between the Device and the App, using the App to do the Server link. However, WiFi is a direct and constant connection between the device and the Server.

Both BT/BLE and WiFi as shields mean the commonality is the Serial link. As there is more communication across WiFi, there may be a bit of a bandwidth bottleneck when running only 9600 baud. Something not noticeable except with another timing sensitive process like stepper control.

Since you are using a Hardware Serial connection between the DUE and ESP, try reconfiguring your ESP-as-Shield to 115200, as well as in your sketch.

Ping time is always arround 50ms on Local Server, which i think is pretty OK.

Wires on hardware are OK since everything runs smooth with BT. The only change is the replacing of the HC-05 module with the ESP-01 adapter with the 8266 on it.

Thanks for this information, i will try it with 115200.
Will report here soon about the result!
Andreas

Also, as you are running a Local Server, and using virtual pins, you might want to test adding these into your sketch…

#define BLYNK_MSG_LIMIT 0  // Possibly disable or limit the anti-flooding, aka "nanny mode" built in delays if trying to do too-much-too-fast.
#define BLYNK_NO_BUILTIN  // Disable the built-into-App analog & digital pin operations

Just tried it with 115200. Pingtime improved down to 15ms, but the stepper still is running strange.

Then i tried your last hint:

…but no success with that.

Strangewise, the deceleration part (when Arduino gets a “0” from the Blynk-Widget) runs smooth. Means, that when i push the Widget on the app (throwing a “1” ), stepper runs very slow and noisy. When i release the Widget (throwing “0”), the stepper decelerates as if he was fast running before, and smoothly slowes down. Maybe it is something with the AccelStepper library?

But then again, why it would run when connection is Bluetooth? Still really mysterious to me…

When you are triggering a 1 action, your code is actively doing something that requires the MCU to manage each pulse… stepper1.moveTo()

Again, I believe it all has to do with timing. Blynk has somewhat critical timing as it is in constant communication with the server. Also longer pings to and from server vs. just the phone, at least with WiFi, much less so I believe when using BT/BLE as somewhat confirmed in your testing, but then there are other limitations as well.

Stepper control is very timing constrained, particularly when the MCU is literally controlling each and every pulse. In the past I experimented with using Blynk with stepper control, but over a separate MCU for the stepper. Basically the same idea as many dedicated stepper controllers that just take the instructions and handle all the micromanagment work (pulses) within themselves.

2 Likes

Thanks a lot for this @Gunner !
Sounds logical to me… think i will follow your hint and try running Blynk on the ESP8266 and have the DUE just for the stepper.
I just hope it is not too tricky to send information (like current stepper position etc) from the Arduino back to the ESP and finally on the app. Gonna have to try, will take some time…