Help with P5 RGB64x32 Matrix Clock with ESP32

Finally, I want to express here a principle that I hold dear, perhaps my own ideology.

Although I am in a forum about Arduino programming, I am nowhere near that, in fact, as I have already said here, I have great difficulties with the subject; if it weren't for that, I wouldn't be here asking for help. I am a retired musician from a Military Band. But, if this were a music forum, I wouldn't hesitate for a second if someone asked about any music-related subject, as long as I knew about it, and I would clarify everything with a good heart. Having said that, I thank everyone who, in some way, helped me. Cheers to all.

Click the link. Read the read.me. Lookk at the example sketches. In fact there is a clock example. SmartMatrix/examples/MatrixClock/MatrixClock.ino at master · pixelmatix/SmartMatrix · GitHub

Ok question to you:

I know nothing about music.
I have put three notes together
C fis b
I want to sound it like an orchestra.
Can you compose the missing tabulature?

To be honest, I feel that your arduino project is way too ambitious. Unfortunately, you combined that with a bad start with code you took from the internet.
You were told it will not work, but you wanted us to fix it. Would we ask a musician to fix a violin with broken neck with cellotape?

I am sorry we could not fix your problem. We are a bunch of volunteers trying to help. We are not a coding for free service...

xfpd

Thank you; yes, I'll take a look.

It doesn't work for me, but it works for others!?

That's the question!

Whom?

We understand that you are doing your best to make this work, and asking question to help solve this. When I was the struggling student, my response to my teacher asking "any questions?" was "What questions should I ask?" to which they would say something like, "Read the chapter/book." Which, to me, was no help.

Here, I am the student (I am listening to you), and you are the teacher (you have the things). The first thing I noticed was your topic title containing "P5"... and asking why a library containing "P3" in the title does not work. My first question to you, as I am now a confused student, is, "Does a P3 library work with a P5 display?" because if "no" is the answer, then I would say, "You need a P5 library."

This library seems to handle a variety of "Px" forms... GitHub - 2dom/PxMatrix: Adafruit GFX compatible graphics driver for LED matrix panels · GitHub

This Waveshare wiki seems to be for P5... https://www.waveshare.com/wiki/RGB-Matrix-P5-64x32

If you have questions about the instructions inside these links, ask, but they seemed good enough for anyone tinkering with them, not expecting an off-the-shelf experience.

That library is very old, over 7 years. It is possible that you may need to use the ESP32 board package, as well as the Adafruit_GFX and WiFi libraries, that were available at that time to get it to work as expected, although I think that is highly unlikely to help. I can say for certain that it will not compile with the current version of the ESP32 board package.

There could be something about the specific display that was being used that behaves differently from your display, as @xfpd has pointed out.

As a test, see if the following sketch will run without blinking or skipping seconds. The double buffering may be requiring a very long time to update the entire display.

#include <WiFi.h>

#include <Adafruit_GFX.h>
#include <P3RGB64x32MatrixPanel.h>
#include <Fonts/FreeSansBold9pt7b.h>

// constructor with default pin wiring
P3RGB64x32MatrixPanel matrix;

char ssid[] = "Xxxxxxx";
char pass[] = "Xxxxxxxxxxxx";

#define TZ (-3*60*60) /*JST*/

time_t last_t;
const char* const wd[7] = {"Domingo", "Segunda", "Terca", "Quarta", "Quinta", "Sexta", "Sabado"};

void setup() {
  Serial.begin(115200);

  Serial.print("Attempting to connect to Network named: ");
  Serial.println(ssid);                   // print the network name (SSID);

  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println("");
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  configTime(TZ, 0, "ntp.nict.jp", "ntp.jst.mfeed.ad.jp"); // enable NTP

  matrix.begin();                           // Configura a matriz de LEDs

  initializeDisplay();
}

void initializeDisplay() {
  matrix.fillScreen(0);
  matrix.setFont(&FreeSansBold9pt7b);
  matrix.setCursor(0, 13);
  last_t = time(NULL);
  struct tm* tm = localtime(&last_t);
  matrix.setTextColor(matrix.color444(15, 15, 15));
  matrix.printf("%02d:%02d", tm->tm_hour, tm->tm_min);
  matrix.setFont();
  matrix.printf(":%02d", tm->tm_sec);
}

