Texte mit unterschiedlichen Fonts darstellen

Aus Micropython Referenz
Zur Navigation springen Zur Suche springen

Ich habe im Internet die folgenden Links zum obigen Thema gefunden:

[[1]] [[2]] [[3]] [[4]] [[5]] [[6]] [[7]] [[8]]

Grundsätzlich handelt es sich wohl um das Modulpaket micropython-oled.


Erster Versuch mit micropython-oled

[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?

Nee lag an mir:

>>> %Run -c $EDITOR_CONTENT
>>> oled.fill(0)
>>> oled.show()
>>> 

tut was es soll. Display komplett schwarz.

Hier ein weiterer Versuch:

>>> oled.fill(0)
>>> oled.show()
>>> write20.text('12.236 Volt', 0, 0)
>>> oled.show()
>>> write20.text('1025 mA', 0, 20)
>>> oled.show()
>>> write20.text(12.236 * 1025 / 10000, ' Watt' , 0, 40)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/oled/write.py", line 54, in text
TypeError: 'float' object isn't iterable
>>> watt = 12.236 * 1025 / 10000
>>> write20.text(watt, ' Watt' , 0, 40)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/oled/write.py", line 54, in text
TypeError: 'float' object isn't iterable
>>> write20.text(watt, + ' Watt' , 0, 40)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported type for __pos__: 'str'
>>> write20.text(str(watt) + ' Watt' , 0, 40)
>>> oled.show()
>>> oled.fill(0)
>>> oled.show()
>>> write20.text(str(12.236 * 1025 / 10000) + ' Watt' , 0, 40)
>>> oled.show()
>>> oled.fill(0)
>>> oled.show()
>>> write20.text('%.3f Watt'%(12.236 * 1025 / 10000), 0, 40)
>>> oled.show()
>>> 



Zurück