Tinyfont
tinygo.org/x/tinyfont is a lightweight font rendering library designed for microcontrollers. It works with any display that implements the drivers.Displayer interface — OLEDs, TFT screens, e-ink panels — and draws text one pixel at a time, making it ideal for resource-constrained environments where a full font engine would be too large.
Quick start
import (
"image/color"
"tinygo.org/x/tinyfont"
)
// disp is any drivers.Displayer (e.g. an SSD1306 OLED or ILI9341 TFT)
tinyfont.WriteLine(disp, &tinyfont.TomThumb, 2, 14, "Hello!", color.RGBA{R: 0xff, A: 0xff})
WriteLine signature:
func WriteLine(display drivers.Displayer, font Fonter, x, y int16, str string, c color.RGBA)
| Parameter | Description |
|---|---|
display | Target display — anything with SetPixel + Size |
font | A Fonter value — pointer to one of the font variables |
x, y | Top-left origin of the text baseline (pixels) |
str | The string to render (ASCII; full Unicode depends on font) |
c | Foreground color as color.RGBA |
Built-in fonts
The root package ships four bitmap fonts that range from tiny to small:
| Variable | Size | Best for |
|---|---|---|
tinyfont.Tiny3x3a2pt7b | 3×3 px | Status indicators, tiny labels |
tinyfont.Picopixel | ~5 px | Dense data on small OLEDs |
tinyfont.TomThumb | ~6 px | Compact, very readable at small sizes |
tinyfont.Org01 | ~6 px | Clean monospace look |
Sub-packages (freemono, freesans, freeserif, notosans, proggy, gophers) add larger proportional and monospace faces at the cost of binary size.
The drivers.Displayer interface
type Displayer interface {
// SetPixel draws a single pixel at (x, y) with color c.
SetPixel(x, y int16, c color.RGBA)
// Size returns the display dimensions in pixels.
Size() (x, y int16)
// Display flushes buffered data to the hardware (no-op for direct-write displays).
Display() error
}
Any struct that satisfies these three methods can be passed to tinyfont.WriteLine. The TinyGo drivers package provides ready-made implementations for most common displays.
Multi-line text
For displays with limited height, you can call WriteLine multiple times advancing y by the font’s line height:
lineH := int16(10)
y := lineH
for _, line := range strings.Split(text, "\n") {
tinyfont.WriteLine(disp, &tinyfont.TomThumb, 2, y, line, white)
y += lineH
}
Font tester
Try out the built-in fonts directly in the browser. The widget below runs the same rendering code you would use on a real microcontroller, compiled with TinyGo to WebAssembly.
⚠️ WASM binary not found. Run ./build-wasm.sh to build it.
Select a font, adjust colors, choose a display size, and type your text to preview exactly how it will look on the target hardware.