The font drawer is designed the write text on a MicroPython FrameBuffer.
As FrameBuffer ar the recommanded ancestor for TFT Display. As such this front drawer should work with any of the TFT Screen display for MicroPython (as such as they are build on the top of FrameBuffer).
The fdrawer.py
library and desired font (.bin files, EG: vera.m15.bin
) must be copied to the MicroPython board.
The following test_basic.py
example shows how to draw a character and a string.
from machine import I2C
from SSD1306 import SSD1306_I2C
from fdrawer import FontDrawer
i2c = I2C( 1, freq=2000000 )
lcd = SSD1306_I2C( width=128, height=64, i2c=i2c, addr=0x3c, external_vcc=True )
# Normal FrameBuffer operation
lcd.rect( 0, 0, 128, 64, 1 )
lcd.show()
# Use a font drawer to draw font to FrameBuffer
fd = FontDrawer( frame_buffer=lcd, font_name = 'vera_m15' )
fd.print_str( "Font Demo", 2, 2 )
fd.print_char( "#", 100, 2 )
fd.print_str( fd.font_name, 2, 18 )
# Send the FrameBuffer content to the LCD
lcd.show()
Which produce the following results:
Note:
- the "m" in front of "m15" means that the .bin file only contains a part of the character set.
- An uncoded character is replaced by a squared rectangle (like the space in this example)
Look at the upy-fonts
folder in the freetype-generator github repository.