Git Product home page Git Product logo

Comments (4)

olikraus avatar olikraus commented on June 2, 2024

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

from u8g2.

Herwig9820 avatar Herwig9820 commented on June 2, 2024

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

from u8g2.

olikraus avatar olikraus commented on June 2, 2024

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:

  1. your text editor translates the key into an encoded which is used / configured in your text editor. This might be UTF-8 in case of Arduino IDE. The UTF8 encoding for Ä is "0xC3 0xA4", which as nothing todo with 0xC4
  2. Once your c-code contains the byte sequence "0xC3 0xA4" (remember you will always see Ä because your editor is configured for UTF-8), then the C-Compiler has to understand what exactly is "0xC3 0xA4". Usually it doesn't do much, but some remarks are here: https://gcc.gnu.org/onlinedocs/gcc-4.0.4/cpp/Character-sets.html
  3. Finally the software (in this case U8g2 / U8x8) has to decode the encoded character and fetch the correct glyph from the font. In this case, u8x8 and u8g2 have to assume, what input encoded you might have, because there is no way to tell u8g2 / u8x8 how your editor is configured.

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.

from u8g2.

Herwig9820 avatar Herwig9820 commented on June 2, 2024

OK, thanks for the quick reply.

from u8g2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.