This is a workaround I put together to get custom fonts working on the Piicodev OLED module.
It depends on the imagemagick
binaries, so unfortunately it won’t run on microcontrollers (as far as I understand things). You’ll need a TTF font - experiment with one that scales down well.
Install imagemagick
sudo apt install imagemagick
Here’s some code
from PiicoDev_SSD1306 import *
from os import system
display = create_PiicoDev_SSD1306()
def custom_text(text, font, text_size, x, y):
system('convert -background white -font ' + font + ' -fill black -pointsize ' + str(text_size) + ' -extent 128x64-' + str(x) + '-' + str(y) + ' label:"' + text + '" -depth 1 +repage custom_text.pbm')
display.load_pbm('custom_text.pbm', 1)
display.fill(0)
custom_text('Some text', 'myfont.ttf', 24, 1, 1)
display.show()
Couldn’t find a “Python” way to interface with imagemagick, but got around it simply by calling convert
through os.system
.