Go Down

Topic: Wemos D1 Mini Lite - MAX7219 32x8 LED matrix FC-16 (Read 350 times) previous topic - next topic



Currently i'm working on a project with a 32 x 8 MAX7219 led matrix and a Wemos D1 Mini Lite that fetches text from a server via the http protocol, which is then shown on the matrix. This seemed quite easy. However, I'm stuck :smiley-confuse:. When I execute the code, everything looks fine. But the problem is that after around an hour of operation (not really consistent though, max 3 hours), the text is not refreshed, making the current text display infinitely.
By checking the access logs on my server, it became clear that the Wemos doesn't make any http calls to my server anymore in that 'failing stage'. The WiFi that the Wemos operates on is quite stable.
The code can be found below.


Code: [Select]

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <FC16.h>

const char* ssid = "----------";
const char* password = "----------";

char payloadChar[255];
String payload = "";
int lasthttpCode = 0;
int payloadLength = 0;

const int csPin = D4; // CS pin used to connect FC16
const int displayCount = 4; // Number of displays
const int scrollDelay = 30; // Scrolling speed - pause in ms

int Short = 0;
int Counter = 0;

FC16 display = FC16(csPin, displayCount);

void setup() {
    WiFi.begin(ssid, password); // Connect to WiFi
    while (WiFi.status() != WL_CONNECTED) {
    display.begin(); // turn on display
    display.setIntensity(1); // set brightness
    display.clearDisplay(); // turn all LED off
    display.setText("Connected to ---------.");
    WiFi.softAPdisconnect (true); // Turn of AP

void loop() {
    if(display.update()){ //If the current message has been shown; fetch new line
    payload = "";
    String fetchedText = fetchNewText();
    payloadLength = fetchedText.length() + 1;
    fetchedText.toCharArray(payloadChar, payloadLength); //setText doesn't take in strings

String fetchNewText(){
    HTTPClient http; //Declare an object of class HTTPClient
    http.begin("http://xxx.xxx.xxx.xxx/WEMOSMATRIX.php"); //Specify request destination
    lasthttpCode = http.GET(); //Send the request
    payload = http.getString(); //Get the request response payload
    if(payload.length() < 15){
        Short = 1;
        payload = "";
        Short = 0;
    http.end(); //Close connection
    if(lasthttpCode > 0){
        return payload;
        return "Error fetching the data";


The clear reason for the failure after time, is the inappropriate use of "String" (capital "S") variables.  You simply cannot use them on microcontrollers of this calibre.  :smiley-roll-sweat:

If driving that many MAX219s from an ESP8266, it would be a good idea to buffer the three control signals with a 74HCT14, two cascaded inverters for each signal.  :smiley-grin:


Aug 13, 2020, 07:07 am Last Edit: Aug 14, 2020, 03:48 am by noiasca
Is it really necessary to fetch new data in each loop iteration? How about once every 5 seconds, just as an example?

Before you do the http request, check if you are still connected to the wifi.
If not, connect to the wifi again. Don't rely on WiFi.reconnect();. Try a new begin:

this is just an example I'm using:
Code: [Select]

  if (!WiFi.isConnected())
    Serial.println(F("D011 WIFI not connected, try to reconnect"));
    WiFi.begin(ssid, password);

how to react on postings:
- post helped: provide your final sketch, say thank you & give karma.
- post not understood: Ask as long as you understand the post
- post is off topic (or you think it is): Stay to your topic. Ask again.
- else: Ask again.


The clear reason for the failure after time, is the inappropriate use of "String" (capital "S") variables.  You simply cannot use them on microcontrollers of this calibre.  :smiley-roll-sweat:
I agree it's a probable cause, but it's going to be hard to avoid using them. The HTTPClient class uses them extensively for example. Its .getString() method, which is used in the OP's sketch, returns one. But that class will have been tested fairly thoroughly by the developers and the community by now, so the hope would be that any major memory leaks have been found & fixed. Better the OP focuses on their own code. Having said that, I didn't spot an obvious problem.

Go Up