RepositoryCJPJapan
nopnop2002

nopnop2002/esp-idf-st7789

ST7789 Driver for esp-idf

420stars
83forks
4issues
1views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: jpeg

#1 Repository of the month

1
TINIX TRENDING·Topic: st7789

#1 Repository of the month

1
TINIX TRENDING·Topic: ttgo

#1 Repository of the month

esp-idf-st7789

ST7789 Driver for esp-idf

The demo video by Dmitry Andreev.
https://www.youtube.com/watch?v=aOyaK0pUiPk&t

Software requirements

ESP-IDF V5.0 or later.
ESP-IDF V4.4 release branch reached EOL in July 2024.

Note for ESP32-C6
ESP-IDF V5.1 is required when using ESP32-C6.

Installation

git clone https://github.com/nopnop2002/esp-idf-st7789
cd esp-idf-st7789/
idf.py menuconfig
idf.py flash

Note for ESP32-S2/ESP32-C2
The tjpgd library is not included in the ESP32-S2/ESP32-C2 ROM.
However, you can use this IDF component registry.
JPEG files can be displayed.

Note for ESP32-C2
ESP32-C2 has less SRAM, so JPEG and PNG may not be displayed on higher resolution TFTs.

E (256560) decode_jpeg: Error allocating memory for line 251
E (260630) pngle_new: Error allocating memory for line 160

st7789-1 st7789-2 st7789-3 st7789-4 st7789-5 st7789-6 st7789-7 st7789-8 st7789-9 st7789-10

BMP file
st7789-11

JPEG file(ESP32/ESP32S2/ESP32C3)
st7789-JPEG

PNG file
st7789-PNG

QR-CODE
st7789-QRCODE

PNG icon
st7789-11

Configuration

config-top

Generic ST7789 1.3 Inch

There is 2 kinds of marking.
The pin marking is written as SCL/SDA, so it looks like i2c, but it is SPI.
SCL is SCLK, SDA is MOSI.
st7789-back

config-1_3inch

Note for display remains black
This module may require a large current to reset.
This may be improved by following the steps below.

  1. Pull up RES with 100 ohms.
  2. Write the firmware.
  3. Press the reset button several times.

PullUp-Register

Generic ST7789 1.14 Inch

st7789-135x240-2 st7789-135x240-1

Generic ST7789 1.54 Inch (Non IPS)

Left:1.54inch Right:1.3inch
config_1_54inch-1 config_1_54inch-2

Generic ST7789 1.9 Inch (Non IPS)

st7789-170x320-1 st7789-170x320-2 st7789-170x320-3 config

Generic ST7789 2.0 Inch (Non IPS)

Left:2.0inch Right:1.54inch
st7789-240x320-3 st778-240x320-1 st778-240x320-2 st7789-240x320-4

Generic ST7789 2.4 Inch (Non IPS)

Left:2.4inch Right:2.0inch
config_2_4inch-1 config_2_4inch-2

Generic ST7789 2.8 Inch (Non IPS)

Left:2.4inch Right:2.8inch
2_8inch-1 2_8inch-2

LILYGO TTGO 1.14 Inch ESP32

ttgo-1 ttgo-2

TENSTAR T-Display 1.14 Inch ESP32(LILYGO TTGO clone)

ttgo-1 Image

LILYGO TTGO T8 ESP32-S2

TTGO_T8_ESP32-S2-1 TTGO_T8_ESP32-S2-2

TENSTAR TS-ESP32-S3 Development Board With 1.14 Inch TFT Display

This board comes with the BMP280 Temperature and Pressure Sensor and QMI8658C Gyroscope, Acceleration Sensor.
Image Image

Custom PCB

Click here for more information.

esp32s2-pcb-1 esp32s2_pcb-2

SPI Clock speed

