I can't print the text "Hello, Arduino!" sent as PSTR on the screen
I also have to associate it with a String (text_program_oled) to be able to print it on the screen with: u8g2.print(text_program_oled);
and it prints only the character "D"
Thanks for the reply.
I have done what you indicated and it prints ""DDoAoAA..."
The problem is how to pass the content of (const char* texto_programa) to the variable: String texto_programa_oled
That function is never called. What is it's purpose?
You're over complicating things. U8g2 and LiquidCrystal_I2C both inherit from the Print class. So, they both know how to print text using the F() macro.
As for the original problem...
In the line I've marked with /* *** (or actually as part of the function call - flash memory is NOT the same as "const" on an AVR), you're "losing" the PSTR-ness of the string you pass to it. When you do the u8g2.print()m the pointer is treated as a pointer to RAM instead of a pointer to Flash, and RAM at that location has random contents.
The string literal is put into flash memory with PSTR(). That creates a const char*, but the compiler cannot distinguish the pointer from a const char* into ram, so it is cast to const __FlashStringHelper*. __FlashStringHelper* is then used to facilitate overloading functions such as print() to handle references to flash memory.
Your code has basically taken a lengthy route to achieve the same objective, by placing the string literal in flash memory with PSTR(), then passing the const char* to a special function which subsequently casts the pointer to const __FlashStringHelper* so that the proper overload of print() will be used.