Esp32 with RGB-Matrix-P3-64x32 part of the screen flashing
Posted: Mon Mar 04, 2024 8:04 pm
Hello, I have a problem with my program, part of the screen blinks synchronously with the seconds.
Code and video presenting the problem:
https://streamable.com/y2imo0
Thank you for help
Code and video presenting the problem:
https://streamable.com/y2imo0
Code: Select all
#include <PxMatrix.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <TimeLib.h>
#define P_LAT 22
#define P_A 19
#define P_B 23
#define P_C 18
#define P_D 5
#define P_E 15
#define P_OE 2
const char* ssid = "NETIASPOT-2.4GHz-13B5C8";
const char* password = "PqJhsksjbLl";
const char* apiKey = "6b7eaec7fcbsosudneozbf";
const char* city = "Lodz";
const char* timezone = "Europe/Warsaw"; // Example: "Europe/Warsaw"
const char* serverName = "http://api.openweathermap.org/data/2.5/weather?q=";
const char* units = "&units=metric";
const char* apiKeyStr = "&appid=";
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
uint8_t display_draw_time=0;
PxMATRIX display(64,32,P_LAT, P_OE,P_A,P_B,P_C,P_D);
uint16_t myRED = display.color565(255, 0, 0);
uint16_t myGREEN = display.color565(0, 255, 0);
uint16_t myBLUE = display.color565(0, 0, 255);
uint16_t myWHITE = display.color565(255, 255, 255);
uint16_t myYELLOW = display.color565(255, 255, 0);
uint16_t myCYAN = display.color565(0, 255, 255);
uint16_t myMAGENTA = display.color565(255, 0, 255);
uint16_t myBLACK = display.color565(0, 0, 0);
void IRAM_ATTR display_updater(){
portENTER_CRITICAL_ISR(&timerMux);
display.display(display_draw_time);
portEXIT_CRITICAL_ISR(&timerMux);
}
void display_update_enable(bool is_enable)
{
if (is_enable)
{
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &display_updater, true);
timerAlarmWrite(timer, 2000, true);
timerAlarmEnable(timer);
}
else
{
timerDetachInterrupt(timer);
timerAlarmDisable(timer);
}
}
void setup()
{
Serial.begin(115200);
configTime(3600, 0, "pool.ntp.org");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi!");
display.begin(16);
display.setFastUpdate(true);
display_update_enable(true);
//display.setBrightness(80);
}
void loop()
{
display.clearDisplay();
time_t now = time(nullptr);
struct tm* timeinfo = localtime(&now);
char currentTime[6];
strftime(currentTime, sizeof(currentTime), "%H:%M", timeinfo);
display.setCursor(3, 1);
display.setTextSize(2);
display.setTextColor(myCYAN);
display.print(currentTime);
char currentWeekday[15];
strftime(currentWeekday, sizeof(currentWeekday), "%a", timeinfo);
if (strcmp(currentWeekday, "Mon") == 0)
strcpy(currentWeekday, "Pn");
else if (strcmp(currentWeekday, "Tue") == 0)
strcpy(currentWeekday, "Wt");
else if (strcmp(currentWeekday, "Wed") == 0)
strcpy(currentWeekday, "Śr");
else if (strcmp(currentWeekday, "Thu") == 0)
strcpy(currentWeekday, "Cz");
else if (strcmp(currentWeekday, "Fri") == 0)
strcpy(currentWeekday, "Pt");
else if (strcmp(currentWeekday, "Sat") == 0)
strcpy(currentWeekday, "So");
else if (strcmp(currentWeekday, "Sun") == 0)
strcpy(currentWeekday, "Nd");
display.setCursor(2, 16);
display.setTextColor(myRED);
display.setTextSize(1);
display.print(currentWeekday);
char currentDate[6];
strftime(currentDate, sizeof(currentDate), "%d/%m", timeinfo);
display.setCursor(17, 16);
display.setTextColor(myGREEN);
display.setTextSize(1);
display.print(currentDate);
char currentSecond[3];
strftime(currentSecond, sizeof(currentSecond), "%S", timeinfo);
display.setCursor(50, 16);
display.setTextColor(myCYAN);
display.setTextSize(1);
display.print(currentSecond);
getWeatherData();
delay(1000);
}
void getWeatherData() {
String url = String(serverName) + String(city) + String(units) + String(apiKeyStr) + String(apiKey);
HTTPClient http;
http.begin(url);
int httpCode = http.GET();
if (httpCode > 0) {
String payload = http.getString();
DynamicJsonDocument doc(1024);
deserializeJson(doc, payload);
float pressure = doc["main"]["pressure"];
display.setCursor(2,24);
display.setTextColor(myMAGENTA);
display.setTextSize(1);
display.printf("%.0f", pressure);
float temperature = doc["main"]["temp"];
display.setCursor(35,24);
display.setTextColor(myYELLOW);
display.setTextSize(1);
display.printf("%.1f", temperature);
display.drawRect(59, 24, 2, 2, myYELLOW);
}
http.end();
}