Creating characters for display-o-tron hat. How?


#1

I have recently been trying out the dot hat and I was scrolling through the function reference and wanted to create a character however I did not really understand how to do it. From looking at the function reference I saw that each digit is 5 x 7 and I was hoping to do a design like this

but I am not sure how to execute it with 8, 8 bit integers or what the number 0-7 is for before it?

and finally to save me having to ask this later once you have done the lcd.create_char(char_pos, char_map) how do you write it to the display and chose where it goes.

I would be grateful if anyone could help me.


#2

pcarver said it best in his response on this GitHub issue, which I have left open for posterity: https://github.com/pimoroni/dot3k/issues/18

Let me know if you want me to elaborate, but his examples should really help!


#3

thanks for the link! I have now created my character in binary and run the lcd.create_char(char_pos, char_map) but how do you write the character to the display?


#4

Your character is actually saved to memory on the LCD display itself. Custom chars are in positions 0 to 7 in the display character memory. These char indexes are significant because they’re usually reserved for stuff in ASCII that’s borderline useless in this day and age, and virtually unprintable.

You can use Python’s chr() function, along with the desired index, to send these unprintable characters to Display-o-Tron, whereupon it will substitute them with the icon that you previously saved automagically:

lcd.write(chr(0))

And if you wanted to interpolate your icons into some text, perhaps:

lcd.write("Hello World {icon0}".format(icon0=chr(0)))

Incidentally, chr(0) is just a slightly less painful way of generating the correct escape sequence to represent this unprintable character in a string. You could use the raw sequence like so:

lcd.write("Hello World \x00")

And get the same result!