Can we declare BlynkTimer in microseconds?

Hello,

I was currently trying to move my stepper motor with the help of AccelStepper and Blynk app through NodeMCU and TB6600 Motor Driver.

I added a blynktimer named timer in my code so that it does not cause wet reset.

But the problem is that the timer is in milliseconds i.e. 1 millisecond, but that is causing the stepper motor to run very slow. I need to know that is there any way to declare the timer in microseconds or either we have to use any other timer. Then please also specify that timer because I am new to these things.

If you needed to do timing in microseconds then if your code was well written you shouldn’t be getting wdt reset issues.
BlynkTimer uses milliseconds, not microseconds.

If you want to do timing in microseconds then you can compare the current micros() value with the value from when your timing loop began, in just the same way that you’d do this using a millis() comparison.
If you do a quick search you’ll find many examples of using millis() in this way.

The important thing from a Blynk perspective is that you process a Blynk.run() command as frequently as possible. This would normally be done in the void loop, but if your stepper processing code is running in a loop that prevents the code returning to the void loop frequently enough then you’ll need to add Blynk.run() into your stepper loop.
This may well cause you timing issues with your stepper, but that’s something you’ll need to live with if you’re using Blynk in this way. An alternative approach is to use two MCUs - one to talk to Blynk and the other to control the stepper. If you sea h the forum there are a few recent discussions about this approach.

Pete.

1 Like

Thanks for the help! I created my own timer in microseconds and it is working!!

I also tried 1 MCU and UNO communication that takes a lot of time thus decreasing the speed.

Creating the own timer is the best idea.

here is the code for my timer for the help of other people.

Declare Global Variables

const unsigned long eventInterval = 0.1;
unsigned long previousTime = 0;

Code for Timer Function

  void AnshTimer() {
  unsigned long int currentTime = micros();
  if (currentTime -  previousTime >= eventInterval) {
    stepperControl();
    previousTime = currentTime;
  }
}

so your trying to work in pico seconds :grinning:

If you want to do it properly then this is the sort of hardware you’d need to be using…

Pete.