void loop() {
  time_t t;
  struct tm *tm;

  t = time(NULL);
  if (last_t == t) return; // desenha cada segundo
  
  char current[11];
  char previous[11];
  tm = localtime(&last_t);
  struct tm tmPrev = *tm;
  //struct tm tmPrev = *localtime(&last_t);
  tm = localtime(&t);
  if ((tmPrev.tm_hour != tm->tm_hour) || (tmPrev.tm_min != tm->tm_min)) {
    sprintf(previous, "%02d:%02d", tmPrev.tm_hour, tmPrev.tm_min);
    sprintf(current, "%02d:%02d", tm->tm_hour, tm->tm_min);
    matrix.setFont(&FreeSansBold9pt7b);
    matrix.setCursor(0, 13);
    updateText(previous, current, matrix.color444(15, 15, 15), 0);
  }

  matrix.setFont();
  matrix.setCursor(50, 7);
  sprintf(previous, "%02d", tmPrev.tm_sec);
  sprintf(current, "%02d", tm->tm_sec);
  updateText(previous, current, matrix.color444(15, 15, 15), 0);

  last_t = t;
  
  //check WiFi connection status
  const unsigned long statusCheckInterval = 30000; //30 seconds
  static unsigned long previousMillis = millis() - statusCheckInterval;
  if ((WiFi.status() != WL_CONNECTED) && ((millis() - previousMillis) >= statusCheckInterval)) {
    Serial.println("WiFi connection lost, reconnecting...");
    WiFi.disconnect();
    WiFi.reconnect();
    previousMillis = millis();
  }
}

void updateText(const char* oldText, const char* newText, const uint16_t colorForeground, const uint16_t colorBackground) {
  if (strlen(newText) != strlen(oldText)) {
    return;
  }
  matrix.setTextColor(colorForeground);
  while (*newText) {
    if (*oldText != *newText) {
      int cursorPosX = matrix.getCursorX();
      int cursorPosY = matrix.getCursorY();
      matrix.setTextColor(colorBackground);
      matrix.print(*oldText);
      matrix.setTextColor(colorForeground);
      matrix.setCursor(cursorPosX, cursorPosY);
    }
    matrix.print(*newText);
    oldText++;
    newText++;
  }
}

Thank you, yes, I will read it.
But, regarding P5 and P3, that is simply the center distance from one LED to the other on the Matrix Panel; therefore, I believe that code for a P3 works on a P5, as long as both have the same technical characteristics.
Thank you again.

Thank you; I will test it and share the result.

Does it?

Do they?

Others may simply be lucky...
... or they are lying in their fancy YouTube videos.

I think your code is rubbish... (sorry).
It would be better to find another source to start from.
I am not willing to correct this rubbish.
It will take a lot of time (I would rather start from zero).
Also, I have very limited experience with ESP wifi (I did succeed a few years ago though).

See how @david_2018 handles wifi problems?

  if ((WiFi.status() != WL_CONNECTED) && ((millis() - previousMillis) >= statusCheckInterval)) {
    Serial.println("WiFi connection lost, reconnecting...");
    WiFi.disconnect();
    WiFi.reconnect();
    previousMillis = millis();
  }
}

so not by resetting the ESP!

It's absolutely true! But are you sure that your panel has "the same technical characteristics" as the matrix from the example? :)

Actually, I don't think the matrix is ​​the issue either. Having worked with these panels for almost 10 years, I can confidently say that your problems aren't due to the panel. When the panel isn't working, you'll either see flickering, interference, or a complete lack of image.
I'd say it's impossible for the panel to lose some information. The problem is somewhere else in the code. Most likely, it's the WiFi, as you've already heard.

There are many other libraries for working with such panels on ESP32.

This is the most relevant I think:

also

also some already mentioned above

Yes, I'll take a look at those libraries, but I'll also try out the last code that @david_2018 posted. Thank you.

Greetings everyone
Hi @david_2018. I took this long to reply to your last sketch that you sent me in post #88 because I was waiting for an ESP32 to arrive, which I bought from Aliexpress. So, I made the same connections and here is the result (shown in the attached video). I don't know if in the code you omitted the bottom part of the screen, which is the Date (Day/Month/Year) and Day of the Week? Thank you again.

https://youtu.be/LtIC-DLZozE

I did omit those, this was meant as a test to see if the display would still flicker. The code removes the double buffering, and only updates the numbers that change, instead of erasing the entire display and rewriting everything. Fortunately the font you are using, even though it is proportionally spaced, has equal spacing for all the numbers.

Adding the day of the week and date into the display should be fairly simple, especially since those normally only change once a day at midnight.

Great! Could you please complete the code for me?

Come on, you are sipposed to do the work!
Look at the example.
Do the same trick with the date as it was done with time.

I'm trying, but it's not easy at all! Like I said, I'm having a lot of difficulties.

The difficulties with what?
Please show the code that presents your efforts.