I am trying to print μ on to a 16x2 LCD.
I get strange Japanese characters instead of μ with the following code
case 2:
it.printf(0, 0, "ESP32 Halleffect: %.1f %μT", id(halleffect).state);
break;
I am trying to print μ on to a 16x2 LCD.
I get strange Japanese characters instead of μ with the following code
case 2:
it.printf(0, 0, "ESP32 Halleffect: %.1f %μT", id(halleffect).state);
break;
What component is that? If it is an HD44780 using this Character-Based LCD Display — ESPHome, which one of the models is it?
Seems to be HD44780UA00, IMHO.
Best option is trial and error
If it’s the Japanese version try \xb5.
Want to print Mu μ but it is printing some Japanese characters
The codes are in the datasheet, which is linked in the esphome docs. μ is present on both models, but in a different place.
And in the other version it is \xe4
Yes that is what I said. Pages 17 & 18.
Read the responses above. Also that is probably not your model.
it.printf(0, 0, "ESP32 Halleffect: %.1f \xe4T", id(halleffect).state);
That did it
and another solution
it.printf(0, 0, "ESP32 Halleffect: %.1f %cT", id(halleffect).state, 0xe4);
I am using an oled display and needed to display μg
on my Air Quality Sensor ESPHome builds. I tried all the versions above but all just display a white stripe instead. Any suggestions on what else I can try?
display:
- platform: ssd1306_i2c
id: device_display
model: "SH1106 128x64"
address: 0x3C
An OLED display doesn’t have a fixed character set, so you just need to include the glyph for μ.
Unfortunately the calibre.ttf font supplied with ESPHome doesn’t have that symbol, so you need to download (or create) a TTF file with it included. You could get one by googling “free calibre ttf”, but if you do then you may need to restrict the glyphs to just the ones you use to save memory as most font files on the web are bigger than the default one.
I figured it out and sharing here as my searches for this info led me here…
This applies to OLED Displays:
Google Fonts can be pulled in ESPHome so I checked at https://fonts.google.com/ if μ was in any of the fonts. The site showed me what fonts could display it including Roboto which is what I use. I then discovered that ESPHome only pulls in basic characters from these fonts and anything beyond the alphabet and punctuation needs to be included using glyphs (@zoogara Thanks for pointing me in that direction). I installed the font in Windows as the preview only shows the basic set and the Character Map application (default in Windows) showed me the Unicode number to reference when importing it into ESPHome.
I tried adding the Glyph section to one of the font sizes I already had but it caused that font to be displayed as a white block so I created a new one with the glyphs for both Mu
and g
. I did this because it appears that when you add the glyphs section, only those specific glyphs are imported so the basic alphabet is stripped out thus requiring me to add the basic g back in to avoid having to reference the 2 different font configurations to type µg
.
font:
# gfonts://family[@weight]
- file: "gfonts://Roboto"
id: roboto
size: 12
- file: "gfonts://Roboto"
id: roboto_symbols
size: 12
glyphs: [
"\U000000B5", #µ
"\U00000067" #g
]
Another thing that stumped me for a bit was that the character map what showing me U+00B5 as the Unicode for the Mu but ESPHome requires a longer version. What worked was to pad the code with 0 to make it 9 characters (\U0000 00B5 but no space in between).
In my lambda code I referenced the new font where I needed the µg (micro-gram). BTW, ALT+0181 types µ
- id: page2
lambda: |-
it.printf(4, 4, id(roboto_medium), "PM 1: ");
it.printf(96, 4, id(roboto_medium), TextAlign::TOP_RIGHT, "%4.0f", id(pm1_0).state);
it.printf(124, 4, id(roboto_symbols), TextAlign::TOP_RIGHT, "%sg", "\U000000B5");
Another syntax that worked is:
it.printf(4, 42, id(roboto_medium), "PM 10: ");
it.printf(96, 42, id(roboto_medium), TextAlign::TOP_RIGHT, "%4.0f", id(pm10_0).state);
it.printf(124, 42, id(roboto_symbols), TextAlign::TOP_RIGHT, "µg");