This is wrong in many ways:
String input = Serial.readString();
serialInputBuffer = new char[input.length()];
input.toCharArray(serialInputBuffer, input.length());
What's fatal is that you later don't free the memory allocated with new
. Don't use String and new
. Both use heap memory and will fragment it with these small allocations until there is no space for the next allocation. I see you have dynamic allocation in other parts of the sketch and there it looks like you have a delete
, but they still cause the fragmentation problem.
Use a global buffer like char serialInputBuffer[64];
and use:
int l = Serial.readBytes(serialInputBuffer, sizeof(serialInputBuffer));
serialInputBuffer[l] = 0;
In the scale function, there is a dynamically allocated array. Replace it with a class variable, which acts as a buffer which can hold the maximum number of bytes you expect the use to scale their byte to.
DynamicAgain, dynamic allocations will cause fragmentation even after deletionif the memory is released properly.