Closed Herwig9820 closed 1 month ago
You need to check, whether the required character is available in the selected font. In your example the selected font doesn't contain the desired character: https://github.com/olikraus/u8g2/wiki/fntgrpopengameart#chroma48medium8
I suggest to use this font instead: https://github.com/olikraus/u8g2/wiki/fntgrpcodeman38#pressstart2p
OK, in the code snippet above, I changed the font, as folllows:
//u8x8_i2c.setFont(u8x8_font_chroma48medium8_r);
u8x8_i2c.setFont(u8x8_font_pressstart2p_f);
Looking at the character map, I can verify that the characters printed are according to the character codes: example: when printing 'char(224)', it prints 'à', which is correct.
But when printing "à", it prints "Ä " (wrong character, followed by a space), which is not correct. Check: printing asc('à) returns 195. The character map of the font indeed indicates Ä for character code 195.
So, Arduino does not translate a character to the character code expected by the OLED. Example: it sends character code 195, and not 224, when printing 'à'.
Does that mean I'm again using a wrong font ? I would again appreciate your help.
Best regards Herwig
The short suggestion is: Read out the hex code from the table. For Ä this would be 0xc4. Hex codes can be embedded into strings, by using \x escape sequence: "\xc4pfel" would print the German word "Äpfel" (apples).
Long answer: If you enter "Ä" (or any other char) into your keyboard, then:
Now, this is what u8g2 and u8x8 will do: Both will assume ISO/IEC 8859 encoding. U8g2 (as a special feature) also supports UTF8 if enabled (https://github.com/olikraus/u8g2/wiki/u8g2reference#enableutf8print) or if you use the drawUTF8 function.
U8x8 has a similar function, but my suggestion is not to trust that u8x8 function.
Coming back to your problem: Your IDE will probably use UTF8 encoding, however U8x8 assumes ISO/IEC 8859 encoding... so no wonder the wrong chars will appear. So better use the \xYY number code from the u8x8 font table.
OK, thanks for the quick reply.
Hi, I'm using OLED displays with your U8g2lib. Great library, but I cannot print accented characters (é, à, ...).
I found an u8lib issue '452', for which you provided a solution, for graphic mode. I tried various ways to do something similar (u8g2lib, character mode), but I couldn't find an 'enableUTF8Print' method for the objects I created. I'm probably doing something wrong. Could you help me with that ?
Many thanks Herwig