[gelöst] ESP32 mit SSD1306 deutsche Umlaute

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Achim
Posts: 18
Joined: Sun Aug 15, 2021 5:43 pm

[gelöst] ESP32 mit SSD1306 deutsche Umlaute

Post by Achim » Sun Aug 15, 2021 6:02 pm

MicroPython v1.16
Ich bin absoluter Anfänger und suche nun schon seit Tagen im Netz nach einer Möglichkeit, auf dem SSD1306 Text mit deutschen Umlauten auszugeben.
Mein jetziger Stand (weitere Scripte habe ich auch getestet) bringt nicht das gewünschte Ergebnis. Normale print-Ausgaben funktionieren, aber der SSD1306 versteht keine Umlaute. Die beiden oberen Kommentarzeilen bringen bei Aktivierung/Austausch auch Fehler.
Der abgebildete Code bringt den Fehler:
-----------------------------------------------------------------------------------------------------------
Warning: I2C(-1, ...) is deprecated, use SoftI2C(...) instead
Orientation: horiz Reversal: False
-----------------------------------------------------------------------------------------------------------
Ansonsten erscheint auf dem Display:
Wie gewollt in großer Schrift:
H?ll?
dann darunter die einzelnen Umlaute in gleichen Grafikzeichen
und darunter in gewollt kleiner Schrift: sch*n gr*n * sind hier auch wieder Grafikzeichen
-----------------------------------------------------------------------------------------------------------

import machine
import ssd1306
import freesans20
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
from writer_minimal import Writer

i2c = I2C(scl=Pin(22), sda=Pin(21), freq=10000)
# i2c = machine.I2C(1,scl=machine.Pin(22), sda=machine.Pin(21), freq=10000)
oled = ssd1306.SSD1306_I2C(128,64,i2c,0x3c)
# oled = SSD1306_I2C(128,64,i2c)

font_writer = Writer(oled, freesans20)

oled.fill(0)

font_writer.set_textpos(5,20)
font_writer.printstring("Hällö")
# font_writer.set_textpos(30,10)
# font_writer.printstring("Ä Ö Ü ä ö ü ß")
oled.text("Ä Ö Ü ä ö ü ß",5,30,1)
oled.text("schön grün",5,55,1)

oled.show()
Last edited by Achim on Mon Aug 16, 2021 1:10 pm, edited 1 time in total.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32 mit SSD1306 deutsche Umlaute

Post by Roberthh » Sun Aug 15, 2021 6:39 pm

The default font used by the framebuffer module only supports characters with the ordinal numbers 32-127, which is the ASCII character set. The German Umlaute have ordinal numbers >=128. So you have to eiter use ae, oe, ue, ss, or use your own font. @pythoncoder has set up an system to use arbitrary fonts, albeit these are somewhat slower than the built-in font. See https://github.com/peterhinch/micropyth ... ebuf_utils
But for a beginner that might be too hard to use.

Achim
Posts: 18
Joined: Sun Aug 15, 2021 5:43 pm

Re: ESP32 mit SSD1306 deutsche Umlaute

Post by Achim » Sun Aug 15, 2021 6:48 pm

Bei Perter Hinch war ich schon (Kommentar # i2c = machine.I2C(1,scl=machine.Pin(22), sda=machine.Pin(21), freq=10000), aber da kam ich dann zu anderen "Fehlern".
Die Nutzung von ae, ue, und oe ist leider bei Namen und Eigennamen problematisch, denn es gibt bei Namen z.B. die korrekten Schreibweisen Mueller und Müller. Kein "Müller" will da wieder als "Mueller" erscheinen.
Trotzdem danke für die Hinweise.

Achim
Posts: 18
Joined: Sun Aug 15, 2021 5:43 pm

Re: ESP32 mit SSD1306 deutsche Umlaute

Post by Achim » Sun Aug 15, 2021 7:36 pm

ich hatte auch noch einen anderen Code getestet.
Quelle:
https://community.hobbyelektroniker.ch/ ... ostID=1336
Das schien zumindest eine relativ einfache Lösung zu sein, aber auch hier erhalte ich Fehler bei der Ausführung. Ich habe auch mit einer ältere Versionen von MicroPython getestet (esp8266-1m-20200902-v1.13.bin), leider auch ohne Erfolg.
Es ist für mich doch erstaunlich, dass es für dieses Problem kaum Lösungsansätze gibt.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32 mit SSD1306 deutsche Umlaute

Post by Roberthh » Sun Aug 15, 2021 7:58 pm

Ok. I just noticed that you already use Peter's font lib. But that has the same limitation of not offering characters with ordinal numbers > 126. So you have to create your own font using peter's tools with character > 126. That#s font-to-py.py, with using the -l option. The ordinal numbers for the Umlaute are:
Ä 196
Ö 214
Ü 220
ä 228
ö 246
ü 252
ß 223

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32 mit SSD1306 deutsche Umlaute

Post by Roberthh » Sun Aug 15, 2021 8:12 pm

I have packed a larger freesans20 file. Not sure if it works. But at least it has characters up to ordinal number 255.
freesans-20-255.zip
(5.65 KiB) Downloaded 176 times

Achim
Posts: 18
Joined: Sun Aug 15, 2021 5:43 pm

Re: ESP32 mit SSD1306 deutsche Umlaute

Post by Achim » Mon Aug 16, 2021 5:39 am

Danke für ihre Mühe.
Es kommt leider der Fehler:

Warning: I2C(-1, ...) is deprecated, use SoftI2C(...) instead
Traceback (most recent call last):
File "<stdin>", line 13, in <module>
File "writer_minimal.py", line 56, in __init__
ValueError: Font must be horizontally mapped.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32 mit SSD1306 deutsche Umlaute

Post by Roberthh » Mon Aug 16, 2021 6:14 am

Ok. So I recreated the file as horizontally mapped. I could not add the ttf file itself, because it is too large. But you can use any ttf font file.
freesans-20-255.zip
(5.6 KiB) Downloaded 180 times

Achim
Posts: 18
Joined: Sun Aug 15, 2021 5:43 pm

Re: ESP32 mit SSD1306 deutsche Umlaute

Post by Achim » Mon Aug 16, 2021 6:48 am

freesans20_255 ist OK. ! ! !
Vielen Dank ! ! !

Was muss ich tun, damit auch die kleine (normale) Schrift mit Umlauten kommt (Ausgabe über oled.text("ÄÖÜäöüß") ?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP32 mit SSD1306 deutsche Umlaute

Post by Roberthh » Mon Aug 16, 2021 9:07 am

old.text() uses the built-in font, which cannot be changed. using Peter's font-to-py.py, you can create fonts of any size. The call would be:
python3 font_to_py.py -x -l255 font_file.ttf font_size output_file.py

with fontfile, fontsize and output_file being the parameters. Creating the freesans-20-255.py file, the call was:

python3 font_to_py.py -x -l255 FreeSans.ttf 20 freesans-20-255.py

Post Reply