Texte mit unterschiedlichen Fonts darstellen
Offenbar gibt es vereschiedene Möglichkeiten verschiedene Fonts einzusetzen.
[[1]] [[2]] [[3]] [[4]] [[5]] [[6]] [[7]] [[8]]
Erster Versuch mit micropython-oled
example1.py
>>> from machine import Pin, I2C >>> from oled import Write, GFX, SSD1306_I2C >>> from oled.fonts import ubuntu_mono_15, ubuntu_mono_20 >>> scl = Pin(17) sda = Pin(16) >>> i2c = I2C(scl=scl, sda=sda) Pin(16, Pin.OUT, value=1) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'id' argument required >>> i2c = I2C(0, scl=scl, sda=sda) Pin(16, Pin.OUT, value=1) Pin(16, mode=OUT) >>> oled = SSD1306_I2C(128, 64, i2c) gfx = GFX(128, 64, oled.pixel)
Hier hängt sich die REPL auf.
Das selbe Programm jetzt aus dem Text-Editor heraus:
from machine import Pin, I2C from oled import Write, GFX, SSD1306_I2C from oled.fonts import ubuntu_mono_15, ubuntu_mono_20 scl = Pin(17) sda = Pin(16) i2c = I2C(0, scl=scl, sda=sda) Pin(16, Pin.OUT, value=1) oled = SSD1306_I2C(128, 64, i2c) gfx = GFX(128, 64, oled.pixel) write15 = Write(oled, ubuntu_mono_15) write20 = Write(oled, ubuntu_mono_20) write15.text("Espresso IDE", 0, 0) write15.text("micropython-oled", 0, 15) gfx.line(0, 32, 127, 32, 1) gfx.line(0, 33, 127, 33, 1) write20.text("1234567890", 0, 35) write15.text("Ubuntu Mono font", 0, 52) oled.show()
Auch jetzt hängt sich das Programm ohne Fehlermeldung auf!
Offenbar bleibt es schon in dieser Zeile hängen:
oled = SSD1306_I2C(128, 64, i2c)
Die Ausgabe:
Pin(16, mode=OUT)
erscheint noch. Dann geht nichts mehr.
Diese Zeile ist der Übeltäter:
Pin(16, Pin.OUT, value=1)
Nachdem sie auskommentiert wurde funktionierte das Beispielprogramm!
Hier die Liste der enthaltenen Fonts:
>>> dir(Write) ['__class__', '__init__', '__module__', '__name__', '__qualname__', '__bases__', '__dict__', 'text', 'char'] >>> dir(GFX) ['__class__', '__init__', '__module__', '__name__', '__qualname__', '__bases__', '__dict__', 'fill_rect', 'line', 'rect', '_slow_hline', '_slow_vline', 'circle', 'fill_circle', 'triangle', 'fill_triangle'] >>> dir(SSD1306_I2C) ['__class__', '__init__', '__module__', '__name__', '__qualname__', '__bases__', '__dict__', 'fill', 'invert', 'pixel', 'scroll', 'text', 'show', 'poweron', 'init_display', 'write_cmd', 'poweroff', 'contrast', 'write_framebuf'] >>> oled.fill(0) >>>
oled.fill(0) funktioniert nicht.
>>> gfx.fill_rect(0,0,127,63, 0) >>>
... auch nicht. Vielleicht liegt es an der REPL?