According to the ST7789 datasheet, the minimum SPI clock cycle time is 16ns.
Therefore, the maximum SPI clock frequency is 62.5MHz.
The SPI clock frequency used by this project is 20MHz.
Higher SPI clock frequencies can be specified using spi_clock_speed().
When using higher SPI clock frequencies, you need to be careful about the length of the wire cable.

    //int speed = 40000000; // 40MHz
    int speed = 60000000; // 60MHz
    spi_clock_speed(speed);
    spi_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_CS_GPIO, CONFIG_DC_GPIO, CONFIG_RESET_GPIO, CONFIG_BL_GPIO);
    lcdInit(&dev, CONFIG_WIDTH, CONFIG_HEIGHT, CONFIG_OFFSETX, CONFIG_OFFSETY);
  • Benchmarking using ESP32@240 & 1.3 inch TFT Without Frame Buffer.
    Clock up has little effect.
20MHz40MHz60MHz
FillTest115010901090
ColorBarTest505050
ArrowTest280250250
LineTest219021502150
CircleTest194019101910
RoundRectTest198019401940
DirectionTest450430430
HorizontalTest107010401040
VerticalTest107010401040
FillRectTest190150150
ColorTest260220220
CodeTest107010401040
BMPTest716071307130
JPEGTest255025302530
PNGTest285028302830
QRTest220170170
  • Benchmarking using ESP32@240 & 1.3 inch TFT With Frame Buffer.
    The effect of clocking up varies depending on the test case.
20MHz40MHz60MHz
FillTest115010901090
ColorBarTest705050
ArrowTest603030
LineTest503030
CircleTest603030
RoundRectTest503030
DirectionTest604040
HorizontalTest705050
VerticalTest705050
FillRectTest603030
ColorTest605030
CodeTest1008050
BMPTest222021902190
JPEGTest257025502550
PNGTest286028402840
QRTest190170170

SPI BUS selection

config-spi-bus

The ESP32 series has three SPI BUSs.
SPI1_HOST is used for communication with Flash memory.
You can use SPI2_HOST and SPI3_HOST freely.
When you use SDSPI(SD Card via SPI), SDSPI uses SPI2_HOST BUS.
When using this module at the same time as SDSPI or other SPI device using SPI2_HOST, it needs to be changed to SPI3_HOST.
When you don't use SDSPI, both SPI2_HOST and SPI3_HOST will work.
Previously it was called HSPI_HOST / VSPI_HOST, but now it is called SPI2_HOST / SPI3_HOST.

Using Frame Buffer

config-frame-buffer

When FrameBuffer is enabled, all output will be stored in the internal FrameBuffer and reflected to the device with lcdDrawFinish.
If you don't use FrameBuffer, lcdDrawFinish does nothing.
If your main purpose is to display text, it's well worth using FrameBuffer.
If your main purpose is to display images, there is no value in using FrameBuffer.
Enabling FrameBuffer does not make image display faster.
This is because image analysis takes time.
ESP32-C2 has too small memory to use this function.
Note that using FrameBuffer consumes memory.
Memory allocate errors may occur with TFTs with large resolutions.

ESP32-S2 has less SRAM, but some ESP32-S2 have PSRAM.
If your SoC has PSRAM, you can avoid running out of memory by enabling PSRAM.
config-psram

Benchmarking using ESP32@240 & 1.3 inch TFT

Disable Frame BufferEnable Frame Buffer
FillTest11501150
ColorBarTest5070
ArrowTest28060
LineTest219050
CircleTest194060
RoundRectTest198050
DirectionTest45060
HorizontalTest107070
VerticalTest107070
FillRectTest19060
ColorTest26060
CodeTest107070
BMPTest71602220
JPEGTest25502570
PNGTest28502860
QRTest220190

JPEG Decoder

The ESP-IDF component includes Tiny JPEG Decompressor.
The document of Tiny JPEG Decompressor is here.
This can reduce the image to 1/2 1/4 1/8.

The jd_prepare() function included in Tiny JPEG Decompressor requires a work area.
The work area is allocated dynamically.
By enabling PSRAM, a larger work area can be allocated.
PSRAM can be enabled using menuconfig.

  • Work area when PSRAM is disabled
