I have a web server on my Arduino that should render a form to save some data to the EEPROM. The HTML data has about 1500 characters. At the moment, my code looks like:
[...]
serverClient.println("HTTP/1.1 200 OK");
serverClient.println("Content-Type: text/html");
serverClient.println("Connnection: close");
serverClient.println();
serverClient.println("<!DOCTYPE html>");
[...]
I read about storing the data in PROGMEM using the F keyword like:
[...]
serverClient.println(F("HTTP/1.1 200 OK"));
serverClient.println(F("Content-Type: text/html"));
serverClient.println(F("Connnection: close"));
serverClient.println();
serverClient.println(F("<!DOCTYPE html>"));
[...]
But this needs more flash memory.
Is there any benefit using the second way? Or are there better solutions?
(I can’t use a SD card to store the data.)
It’s a trade-off between flash memory usage and RAM usage, and there’s a lot more flash than RAM on those microcontrollers.
I usually don’t bother storing the strings in flash unless my Arduino sketch is running out of RAM. Unfortunately, it’s not easy to tell if a sketch needs more RAM than is available – there are no compile warnings, things just won’t work or you’ll get weird behaviour. In that case, I find some arrays that I can shorten temporarily, and compile the sketch again. If the thing behaves better, I know I’m running out of RAM somewhere, so then I go looking for things I can
PROGMEMor think about another way of writing the program using less RAM.