I’ve found SmartMatrix when looking for a LED Library but the ReadMe there is very hard to follow. It’s a lot of theory, but without actual instructions.
I avoided the library because I had no idea how to do the wiring. And I still don’t !
Which one is the basic example ?
Will it work with a 64x32 with 1/8 scan Matrix ?
Is there any: " This is how you do it, step-by-step guide " ?
It also states very clearly that it still has problems with RAM Usage.
Yet, I believe that every Matrix Library running on ESP32 has problems with RAM Usage.
Still seeing some crashes related to memory usage early in sketch when other memory intensive objects (e.g. WiFi library) are included in the sketch? Need to reproduce and track down
- May see a rolling reset before the sketch can do much
- This is hopefully fixed now. Please post to the SmartMatrix Community or create a GitHub Issue if you see this error: “Guru Meditation Error: Core 1 panic’ed (Cache disabled but cached memory region accessed)”
And it seems like a lot MORE work to make it work than the PxMatrix, for example.
Reading around the github and the forum I’ve found A LOT of libraries and APIs and it’s very confusing. There are SmartMatrix, FastLED, NeoMatrix, LEDMatrix, SmartMatrix_GFX…
It’s very confusing. There isn’t ONE guide that explains where should you start and what to actually use for your project. Everything is thrown at you. For a newcomer like me it doesn’t make any sense.
Also, there are shields and no shields versions. I need direct wiring because I am working with a breadboard.
I would really like to know if I can use it within my project, which, as I said, contains a lot of SPIFFS interactions like reading from and writing to a file and serving web-pages; contains a lot of Strings; going from AP to STA using ESPAsyncWebServer, constantly checking in loop for a URL’s body, parsing it and displaying 2 digits and greater-than sign on a LED Matrix.
I don’t find PxMatrix stable, because I have to do some workarounds, since it isn’t compatible with ESPAsyncWebServer, HTTPClient or SPIFFS, I am not sure which one. I also have to close the display each time I access a SPIFFS file or a web-page and then open it, and this produces an ugly effect or flicker.
Here is a sample of my project, in STA mode, currently using PxMatrix:
#include <Arduino.h>
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <SPIFFS.h>
#include <HTTPClient.h>
#include <PxMatrix.h>
#define P_LAT 22
#define P_A 19
#define P_B 23
#define P_C 18
#define P_D 4
#define P_E 15
#define P_OE 25
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
#define matrix_width 64
#define matrix_height 32
PxMATRIX display(matrix_width,matrix_height,P_LAT, P_OE,P_A,P_B,P_C,P_D,P_E);
uint8_t display_draw_time= 40;
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(){
// Increment the counter and set the time of ISR
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 fileReadLines(File file, String x[]) {
int i = 0;
while(file.available()){
String line= file.readStringUntil('\n');
line.trim();
x[i] = line;
i++;
Serial.println(line);
}
}
unsigned int number = 0;
String IPAddr = "";
const char* ssid = "ssid";
const char* password = "password";
AsyncWebServer server(80);
void setup() {
Serial.begin(115200);
delay(500);
WiFi.begin(ssid, password);
delay(500);
int k = 0;
while (WiFi.status() != WL_CONNECTED && k<20) {
k++;
delay(1000);
Serial.println((String)"Attempt " + k + " - Connecting to WiFi..");
}
delay(100);
display.begin(8);
display.clearDisplay();
display.setTextWrap(true);
display.setRotation(0);
if(WiFi.status() == WL_CONNECTED) {
IPAddr = WiFi.localIP().toString();
Serial.println((String)"Connected to " + ssid + " with IP addres: " + IPAddr);
display.setTextColor(myCYAN);
display.setTextSize(1);
display.setCursor(1,1);
display.print(IPAddr);
display_update_enable(true);
delay(5000);
} else {
Serial.println("Couldn't connect to WiFi Network. Restarting in 5 seconds...");
display.setTextColor(myRED);
display.setTextSize(1);
display.setCursor(1,1);
display.print("Error 1 - Restarting in 5 sec!");
display_update_enable(true);
delay(5000);
ESP.restart();
}
display_update_enable(false);
if (!SPIFFS.begin(true)) {
Serial.println("An Error has occurred while mounting SPIFFS ! Formatting in progress");
return;
}
server.on("/url", HTTP_GET, [](AsyncWebServerRequest *request){
display_update_enable(false);
request->send(SPIFFS, "/url_page.html", "text/html");
});
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
display_update_enable(false);
request->redirect("/url");
});
server.on("/logs", HTTP_GET, [](AsyncWebServerRequest* request){
display_update_enable(false);
request->send(SPIFFS, "/events.html", "text/html");
});
server.on("/jquery-1.12.4.min.js", HTTP_GET, [](AsyncWebServerRequest* request){
display_update_enable(false);
request->send(SPIFFS, "/jquery-1.12.4.min.js", "text/javascript");
});
server.on("/style_url.css",HTTP_GET, [](AsyncWebServerRequest *request){
display_update_enable(false);
request->send(SPIFFS, "/style_url.css", "text/css");
});
server.on("/master.css", HTTP_GET, [](AsyncWebServerRequest *request) {
display_update_enable(false);
request->send(SPIFFS, "/master.css", "text/css");
});
server.on("/back-image.jpg", HTTP_GET, [](AsyncWebServerRequest *request) {
display_update_enable(false);
request->send(SPIFFS, "/back-image.jpg", "image/jpeg");
});
server.on("/logo.png", HTTP_GET, [](AsyncWebServerRequest *request) {
display_update_enable(false);
request->send(SPIFFS, "/logo.png", "image/png");
});
server.on("/url", HTTP_POST, [](AsyncWebServerRequest * request){
display_update_enable(false);
int params = request->params();
String URL;
for(int i=0;i<params;i++){
AsyncWebParameter* p = request->getParam(i);
if(p->isPost()){
Serial.println((String)"POST[" + p->name().c_str() + "]: " + p->value().c_str() + "\n");
URL = p->value();
} else {
Serial.println((String)"GET[" + p->name().c_str() + "]: " + p->value().c_str() + "\n");
}
} // for(int i=0;i<params;i++)
if(URL != NULL && URL.length() != 0) {
File urlWrite = SPIFFS.open("/urlFile.txt", "w");
if(!urlWrite) Serial.println((String)"ERROR_INSIDE_URL_POST ! Couldn't open file to write URL !");
urlWrite.println(URL);
urlWrite.close();
request->redirect("/url");
} else {
request->redirect("/url");
}
});
server.begin();
}
void show_on_display(unsigned int nr) {
display.clearDisplay();
display.setTextWrap(false);
display.setRotation(0);
display.setTextColor(myGREEN);
display.setCursor(44,5); //- cursor for 1 digit number
display.setTextSize(3);
if(nr == 0) {
display.setTextColor(myRED);
} else if(nr >9) {
display.setCursor(26,5); //- cursor for 2 digits number
}
display.print(nr);
}
void parse_URL(String string) {
string.toUpperCase();
int f = string.indexOf("FREE");
String Free = string.substring(f);
Free.remove(0, 4);
number = Free.toInt();
}
void loop() {
display_update_enable(false); // close before accessing SPIFFS file
if (WiFi.status() == WL_CONNECTED) { //Check the current connection status
File urlRead = SPIFFS.open("/urlFile.txt");
if(!urlRead) Serial.println((String)"ERROR_INSIDE_loop ! Couldn't open file to read !");
if(urlRead.size() > 10) {
HTTPClient http;
String URL;
Serial.println((String)"URL: ");
fileReadLines(urlRead, &URL);
http.begin(URL); //Specify the URL
urlRead.close();
display_update_enable(true); // open after we've finished accessing SPIFFS file
int httpCode = http.GET(); //Make the request
if (httpCode > 0) { //Check for the returning code
Serial.println((String)"[HTTP] GET... code: " + httpCode);
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
Serial.println(payload);
parse_URL(payload);
}
} else {
Serial.println((String)"[HTTP] GET... failed, error: " + http.errorToString(httpCode).c_str());
}
http.end(); //Free the resources
} else {
Serial.println("URL Link is invalid ! Please enter another URL");
}
}
show_on_display(number);
delay(3000);
}
Also, another question I had was what is the maximum numbers of display I can use with either library ?
Thank you !