This keeps me up at night for the last few days. I try to control these LED matrices with an ESP8266 microcontroller.
First, the minimum code I could come up with that shows my issue (also attached as a zip file - also including headers):
WiFiDisplay.ino
#include "RunningText.h"
RunningText rt;
const long interval = 100;
unsigned long previousMillis = 0;
void setup() {
Serial.begin(115200);
Serial.println(" \r\nINIT \r\n");
String text = "Hi, this is an exceptionally long text that I want to display on my LED panels";
char* textInput = (char*)malloc((text.length() + 1) * sizeof(char));
text.toCharArray(textInput, text.length() + 1);
rt.setText(textInput, strlen(textInput));
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
rt.updatePosition();
}
}
RunningText.cpp
#include "RunningText.h"
#include "MatrixConstants.h"
#include <Arduino.h>
#define MAX_IN_USE 8
int buf[MAX_IN_USE * 4] = { 0 };
/*
* Overrrides the current buffer content
*
* Parameter arr: 1d array containing the new buffer content
*/
void setWholeBuffer(int* arr) {
for (int x = 0; x < (MAX_IN_USE * 8); x++) {
Serial.print("|");
Serial.print(buf[x]);
Serial.print(":");
buf[x] = arr[x];
Serial.print(buf[x]);
}
}
/*
* Puts a symbol in the running buffer so it can be displayed later.
*
* Parameter x: how far to the right the symbol should be placed in pixels
* Parameter arr: array containing the symbol, see MatrixConstants.h file for examples
* Parameter len: width of the symbol in pixels
*/
void RunningText::symbolInRunningBuffer(int x, int* arr, int len) {
for (int i = 0; i < len; i++) {
runningBuffer[x + i] = *(arr + i);
}
}
/*
* Sets the text that should be displayed.
*
* Parameter text: the text that should be displayed
* Parameter len: the number of characters
*/
void RunningText::setText(char *text, int len) {
bufferWidth = (len * 6) + (MAX_IN_USE * 16);
runningBuffer = (int*)malloc(bufferWidth * sizeof(int));
int pos = 0;
symbolInRunningBuffer(pos, empty, MAX_IN_USE * 8);
pos += (MAX_IN_USE * 8);
for (int i = 0; i < len; i++) {
symbolInRunningBuffer(pos, letters[text[i] - 32], 5);
pos += 5;
runningBuffer[pos] = 0;
pos++;
}
symbolInRunningBuffer(pos, empty, MAX_IN_USE * 8);
position = 0;
}
/*
* Shifts the whole text one pixel to the left.
* Stops when the whole text has been displayed
*/
void RunningText::updatePosition() {
if (position < (bufferWidth - (MAX_IN_USE * 8))) {
Serial.println(position);
setWholeBuffer(runningBuffer + position);
position++;
}
}
MatrixConstants.cpp is also attached (only contains constants)
Example output from the serial console:
INIT
0
|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|18755581:0|18750000:0|1075843120:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:01
|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:1272
|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:127|127:83
|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0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0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:127|127:8|8:8|8:8|8:127|127:0|0:08
|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:127|127:8|8:8|8:8|8:127|127:0|0:0|0:689
|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|1073651700:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:0|0:127|127:8|8:8|8:8|8:127|127:0|0:0|0:68|68:125
ets Jan 8 2013,rst cause:4, boot mode:(3,6)
wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v4ceabea9
~ld
INIT
0
|0:0|0:0|...
and so on and so on....
My general problem is that I update an array a couple of times (10 times in this example; setWholeBuffer() in RunningText.cpp) but suddenly the program completely stops responding until the hardware watchdog resets and everything starts over again (rst cause:4, boot mode:(3,6)).
As you can see in the last output line of setWholeBuffer, the value of buf[x.] is 1073651700 at one point which leads me to believe that there is some kind of a memory problem. The number 1073651700 is always the same after a reset.
I am developing in Visual Studio 2017 using visualmicro. When I compile and upload the code with the arduino IDE, I get only one output line from setWholeBuffer().
Settings for the programmer:

I would be really happy if you could help me find the issue because I don't think I can fix it on my own anymore, I have spent too many nights on this ![]()
WiFiDisplay.zip (3.24 KB)