-->
Page 1 of 1

Putting strings into flash with PSTR and PGM_P

PostPosted: Tue Feb 27, 2018 2:14 pm
by johnsondavies
I've read the excellent documentation "Guide to PROGMEM on ESP8266 and Arduino IDE" in the docs, but still can't get my application to work.

I want to store strings in flash, to free up RAM, and I need to read them a character at a time. Here's a demo program:

Code: Select allvoid pfstring (PGM_P s) {
  intptr_t p = (intptr_t)s;
  while (1) {
    char c = pgm_read_byte(p++);
    if (c == 0) return;
    Serial.print(c);
  }
}

void Test () {
  pfstring(PSTR("Printed from Test"));
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  Test();
}

This gives errors when I try and compile - help much appreciated.

Thanks, David