TFT_eSPI offers a rich text rendering system that covers everything from compact GLCD bitmaps to smooth anti-aliased fonts loaded from flash. Alongside font selection, the library provides a datum system — a set of named reference points — that lets you anchor text to any corner, edge, or centre of its bounding box without manually measuring string widths.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Marcussacapuces91/doc-TFT_eSPI/llms.txt
Use this file to discover all available pages before exploring further.
Built-in Bitmap Fonts
TFT_eSPI includes eight built-in bitmap fonts selectable by number. Select one withsetTextFont(n) or by passing the font number directly to drawing functions:
Fonts 4, 6, 7, and 8 are stored as Run Length Encoded (RLE) bitmaps to reduce the FLASH footprint compared to uncompressed fonts.
| Font Number | Description | Approximate Height | Encoding |
|---|---|---|---|
1 | GLCD font (Adafruit GFX compatible) | 8 px | Raw |
2 | Small proportional font | 16 px | Raw |
4 | Medium proportional font | 26 px | RLE |
6 | Large digit font (0–9 and : only) | 48 px | RLE |
7 | 7-segment style digit font | 48 px | RLE |
8 | Large digit font (0–9 and : only) | 75 px | RLE |
Hello World with Font 2
GFX Free Fonts
In addition to the numbered fonts, TFT_eSPI supports the full Adafruit GFX proportional font collection viasetFreeFont(). Free fonts are stored as const GFXfont structures in PROGMEM and offer smooth proportional rendering across a wide range of sizes.
Smooth (Anti-aliased) Fonts
When#define SMOOTH_FONT is enabled in User_Setup.h, TFT_eSPI can load VLW format smooth fonts from SPIFFS or LittleFS. These fonts use anti-aliasing for crisp rendering at any size.
Smooth fonts require
SMOOTH_FONT to be defined at compile time and a filesystem (SPIFFS or LittleFS) pre-loaded with the .vlw font files generated by the Processing sketch bundled with the library.Text Datum Constants
A datum defines the reference point on the text bounding box that is pinned to the(x, y) coordinate you pass to drawString(). By default TFT_eSPI uses TL_DATUM (top-left), meaning (x, y) locates the top-left corner of the first character.
Set the active datum with:
Full Datum Table
| Constant | Value | Reference Point |
|---|---|---|
TL_DATUM | 0 | Top left (default) |
TC_DATUM | 1 | Top centre |
TR_DATUM | 2 | Top right |
ML_DATUM | 3 | Middle left |
CL_DATUM | 3 | Centre left, same as ML_DATUM |
MC_DATUM | 4 | Middle centre |
CC_DATUM | 4 | Centre centre, same as MC_DATUM |
MR_DATUM | 5 | Middle right |
CR_DATUM | 5 | Centre right, same as MR_DATUM |
BL_DATUM | 6 | Bottom left |
BC_DATUM | 7 | Bottom centre |
BR_DATUM | 8 | Bottom right |
L_BASELINE | 9 | Left character baseline (line the ‘A’ character would sit on) |
C_BASELINE | 10 | Centre character baseline |
R_BASELINE | 11 | Right character baseline |
L_BASELINE, C_BASELINE, R_BASELINE) pin the coordinate to the line that capital letters like A sit on, making it straightforward to vertically align text with graphical elements at a known Y position.
Datum Usage Example
The following sketch demonstrates several datum constants in a single setup:Choose a font
Call
setTextFont(n) for built-in fonts, setFreeFont(&font) for GFX fonts, or load a smooth font from the filesystem.Set the datum
Call
setTextDatum(d) with one of the 12 datum constants to define which part of the text bounding box the coordinates anchor to.Set text color
Use
setTextColor(fg) or setTextColor(fg, bg) to define foreground and optional background fill colors.