Creating a custom LCD character

I’m trying to recreate the custom character (smiley face) in the example shown in the Pololu AVR Library
Command Reference (page 19) in C and have it display on the 2x8 line display on my 3pi.

Here’s my code. The area of the compile error is noted below.

#include <pololu/3pi.h>
#include <avr/pgmspace.h>

const prog_char smile[] PROGMEM = {
	0b00000,
	0b01010,
	0b01010,
	0b01010,
	0b00000,
	0b10001,
	0b01110,
	0b00000
};

void add_new_chr()	//this loads the new character into the LCD module as character #3
{
	lcd_load_custom_character(smile,3);
	clear();
}

int main()
{
	add_new_chr();
	lcd_goto_xy(0,0);
	print(char(3));		// ERROR IS HERE:  unexpected expression before 'char'
	lcd_goto_xy(3,0);
	print("Happy");
}

Any ideas on how to make this work?

I tried to decipher the 3pi demo code, but it’s not obvious to me how the new back arrow character gets linked in the statement:
const char back_line2[] PROGMEM = “/6B”;

Hello,
There is a short example program at the bottom of that section. It is written in C++, but you can replace the functions with their C versions (lcd_load_custom_character, clear, and print_character) to make it work. We also have an example written in C in the Library User’s Guide.

As for the “\6B” (notice that you copied it wrong - did you retype that whole line instead of using copy & paste??), it gives you a string containing character number 6 (a custom back arrow) followed by the letter ‘B’. To be more clear, it should really be written “\x06” “B” - the space-separated string makes it clear that this should be character 0x06, not character 0x06B.

-Paul

Thanks. So, custom characters are assigned the ASCII values of 0:7. It would be useful if this was explicitly stated somewhere … which it probably is, but I haven’t seen it yet!

The \6B comes straight from the 3pi-demo-program code that is downloaded upon installation. Also, in this same demo program, the custom character created for the musical note character (7) is called using the same backslash format: const char fugue_title[] PROGMEM = " \7 Fugue in D Minor - by J.S. Bach \7 ";

The command reference says “The parameter ‘number’ is a character value between 0 and 7, which represents the character that will be customized. That is, lcd.print((char)number) or print_character(number) will display this drawing in the future.” You can also read over the documentation for the LCD module. It is sad that we only get 8 custom characters!

I was not asking where the “\6B” came from, just noticing that you somehow copied it as “/6B” instead :slight_smile: That way of writing the characters is not quite as good as the “\x06” notation, but I can’t find a definitive reference to the backslash codes supported by gcc, so I can’t really explain why.

Anyway, good luck, and if you come up with some good characters, please post them here!
-Paul