Inkplate 10 custom text fonts in MicroPython TypeError

Customer:

I’m trying to use custom text fonts on the Inkplate 10 using MicroPython. Every time I attempt to use a font, I receive error messages. I’ve tried multiple ways and font file types.

I’ve tried code such as:

display.setFont('/sd/OPTIEngeEtienne.otf')
display.printText(100, 150, "Test")

Which results in:

Traceback (most recent call last):
 File "", line 1, in
 File "inkplate10.py", line 979, in printText
 File "gfx.py", line 499, in _very_slow_text
 File "gfx.py", line 443, in _place_char
TypeError: bytes indices must be integers, not str

I’ve tried otf, ttf, and bdf file types with the same result. I’m guessing I am missing something that is available normally when working with Python on Windows or Linux.

Originally submitted via the contact form on soldered.com on 6 February 2022. Migrated to the forum for community visibility.

Soldered Support:

This error is in the Adafruit GFX library that we use for graphics on Inkplate. You can read about adding custom fonts in the Adafruit GFX library at Using Fonts | Adafruit GFX Graphics Library | Adafruit Learning System

Customer:

Are you using the Adafruit GFX MicroPython library? The test code I am using is:

import machine, sdcard, os, time from inkplate10 import Inkplate
sd = sdcard.SDCard(machine.SPI(1), machine.Pin(15)) os.mount(sd, '/sd')
display = Inkplate(Inkplate.INKPLATE_2BIT) display.begin() display.clearDisplay()
display.setFont('/sd/OPTIEngeEtienne.otf')
display.printText(150, 150, "Test!")
display.display()

I’ve tried multiple font files. Do the font files need to be converted to another format?

Attachment omitted in migration: OPTIEngeEtienne.otf

Attachment omitted in migration: Aurebesh.ttf

Soldered Support:

We use CircuitPython instead of MicroPython. If you want to use custom fonts, you can use GitHub - peterhinch/micropython-font-to-py: A Python 3 utility to convert fonts to Python source capable of being frozen as bytecode · GitHub but you need to change some things inside the library. For using the setFont function you need another library: GitHub - adafruit/Adafruit_CircuitPython_Bitmap_Font: Helpers to load bitmap fonts into CircuitPython · GitHub. You may need to use another Adafruit library for graphics.

Customer:

I’m a bit confused. According to the GitHub page I downloaded the bin file from, it’s MicroPython. Either way, you’ve pointed me in the right direction. With this information I should be able to test what I had planned for my Inkplate 10.

Soldered Support:

Yes, that is confusing. The developer who works on the code says the correct name is CircuitPython instead of MicroPython. The difference isn’t big and everything should work regardless of the name.

Customer:

The library missing from Inkplate is displayio, which should be part of the “default” modules for CircuitPython. This is responsible for converting the font into bitmap data to render the text. I’ve been working on creating config files to build CircuitPython with the module included. Could someone confirm whether I’m on the right track?

This is what I have for the mpconfigboard.mk file:

USB_VID = 0x1A86
USB_PID = 0x7523
USB_PRODUCT = "Inkplate10"
USB_MANUFACTURER = "e-radionica"

IDF_TARGET = esp32

INTERNAL_FLASH_FILESYSTEM = 1
LONGINT_IMPL = MPZ

# The default queue depth of 16 overflows on release builds,
# so increase it to 32.
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32

CIRCUITPY_ESP_FLASH_MODE=dio
CIRCUITPY_ESP_FLASH_FREQ=40m
CIRCUITPY_ESP_FLASH_SIZE=4MB

CIRCUITPY_MODULE=wrover

And the sdkconfig:

CONFIG_ESP32S2_SPIRAM_SUPPORT=y
# # SPI RAM config
# # CONFIG_SPIRAM_TYPE_AUTO is not set
CONFIG_SPIRAM_TYPE_ESPPSRAM16=y
# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set
# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set
CONFIG_SPIRAM_SIZE=2097152
# end of SPI RAM config

CONFIG_DEFAULT_PSRAM_CLK_IO=30
# # PSRAM clock and cs IO for ESP32S2
# CONFIG_DEFAULT_PSRAM_CS_IO=26
# end of PSRAM clock and cs IO for ESP32S2

# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set
# CONFIG_SPIRAM_RODATA is not set
# CONFIG_SPIRAM_SPEED_80M is not set
CONFIG_SPIRAM_SPEED_40M=y
# CONFIG_SPIRAM_SPEED_26M is not set
# CONFIG_SPIRAM_SPEED_20M is not set
CONFIG_SPIRAM=y
CONFIG_SPIRAM_BOOT_INIT=y
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
CONFIG_SPIRAM_USE_MEMMAP=y
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
# CONFIG_SPIRAM_USE_MALLOC is not set
CONFIG_SPIRAM_MEMTEST=y
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set
# # LWIP
# CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
# end of LWIP

I’m still working out what the board.c, mpconfigboard.h and pins.c files should be like.

Soldered Support:

That looks okay. The developer confirmed this looks good. However, for CIRCUITPY_ESP_FLASH_MODE, we think you need to use QIO instead of dio, as that’s what we use in Arduino IDE.