Sending text to Serial LCD with reference to custom characters

I have installed some custom characters in my Serial LCD. When sending text AND custom characters to the display I have been using:

String test1 = "ABC";
String test2 = "DEF";
#define Arrow 130 //reference to custom character in LCD

mySerial.print(test1);
mySerial.write(Arrow);
mySerial.print(test2);

Arrow is the pointer to the custom character portion of the LCD. Note however that it is greater than the usual 32 - 127 value for ASCII text. The above works, but I was wondering if the reference to "Arrow" could be included in a single defined text string to simplify the print/write function. When including several custom characters in a display the above approach becomes cumbersome.

Fred Miller

#include <LiquidCrystal.h> 
LiquidCrystal lcd(12, 11, 6, 5, 4, 3);  your own settings here
byte cbupw[8] = {
  0b11111,
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b10001
};
void setup(){
  lcd.createChar(1, cbupw);
}
void loop (){
lcd.write(1);
}

maybe this helps ?

Does this work?

char test[] = "ABC\x82""DEF";
mySerial.print(test);

\x is used to embed a hex char code in a string. (in this case hex 82 which is 130 decimal), the double inverted commas terminates the escape sequence (otherwise the DEF may be considered part of the hex value)

Thanks, KenF.

The use of escape hex character sequence (\xhh) embedded in a string worked nicely. Hey that’s a technique not referenced in most Arduino programming manuals. I finally found it in a C programming reference. I see there is a similar escape sequence for Octal code \o, but none for ascii or decimal bytes.

Thanks again. I will now be able to develop all of my LCD screen text including use of the special characters.

Fred Miller

KenF:

char test[] = "ABC\x82""DEF";

Thank you so much. I knew about escaping with \x from my old C days, but I was having problems because I didn't separate it with the double quotes. This helped me print the degree symbol ° on a thermometer app I was writing for a 1602A LCD. In case anyone else is looking for this, \xdf is the proper code for that model.