[Solved] Esp8266 millis() crash

I want write code with led matrix without delay, i use library "MD_MAX72xx.h", but when i add millis(), esp8266 has been crash "Soft WDT reset". Please help me!
Here my code, sorry my english

#include <MD_MAX72xx.h>
/**********************************************************************************/
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES  4

#define CLK_PIN   D5
#define Din_PIN   D7
#define CS_PIN    D8

MD_MAX72XX mx = MD_MAX72XX(HARDWARE_TYPE, Din_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

/**********************************************************************************/
void setup()
{
  mx.begin();
}
/**********************************************************************************/
void loop()
{
  String text = "Arduino";

  scrollString(text);
}
/**********************************************************************************/
void scrollChar(char *p)
{
  uint8_t charWidth;
  uint8_t cBuf[8];

  mx.clear();

  uint32_t previousMillis = 0;

  while (*p != '\0')
  {
    charWidth = mx.getChar(*p++, sizeof(cBuf) / sizeof(cBuf[0]), cBuf);
    uint8_t i = 0;
    while (i <= charWidth)
    {
      if (millis() - previousMillis >= 50)
      {
        previousMillis = millis();
        mx.transform(MD_MAX72XX::TSL); 
        if (i < charWidth) {
          mx.setColumn(0, cBuf[i]);
        }
        i++;
      }
    }
  }
}
/**********************************************************************************/
void scrollString(String newMessage)
{
  mx.clear();

  String newMessagePlus = newMessage + "           "; // + blank

  int len = newMessagePlus.length() + 1; 
  char charArray[len];
  newMessagePlus.toCharArray(charArray, len);
  scrollChar(charArray);
}

i'm not familiar with the esp32, but based on your comments, it seems that loop() should not take too long otherwise there is a watchdog timer reset.

by adding the code with millis() it looks like you want to delay the update of each digit by 50 msec which takes 400 msec for all 8 digits.

if this is what you really want to do (instead possibly just updating the entire delay every 50 msec) then you would need to check if 50 msec has elapsed in loop() and call a routine to update a specified digit with a specified character, allowing loop() to return whether the condition is true or not.

gcjr:
i'm not familiar with the esp32, but based on your comments, it seems that loop() should not take too long otherwise there is a watchdog timer reset.

by adding the code with millis() it looks like you want to delay the update of each digit by 50 msec which takes 400 msec for all 8 digits.

if this is what you really want to do (instead possibly just updating the entire delay every 50 msec) then you would need to check if 50 msec has elapsed in loop() and call a routine to update a specified digit with a specified character, allowing loop() to return whether the condition is true or not.

thank you for help.

I want variable "i" increse every 50ms in while() loop in scrollChar(char *p) function

You should post all your code for proper response, but you cold try adding the yield() statement in your while() loop to see if the problem goes away.

6v6gt:
You should post all your code for proper response, but you cold try adding the yield() statement in your while() loop to see if the problem goes away.

thank for reply.
i add yield() and it work, but i don't know yield() mean

yield() can be used in a loop to refresh the watchdog timer and allow other activities to proceed (such as servicing the wlan functions) preventing these crashing your program.

On the ESP8266, any uninterrupted loops must be short (a few mS) otherwise you could have this problem.

Hello hoangduong93bg

Maybe you could have look at :
https://www.sigmdel.ca/michel/program/esp8266/arduino/watchdogs_en.html#ESP8266_WDT_TIMEOUT

Regards,
bidouilleelec

6v6gt:
yield() can be used in a loop to refresh the watchdog timer and allow other activities to proceed (such as servicing the wlan functions) preventing these crashing your program.

On the ESP8266, any uninterrupted loops must be short (a few mS) otherwise you could have this problem.

thank you so much

bidouilleelec:
Hello hoangduong93bg

Maybe you could have look at :
ESP8266 Watchdogs in Arduino

Regards,
bidouilleelec

Thank you, interesting information