actually I am programming an LCD Display with my arduino Nano.
I am using many Strings and the problem is, that the more String arrays I use, the more allocated String arrays loose their content.
My dynamic storage is at 70% and the program memory at 30%.
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
If you need more advice please post your program. And please use the code button </> when doing so.
First I was thinking about using an char array with the length of 20 ( on account of the 4x20 character LCD-Display).
The problem is that my output on the display has a variable number of characters.
So I am getting an error if my input is not 20 characters long.
So actually I am using PROGMEM to store my variables that contain strings.
My program code has more than 400 rows.
So I think that it would be easier if you don´t have to understand my entire code
I wrote an code that shows the problem.
I want to create manually some variable of type person and want to add them to an array.
This is my idea to make it use less storage.
I found out, that I will not get an error, if I´m initializing "const person all_persons[2] PROGMEM;" in the setup() function.
the array all_persons is used by other functions therefore I want to declare it global (or return it alternatively via reference).
#include <avr/pgmspace.h>
struct person
{
String first_name;
int age;
};
const person all_persons[2] PROGMEM;
void setup() {
Serial.begin(9600);
person a PROGMEM;
a.first_name = "Tim";
a.age = 11;
person b PROGMEM;
b.first_name = "Tobi";
b.age = 24;
person all_persons[0] =a;
person all_persons[1]=b;
}
void loop()
{
Serial.println(
}
ok, perfekt.
i could save four percent by using this method.
Are there some more stepts I can do (like using PROGMEM) to safe some more dynamic memory?