Hi,
Seems the Serial.print("any text"); can take up unnecessary Ram space at start up and can be overcome by using the F() macro.
However seems the same happens when printing to a tft screen eg tft.println ("Lights ON"); but the F() Macro has no effect.
Is there any similar workaround for tft printing ?
Know could use ProgMem so store the text strings, but the screen prints are mainly short bits of text .
As well as the Ram space being full, program memory space is also right on the limit, but as the program is mature just want to get it all into the 328 rather than migrate to a different board.
If the TFT library inherits from the Print class, F() should work fine.
If the TFT library doesn't inherit from the Print class, it should, and it looks like you've got yourself a project.
Which library are you using for the tft display?
When printing literal text without the F() macro, the compiler recognizes identical text used in multiple print statements and only stores a single copy of the text, using it for all print statements where it is needed. Unfortunately it does not do this when using the F() macro, which can lead to wasted use of flash memory when the same text is stored multiple times, so it helps to search through your sketch for identical string literals, store the text in PROGMEM as a constant string, then print that string using a cast to (__FlashStringHelper*) in the print statement.
If the tft cannot take text using F(), you can store the text in PROGMEM, then copy to a buffer in ram before printing.
const char text1[] PROGMEM = "This is a test";
const char text2[] PROGMEM = "This text will be copied to ram";
void setup(){
Serial.begin(9600);
Serial.println((__FlashStringHelper*)text1);
char buff[32]; //buffer must be large enough to hold largest string + 1 additional space for terminating null character
strcpy_P(buff, text2);
Serial.println(buff);
}
void loop(){
}