Hi all,
I’m using Blynk with ESP8266 standalone to control a stepper.
I find when the stepper is reaching a long distance, which takes more than 5 seconds.
The ESP will get a wdt msg and restart, then blynk disconnects.
Is this a known issue?
I noticed a post about calling blynk.run() inside a time-cost function. I don’t know if this is the root cause.
I’n not sure how you define your time cost, but the use of “delay()” could be a cause. I’d try without it. You can use millis(). That should work better, but is a bit more complicated. I’ve written a little subroutine to accomplish this:
unsigned long previousMillis = 0;
boolean state = 1;
void loop
{
previousMillis = millis(); // Reset counter
wait(5000); // Wait with interval period
state = 1; // Reset waiting state
}
void wait(unsigned long interval)
{
// Compare previous millis to current one and wait until the interval has been reached in a do loop
// Also set / reset waiting states so the loop keeps looping until the interval has been reached
do
{
if((unsigned long)(millis() - previousMillis) >= interval)
{
previousMillis = millis();
state = 0;
break;
}
}
while (state = 1);
}
This way you can use the function everywhere you want to wait. I hope this helps a bit
I use the stepper library shipped with arduino. Maybe I need to dig inside to see if delay is used. If there is, maybe I want to try your hacked delay. Thanks!
Stepper library also takes use of millis . When I put the step(some distance) in a while loop, with stop condition of some IO state, the ESP will begin to restart very soon during moving
i’m not an expert on this, but i have been working the past weeks with steppers now, and starting to get something that looks promising
The difference is that i’m using a stepper driver compared to you.
I specifically use it to run the motor while pressing a button-widget, and i’m not sure why. but sometimes it get chunky movements. i think it might be because of blynk.run sometimes taking to long due to slow connection.
If your problems isn’t solved, post your code and we can take a look
Hi. As i told you i havn’t tried to work with the stepper.h library because i use a stepper driver.
But your problem looks like mine, the steps take up to long time.
The while loop. You just want it to run until hitting the some switch, right?
if so you could probably do it with the code:
while(digitalRead(STOPPIN))
{
Blynk.run();
stepper.step(5); // try with a low number of steps to avoid each stepper.step() taking to long
}
the other isue is when you want to move precisely 3000 steps.
maybe this will work.
int j = 0
while(j < 3000)
{
Blynk.run();
stepper.step(5); // again avoid to many steps
j = j+5
}
The movement might get a little chunky depending you connection to blynk server. thats my experience anyway. Keep in mind that i haven’t tested it. but i think the idea should work
@Pavel I saw you followed this thread Do you have any better ideas/ workarounds? Or maybe some solution blynk-side
Thanks for your detailed feedback. I’m guessing that the wdt issue is caused easily if we failed in calling Blynk.run() inside active thread. So your solution might work. Will try later after work. Thanks again.
Also I use slider on virtual pin 7. When I tap a long distance to reach, wdt issue happens too. So should I put Blynk.run() inside BLYNK_WRITE(7) {} ? It may cause another heap memory problem, as I saw in another post…
The slider issue i dont have a solution for. The blynk.run() shouldn’t go inside BLYNK_WRITE(). I haven’t had any luck with it, also referring to the link i posted erlier.
Depending on how you want to use the slider, maybe the slider could write a variable and then a function who runs the stepping stuff and reading the value from the slider through the variable. This way you can still put Blynk.run () inside the function. and every time the slider-state is changed the variable is rewritten and the function is called again.