1

im trying to use progmem instead on static char to save some valueble space. Everything seems fine, but serial and lcd show some weird newline symbol instead of my text.

What im trying to do:

...
#include <avr/pgmspace.h>
const static char PROGMEM textSDFailed[]        = "Filesys failed";
const static char PROGMEM textSDAvailable[]     = "Filesys is avail.";
...
lcd.print(textSDFailed);
...

And what i get on lcd when print: https://i.stack.imgur.com/V81Pn.jpg

Can someone help me?

  • 1
    You need special functions to access progmem. Look up Nick Gammon’s page on it. I’d post you a link but I keep getting yelled at for posting links. – Delta_G Jul 21 '20 at 17:11
  • Does lcd.print work if you feed it a string directly? what is that `PROGMEM` thing? is that a preprocessor macro of some sort? usually at this point there should either be a variable name or a `*` – FalcoGer Jul 21 '20 at 17:12
  • Look at the F-Macro. `lcd.print(F("Filesys failed")); ` prints directly from Flash – datafiddler Jul 21 '20 at 17:44
  • @FalcoGer Yes, its progmem think. – Lukáš Švec Jul 21 '20 at 18:01
  • @datafiddler Cant compile with lcd.print(F(textSDFailed)) for uno. – Lukáš Švec Jul 21 '20 at 18:04
  • @FalcoGer, the title has avr/pgmspace.h. https://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html – Juraj Jul 21 '20 at 18:49

1 Answers1

3

You can use the print which takes a progmem string. The overloaded print for progmem string has __FlashStringHelper* as parameter. This is normally for the Arduino F() macro.

For repeated use of the cast I do:

#define FSH_P const __FlashStringHelper*

Then I use it this way:

  lcd.print((FSH_P) textSDFailed);

If you can, use the F macro directly:

  lcd.print(F("Filesys failed"));
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Juraj
  • 3,490
  • 4
  • 18
  • 25
  • Thanks man. Just wondering why cant use smt like lcd.print(F(textSDFailed)) – Lukáš Švec Jul 21 '20 at 18:13
  • 1
    @Lukᚊvec, it is not a cast. it is a macro from Arduino core, which makes the string be stored in PROGMEM and casts it to `__FlashStringHelper`. https://www.arduino.cc/reference/en/language/variables/utilities/progmem/#_the_f_macro – Juraj Jul 21 '20 at 18:34
  • they do not explane so mutch how to work with vars and print them tru progmem, but u make it more clear to me. FSH_P mean smt. or i just rename it whatever? :) – Lukáš Švec Jul 21 '20 at 19:07
  • @Lukᚊvec, I linked to F macro section, but the rest the article is about PROGMEM and I learned it there – Juraj Jul 22 '20 at 05:01