W (1886879) decode_jpeg: v5 version. JPEG Decoder is external tjpgd
I (1886889) decode_jpeg: esp_get_free_heap_size=99752
I (1886889) decode_jpeg: MALLOC_CAP_EXEC=0
I (1886889) decode_jpeg: MALLOC_CAP_32BIT=90112
I (1886889) decode_jpeg: jd_work_size=90112
  • Work area when PSRAM is enabled
W (92219) decode_jpeg: v5 version. JPEG Decoder is external tjpgd
I (92229) decode_jpeg: esp_get_free_heap_size=2161660
I (92229) decode_jpeg: MALLOC_CAP_EXEC=0
I (92229) decode_jpeg: MALLOC_CAP_32BIT=2064384
I (92229) decode_jpeg: jd_work_size=2064384

PNG Decoder

The ESP-IDF component includes part of the miniz library, such as mz_crc32.
But it doesn't support all of the miniz.
The document of miniz library is here.

And I ported the pngle library from here.
This can reduce the image to any size.

Font File

This project uses the following as default fonts:

  • font/ILGH16XB.FNT // 8x16Dot Gothic
  • font/ILGH24XB.FNT // 12x24Dot Gothic
  • font/ILGH32XB.FNT // 16x32Dot Gothic
  • font/ILMH16XB.FNT // 8x16Dot Mincyo
  • font/ILMH24XB.FNT // 12x24Dot Mincyo
  • font/ILMH32XB.FNT // 16x32Dot Mincyo

From 0x00 to 0x7f, the characters image of Alphanumeric are stored.
From 0x80 to 0xff, the characters image of Japanese are stored.
Changing this file will change the font.

You can add your original fonts.
The format of the font file is the FONTX format.
Your font file is put in font directory.
When you build the firmware, the font files are uploaded to the SPIFFS partition.

Please refer this page about FONTX format.

Font File Editor(FONTX Editor)

There is a font file editor.
This can be done on Windows 10.
You can create your own font files.
Developer page is here.

fontx-editor-1

Convert from BDF font to FONTX font

step1)
download Font File Editor(FONTX Editor) from here.

step2)
download BDF font file from Internet.
I downloaded from here.
fontxedit.exe can ONLY import Monospaced bitmap fonts file.
Monospaced bitmap fonts can also be downloaded here.

step3)
import the BDF font file into your fontxedit.exe.
this tool can convert from BDF to FONTX.
fontx-editor-2

step4)
adjust font size.
fontx-editor-3

step5)
check font pattern.
when you have made any changes, press the apply button.
fontx-editor-4

step6)
save as .fnt file from your fontedit.exe.
fontx-editor-5

step7)
upload your font file to $HOME/esp-idf-st7789/fonts directory.

step8)
add font to use

FontxFile fx32L[2];
InitFontx(fx32L,"/spiffs/LATIN32B.FNT",""); // 16x32Dot LATIN

Font file that From 0x80 to 0xff, the characters image of Japanese are stored.
st7789-KANA

Font file that From 0x80 to 0xff, the characters image of Latin are stored.
st7789-LATIN

u8g2 library contains many BDF fonts.
This is a 24x24 font converted from emoticons21.bdf.
bdf-font-1

This is a 16x16 font converted from Scroll-o-Sprites.bdf.
bdf-font-2

Convert from TTF font to FONTX font

step1)
Download WFONTX64.exe from here. Developer page is here.

step2)
Select ttf font.
Please note that if you select a proportional font, some fonts may not convert correctly.
If you select a proportional font, some fonts will need to be modified using fontxedit.exe.
Monospaced fonts can be converted correctly.
You can find Monospaced fonts here.
WFONTX64-1

step3)
Enter Height, Width, FontX2 name.
Specify half of Height for Width.
Specify your favorite font name in the FontX2 name field using up to 8 characters.
WFONTX64-2

step4)
Specify the file name to save.
WFONTX64-3

step5)
Specify the font style as required.
WFONTX64-4

