Serial Graphic Library

Using the SparkFun Serial Graphic Library (GitHub - sparkfun/GraphicLCD_Serial_Backpack at V_1.0.1) along with the SparkFun 128x64 Serial LCD, I can get the example file to run fine. However, all of the examples using strings are hardcoded. When I tried to print a string variable, it bombed.

This will work:

LCD.printStr("Hello");

This will not work:

String myString = "Hello";
LCD.printStr(myString);

The error I get is "No known conversion for argument 1 from 'String' to 'char*'
no matching function for call to 'LCD::printStr(String&)'"

Has anyone else experienced this problem or know how to fix it?

Sure. Don't use the String class. It will give you memory allocation headaches eventually, anyway. Use:

char myString[] = "Hello";
LCD.printStr(myString);
LCD.printStr (myString.c_str()) ;

Ought to work - at least its a method in the String class (I just looked in WString.h)

Thanks for the speedy replies. I appreciate the help.

I was able to get aarg's method to work. MarkT, I tried your suggestion, but got another error:
"invalid conversion from 'const char*' to 'char*' [-fpermissive]"

I'm good to go from here and want to say thanks again!

This is my corrected code:

String stringOne = "11/13/2015";
char myString[78];
stringOne.toCharArray(myString, 78); 
myLCD.printStr(myString);

Why waste resources on the String class just to extract the char array from it?

Why not:

char myString[78] = "11/13/2015";  // why such a large array for such a small string?
myLCD.printStr(myString);