Adding custom fonts to TFT_eSPI

TFT_eSPI accepts custom fonts in the format of Adafruit GFX format. On the web, there are several fonts available in TrueType font format. Before we can use them with TFT_eSPI we need to convert the TTF format GFX format. There are several online tools available for this, I tried truetype2gfx by Rop Gonggrijp and tested it on Wio terminal, it worked wonderfully.

How to add custom fonts to your project

First find the TrueType font file. For example I wanted to add Space Mono available on google fonts to my project, So I downloaded the font package. If you extract the package, you can one TTF file for each customisation, like Bold, Italic etc.

custom fonts for wio terminal (TFT_eSPI)

Now go to this site and upload the TTF file you want to convert. The tool also allows you to adjust the font size and renders a sample text.

converting TTF to Adafruit GFX

Download the font file and put it in the arduino project folder. Then you can include it in your sketch like any other h file.

#include "SpaceMono_Regular50pt7b.h"
#define CF_SM50 &SpaceMono_Regular50pt7b
TFT_eSPI tft = TFT_eSPI();
//setFreeFont method will accept the custom font reference
tft.setFreeFont(CF_SM50);

Sample project is available here.

Add a Comment

Your email address will not be published. Required fields are marked *