step6)
Press the RUN button to convert TTF fonts to FONTX format.
WFONTX64-5

step7)
upload your font file to $HOME/esp-idf-st7789/fonts directory.

step8)
add font to use

    FontxFile fx16G[2];
    FontxFile fx24G[2];
    FontxFile fx32G[2];
    //InitFontx(fx16G,"/spiffs/ILGH16XB.FNT",""); // 8x16Dot Gothic
    //InitFontx(fx24G,"/spiffs/ILGH24XB.FNT",""); // 12x24Dot Gothic
    //InitFontx(fx32G,"/spiffs/ILGH32XB.FNT",""); // 16x32Dot Gothic
    InitFontx(fx16G,"/spiffs/Gigi16.FNT",""); // 8x16Dot Gigi
    InitFontx(fx24G,"/spiffs/Gigi24.FNT",""); // 12x24Dot Gigi
    InitFontx(fx32G,"/spiffs/Gigi32.FNT",""); // 16x32Dot Gigi

TTF_FONT

How to add your color

Change this:

#define RED    rgb565(255,   0,   0) // 0xf800
#define GREEN  rgb565(  0, 255,   0) // 0x07e0
#define BLUE   rgb565(  0,   0, 255) // 0x001f
#define BLACK  rgb565(  0,   0,   0) // 0x0000
#define WHITE  rgb565(255, 255, 255) // 0xffff
#define GRAY   rgb565(128, 128, 128) // 0x8410
#define YELLOW rgb565(255, 255,   0) // 0xFFE0
#define CYAN   rgb565(  0, 156, 209) // 0x04FA
#define PURPLE rgb565(128,   0, 128) // 0x8010

How to use this component in your project

Create idf_component.yml in the same directory as main.c.

YourProject --+-- CMakeLists.txt
              +-- main --+-- main.c
                         +-- CMakeLists.txt
                         +-- idf_component.yml

Contents of idf_component.yml.

dependencies:
  nopnop2002/st7789:
    path: components/st7789/
    git: https://github.com/nopnop2002/esp-idf-st7789.git

When you build a projects esp-idf will automaticly fetch repository to managed_components dir and link with your code.

YourProject --+-- CMakeLists.txt
              +-- main --+-- main.c
              |          +-- CMakeLists.txt
              |          +-- idf_component.yml
              +-- managed_components ----- nopnop2002__st7789

External input module

You can use these if you need some input.

Similar Projects

Discover other similar projects and AI models.

RepositoryC
nopnop2002/esp-idf-ili9340

SPI TFT and XPT2046 touch screen controller driver for esp-idf

263
Nov 24, 2026
RepositoryC#
SixLabors/ImageSharp

A modern, cross-platform, 2D Graphics library for .NET

8.1k
Dec 1, 2026
RepositoryC#
JimBobSquarePants/ImageProcessor

:camera: A fluent wrapper around System.Drawing for the processing of image files.

2.5k
Sep 6, 2023
RepositoryGo
eliukblau/pixterm

Draw images in your ANSI terminal with true color

1.0k
Aug 1, 2026
RepositoryZig
zigimg/zigimg

Zig library for reading and writing different image formats

862
Nov 27, 2026
RepositoryJava
amosshi/binaryinternals

Free Tools to View Internals of Binary File, including .class, .dex, .elf, .zip, etc.

71
Nov 13, 2026
RepositoryC
HeyWillow/willow

Open source, local, and self-hosted Amazon Echo/Google Home competitive Voice Assistant alternative

3.1k
Nov 1, 2026
RepositoryC
RavenSystem/esp-homekit-devices

Advanced firmware to add native Apple HomeKit and custom configurations, compatible with any SoC based on ESP32, ESP32-S, ESP32-C and ESP8266 series. (Shelly, Sonoff, Electrodragon, Tuya...)

3.0k
Nov 8, 2026
RepositoryJavaScript
lovell/sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, AVIF and TIFF images. Uses the libvips library.

32.9k
Nov 30, 2026