after almost two hours of testing different ideas from different search results I hope you can get me a solution....
I want to have a function debug() with which I can print / log some information.
My plan is to pass just a string to that debug-function and either print it via Serial.println() or send it via Bluetooth to my phone or ....
But I don't want to store all the debug-messages in the SRAM because it is getting full quite fast. So I thought of storing the variables in the Flash and get the content from there afterwards.
class helper {
public:
static void debug(char txt[]) {
// 1. Storing txt as variable in flash
char info[] PROGMEM = {txt}; // here is the error
// 2. Get data of stored string and work with it (Serial, Bluetooth, ...)
Serial.println(txt);
}
};
void setup() {
helper::debug("just a senseless long string");
}
void loop() {
}
The error message is
initializer fails to determine size of 'info'
but even if I try to specify the size of info by char info[sizeof(txt)] PROGMEM = txt; it doesn't work (neither the enclosing of txt with to curly braces).
with answer, but maybe the answerer didn't understand your question.
there are two ways:
a macro
#define DEBUG(msg) Serial.println(F(msg))
the preprocessor will replace every
DEBUG("some debug message");
with
Serial.println(F("some debug message"));
before compilation, so every debug message will stay in flash and not be loaded to SRAM in runtime.
or the way described in the SO answer. a parameter of type FlashStringHelper and usage
helper::debug(F("some debug message"));
gfvalvo:
helper::debug(F("just a senseless long string"));
That's what I like to avoid: the F() macro within the function debug(). I though something like debug("just a senseless long string"); was possible, where the string is then processed within the function itself and not whily passing the parameter.