• Stars
    star
    128
  • Rank 281,044 (Top 6 %)
  • Language
    C
  • License
    MIT License
  • Created over 5 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

esp-idf-ili9340

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

Software requirements

esp-idf v4.4 or later.
This is because this version supports ESP32-C3.

Installation

git clone https://github.com/nopnop2002/esp-idf-ili9340
cd esp-idf-ili9340/
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3}
idf.py menuconfig
idf.py flash

Note for ESP32S2
Since the ROM is small, it is not possible to display PNG and JPEG.

Note for ESP32C2
Since the ROM is small, it is not possible to display PNG and JPEG.

Note for ESP32C3
For some reason, there are development boards that cannot use GPIO06, GPIO08, GPIO09, GPIO19 for SPI clock pins.
According to the ESP32C3 specifications, these pins can also be used as SPI clocks.
I used a raw ESP-C3-13 to verify that these pins could be used as SPI clocks.

Configuration

You have to set this config value with menuconfig.

  • CONFIG_WIDTH
  • CONFIG_HEIGHT
  • CONFIG_OFFSETX
  • CONFIG_OFFSETY
  • CONFIG_MOSI_GPIO
  • CONFIG_SCLK_GPIO
  • CONFIG_CS_GPIO
  • CONFIG_DC_GPIO
  • CONFIG_RESET_GPIO
  • CONFIG_BL_GPIO
    GPIO of ESP32 cannot supply too much current.
    TFT backlight becomes brighter when powered by an external power source.

TFT MISO is not use.

config-menu


Tested TFT

  • M5Stack
  • Shenzhen Jingcal Intelligent 3.5" ST7796 480x320 (ESP32-3248S035)
  • Shenzhen Jingcal Intelligent 2.8" ILI9341 320x240 (ESP32-2432S028R)
  • 4.0" ST7796 480x320
  • 3.2" ILI9341 320x240
  • 2.8" ILI9341 320x240
  • 2.4" ILI9341 320x240
  • 2.2" ILI9340 320x240
  • 2.0" ILI9225 176x220
  • 2.0" ILI9225G 176x220
  • 1.8" ST7735 128x160
  • 1.77" ST7735 128x160
  • 1.44" ST7735 128x128
  • 0.96" ST7735 80x160

Generic Product

spi-tft

A note about RESET
Pull Up of the RESET pin may be required. I inserted a 100 ohm resistor between Vcc and RESET.

Shenzhen Jingcal Intelligent Product

They can use touch screens.
Shenzhen_Jingcal_Intelligent

ESP32-2432S032/ESP32-4827S043/ESP32-8048S043 doesn't work because it's an RGB panel, not SPI._


M5Stack

config-m5stack

M5Stick-1 M5Stack-2 M5Stick-3 M5Stick-4 M5Stick-5 M5Stick-6 M5Stick-7 M5Stick-8 M5Stick-9 M5Stick-10 M5Stick-11

BMP file
M5Stack-BMP

JPEG file(Cannot be displayed on ESP32S2)
M5Stack-JPEG

PNG file
M5Stack-PNG


4.0" ST7796S 480x320

config-st7796

Left:4.0" Right:2.4" 4_0_st779s


Shenzhen Jingcal Intelligent 3.5" ST7796 480x320

Vendor part number is ESP32-3248S035.

config-ESP32-3248S035 ESP32-3248S035-1 ESP32-3248S035-2


3.2" ILI9341 320x240

2.8" ILI9341 320x240

2.4" ILI9341 320x240

config-ili9341

Left:3.2" Right:2.4" 3_2_ili9341

Left:2.8" Right:2.4" screen_2-8_240x320


Shenzhen Jingcal Intelligent 2.8" ILI9341 320x240

Vendor part number is ESP32-2432S028R.

config-ESP32-2432S028R-1 ESP32-2432S028R-1 ESP32-2432S028R-2


2.2" ILI9340 320x240

config-ili9340

Left:2.2" Right:2.4" screen_2-2_240x320


2.0" ILI9225 176x220

config-ili9225

Left:2.0" Right:2.4" 2_0_ili9225


2.0" ILI9225G 176x220

config-ili9225g

Left:2.0" Right:2.4" 2_0_ili9225g


1.8" ST7735 128x160

config-st7735-128x160-1

Left:1.8" Right:2.4" 1_8_st7735


1.8" ST7735 128x160

config-st7735-128x160-2 screen_1-8_128x160-12 screen_1-8_128x160-13


1.8" ST7735 128x160

config-st7735-128x160-3 screen_1-8_128x160-21 screen_1-8_128x160-31


1.77" ST7735 128x160

config-st7735-128x160-4

Left:1.77" Right:1.8" screen_1-77_128x160


1.44" ST7735 128x160

config-st7735-128x160-5

Left:1.44" Right:2.0" screen_1-8_128x160-2


1.44" ST7735 128x128

config-st7735-128x128 screen_1-44_128x128-12 screen_1-44_128x128-13

GRAM Offset may be different


0.96" ST7735 80x160

config-st7735-80x160

Left:1.44" Right:0.96" screen_0-96_80x160-3


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.


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

You can add your original fonts.
The format of the font file is the FONTX format.
Your font file is put in font directory.
Your font file is uploaded to SPIFFS partition using meke flash.

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.
Developer page is here.

FontxEditor

This library 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.

How to build your own font file

step1)
download fontxedit.exe.

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-EDITTOR-1

step4)
adjust font size.
FONTX-EDITTOR-2

step5)
check font pattern.
FONTX-EDITTOR-13

step6)
save as .fnt file from your fontedit.exe.
FONTX-EDITTOR-14

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

step8)
add font to use

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

Font file that From 0x00 to 0x7f, the characters image of Standard ASCII are stored.
M5Statck-Font-1

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

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


XPT2046 Touch Screen

A library of XPT2046 Touch Screen is included in this project.
There is a TFT equipped with XPT2046.
XPT2046-3

XPT2046 shares the TFT and SPI bus.
Use the menu to enable XPT2046.
config-xpt2046-1

  • Touch position accuacy
    The coordinates read from XPT2046 are not stable.
    The difference between the coordinates read last time and the coordinates read this time is determined, and if it is within this range, it is regarded as a valid coordinate.
    Decreasing this value will make the position more accurate, but less responsive.
    Increasing this value will make the position more inaccurate but more responsive.

HR2046 Chip

There is a TFT equipped with HR2046.
XPT2046 and HR2046 are very similar. But HR2046 does not work properly.
XPT2046-2

Wirering for XPT2046

TFT ESP32 ESP32-S2/S3 ESP32-C2/C3
VCC -- 3.3V 3.3V 3V3
GND -- GND GND GND
CS -- GPIO14 GPIO34 GPIO2
RES -- GPIO33 GPIO41 GPIO4 (*1)
D/C -- GPIO27 GPIO40 GPIO3 (*1)
MOSI -- GPIO23 GPIO35 GPIO0 (*1) (*2)
SCK -- GPIO18 GPIO36 GPIO1 (*1) (*2)
LED -- 3.3V 3.3V 3.3V (*1) (*3)
MISO -- N/C N/C N/C
T_CLK -- GPIO18 GPIO36 GPIO1 (*1) (*2)
T_CS -- GPIO21 GPIO38 GPIO7 (*1) (*4)
T_DIN -- GPIO23 GPIO35 GPIO0 (*1) (*2)
T_OUT -- GPIO19 GPIO37 GPIO6 (*1) (*2)
T_IRQ -- GPIO22 GPIO39 GPIO8 (*1) (*4)

(*1) You can change it to any gpio using menuconfig. But some gpio's are input only.

(*2) These are shared by TFT and XPT2046.

(*3) It can be controlled using gpio. However, GPIO of ESP32 cannot supply too much current. TFT backlight becomes brighter when powered by an external power source.

(*4) I found that there are limits to the GPIOs that can be used as touch panel controls.

Check if XPT2046 works properly

You can check if XPT2046 works properly.
config-xpt2046-2

If you touch it at this time, the touched coordinates will be displayed.
If there is no touch for 10 seconds, it will end.
TouchPosition-1

Move the touch-pen vertically and horizontally to check the X and Y coordinates.
What you get here is the physical coordinates.
See here about physical coordinates.
TouchPosition-2

Using ESP32-3248S035

This module also has an XPT2046.
ESP32-3248S035-2 ESP32-3248S035-3

XPT2046 uses the same SPI bus as TFT.
XPT2046's SCLK and MOSI use the same GPIO as the TFT.
config-ESP32-3248S035-2

Using ESP32-2432S028R

This module also has an XPT2046.
ESP32-2432S028R-2 ESP32-2432S028R-3

XPT2046 uses a different SPI bus than TFT.
XPT2046's SCLK and MOSI use separate GPIOs from the TFT.
config-ESP32-2432S028R-2

Calibration

Keep touching the point.
XPT2046-1 XPT2046-2

Draw with touch

If there is no touch for 10 seconds, it will end.
TouchPen-1

Button with touch

You can only enter up to 15 characters.
If there is no touch for 10 seconds, it will end.
TouchKeyboard

Move with touch

If there is no touch for 10 seconds, it will end.
TouchMove-1 TouchMove-2

Menu with Touch

If there is no touch for 10 seconds, it will end.
TouchMenu-2 TouchMenu-1

Select with touch

If there is no touch for 10 seconds, it will end.
I borrowed the icon from here.
TouchIcon-1 TouchIcon-2

Save calibration data to NVS

Write calibration data to NVS.
Read calibration data from NVS when starting the firmware and use it.
If you use the same TFT, you don't need to calibrate again.
To clear the calibration data recorded in NVS, execute the following command.

idf.py erase_flash

config-xpt2046-4


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.


Reference

You can use TFT Shield like this:
TFT-Shield

https://github.com/nopnop2002/esp-idf-parallel-tft

More Repositories

1

esp-idf-st7789

ST7789 Driver for esp-idf
C
207
star
2

Arduino-STM32-CAN

Can Example for Arduino Core STM32
C++
203
star
3

esp-idf-ssd1306

SSD1306/SH1106 Driver for esp-idf
C
187
star
4

esp-idf-CANBus-Monitor

Monitor Canbus traffic
C
114
star
5

esp-idf-mqtt-broker

MQTT Broker for esp-idf
C
113
star
6

esp-idf-parallel-tft

8bit parallel TFT & 4-line resistance touch screen Driver for esp-idf using i2s paralell mode
C
100
star
7

esp-idf-json

Example of JSON Serialize and Deserialize in ESP-IDF
C
96
star
8

esp-idf-sx126x

SX1262/SX1268/LLCC68 Low Power Long Range Transceiver driver for esp-idf
C
83
star
9

esp-idf-sx127x

SX1276/77/78/79 Low Power Long Range Transceiver driver for esp-idf
C
73
star
10

STM32_TFT_8bit

STM32F103 8bit parallel TFT Library for Arduino_STM32
C++
53
star
11

esp-idf-mirf

nRF24L01 Driver for esp-idf
C
51
star
12

Raspberry-ili9325

Parallel TFT Shield Library for wiringPi
C
49
star
13

esp-idf-mpu6050-dmp

A demo showing the pose of the mpu6050 in 3D using esp-idf
C++
43
star
14

esp-idf-cc1101

CC1101 Low-Power Sub-1 GHz RF Transceiver driver for esp-idf
C
42
star
15

esp-idf-video-streaming

Capture video from a USB camera using ESP-IDF
C
42
star
16

esp8266_ethernet

Example of using SPI Ethernet module with esp8266
C++
42
star
17

esp-idf-net-logging

Redirect esp-idf logging to the network
C
41
star
18

Raspberry-ssd1306

ssd1306 Command Line Tool for Raspberry Pi
C
40
star
19

esp-idf-can2mqtt

CANbus to mqtt bridge using esp32
C
40
star
20

Raspberry-W25Q64

SPI Flash Memory W25Q64 Access Library for RaspberryPi
C
39
star
21

esp-idf-ftpClient

ftp client for esp-idf
C
37
star
22

esp-idf-w25q64

SPI Flash Memory W25Q64 Access Library for esp-idf
C
36
star
23

esp-idf-can2http

CANbus to http bridge using esp32
C
36
star
24

Arduino-ESPAT-TCP

TCP/UDP Applicaton for Arduino using ESP8266's AT firmware.
C++
35
star
25

wiringpi-tft-tool

TFT Command Line Tool for Raspberry Pi
C
35
star
26

esp-idf-ftpServer

ftp server for esp-idf using FAT file system
C
34
star
27

Raspberry-ili9340spi

ILI9340 SPI TFT Library & XPT2046 Touch Screen Library for Raspberry
C
33
star
28

Arduino-LoRa-Ra01S

An Arduino Library for LoRa Communication using SX1262/1268
C++
33
star
29

Arduino-STM32-Ethernet-LAN8720

Ethernet on STM32 using external PHY
C++
32
star
30

esp-idf-protocol-buffer

Example of Google Protocol Buffers Serialize and Deserialize with ESP-IDF
C
30
star
31

esp-idf-espnow-gateway

Gateway between esp-now and MQTT using esp-idf
C
27
star
32

esp-idf-m5stickC

M5StickC ST7735S Driver for esp-idf
C
27
star
33

esp-idf-ds3231

DS3231 RTC Driver for esp-idf
C
26
star
34

Arduino-CANBus-Monitor

mcp2515 canbus module to Monitor Canbus traffic
C++
26
star
35

esp-idf-can2usb

CANbus to USB bridge using esp32
C
26
star
36

esp-idf-uart2bt

UART to Bluetooth bridge for ESP-IDF
C
25
star
37

SC16IS752

Driver for SC16IS752
C
24
star
38

Robotell-USB-CAN-Python

Python program for USB-CAN Adapter
Python
24
star
39

esp-idf-web-form

WEB Form example for ESP-IDF
C
23
star
40

esp-idf-http-camera

Take a picture and Publish it via HTTP
C
23
star
41

esp-idf-rc-switch

315/433MHz ASK RF driver for esp-idf
C
21
star
42

esp-idf-smb-client

SMB client example for esp-idf
C
21
star
43

OrangePi-ZERO-FAN-HAT

Cooling FAN HAT for OrangePi ZERO
20
star
44

esp-idf-GPS-Repeater

Transfer GPS NMAE messages over Wifi
C
19
star
45

esp-idf-24c

Two-Wire Serial EEPROM Access Library for esp-idf
C
18
star
46

Raspberry-ili9225spi

ILI9225 SPI TFT Library for RaspberryPi/OrangePi
C
18
star
47

esp-idf-wifi-apsta

WIFI_MODE_APSTA example with esp-idf
C
18
star
48

esp-idf-GPS-View

GPS NMEA Viewer for M5Stack
C
17
star
49

Arduino-STM32-8bitTFT

8bit parallel TFT Library for Arduino_Core_STM32
C++
17
star
50

esp-idf-pwm-slider

PWM Slider Bar Control using ESP-IDF
C
16
star
51

esp-idf-mqtt-camera

Take a picture and Publish it via MQTT
C
16
star
52

esp-idf-ftp-camera

Take a picture and Publish it via FTP
C
15
star
53

esp-idf-web-chart

Real-time data visualization using esp-idf
C
15
star
54

esp-idf-benchmark

Dhrystone/Whetstone benchmark for esp-idf
C
15
star
55

esp-idf-ssh-client

ssh client for esp-idf
C
15
star
56

esp-idf-m5stickC-Plus

M5StickC-Plus ST7789V2 Driver for ESP-IDF
C++
15
star
57

esp-idf-web-serial

Serial Monitor for esp-idf
C
14
star
58

esp-idf-a2dp-source

ESP32 Bluetooth A2DP-SOURCE for esp-idf
C
14
star
59

Arduino-SI4432

Arduino library for SILICON LABS SI443x
C++
14
star
60

Arduino-STM32-nRF24L01

Arduino stm32 support files for nRF24L01 RF modules
C++
13
star
61

esp-idf-multipart-upload

A multipart file upload example for esp-idf
C
13
star
62

esp-idf-irSend

M5Stick and M5StickC(+) as a remote control transmitter
C
12
star
63

esp-idf-can2websocket

Brows CAN-Frame using esp-idf
C
12
star
64

esp-idf-ds1302

DS1302 RTC Driver for esp-idf
C
12
star
65

Raspberry-pcd8544

pcd8544 Command Line Tool for Raspberry Pi / Orange Pi
C
12
star
66

esp-idf-nrf905

nRF905 Single chip 433/868/915MHz Transceiver Driver for esp-idf
C
11
star
67

esp-idf-candump

CAN Dump for esp-idf
C
11
star
68

esp-idf-sh1107

sh1107 Driver for esp-idf
C
11
star
69

esp-idf-bmi160

A demo showing the pose of the bmi160 6DoF IMU sensor in 3D using esp-idf
C
11
star
70

esp-idf-vs1053

VS1053 Driver for esp-idf
C
10
star
71

Arduino-STM32-Ethernet

Arduino stm32 example for W5x00 ethernet modules
C++
10
star
72

esp-idf-ultrasonic

Ultrasonic distance sensor for ESP-IDF
C
10
star
73

esp-idf-lsm6ds3

A demo showing the pose of the lsm6ds3 6DoF IMU sensor in 3D using esp-idf
C
10
star
74

esp-idf-zlib

Example compression and decompression using zlib
C
10
star
75

esp-idf-pcf8563

PCF8563 RTC Driver for esp-idf
C
10
star
76

STM32_GD2

FT800/FT81X TFT Library for Arduino_STM32
C
9
star
77

esp-idf-Bluetooth-SPP

Classic Bluetooth SPP example for esp-idf
C
9
star
78

esp-idf-web-gpio

GPIO control using web browser
C
9
star
79

ESP8266-UART-to-UART-Bridge

C++
9
star
80

esp-idf-qr-code-generator

QR Code generator for esp-idf
C
9
star
81

esp-idf-rf69

RFM69 ISM Transceiver driver for esp-idf
C
9
star
82

esp8266-mpd-client

MPD client example for ESP8266/ESP32.
C++
9
star
83

esp-idf-cc2500

CC2500 Low-Cost Low-Power 2.4 GHz RF Transceiver driver for esp-idf
C
8
star
84

esp-idf-video-snapshot

Capture still images from a USB camera using ESP-IDF
C
8
star
85

esp-idf-sql-client

SQL database access example for esp-idf
C
8
star
86

pwmlib-opi

PWM C Library for H3/H2+ Sunxi SoC
C
8
star
87

esp-idf-DFPlayerMini

DFPlayer - A Mini MP3 Player For ESP-IDF
C
8
star
88

Raspberry-at24c

Two-Wire Serial EEPROM Access Library for RaspberryPi
C
8
star
89

esp-idf-mqtt-client

GUI MQTT Client for esp-idf
C
8
star
90

esp-idf-voice-control

Demonstration of voice control of esp32
C
7
star
91

esp-idf-mpr121

MPR121 Capacitive Touch Driver for esp-idf
C
7
star
92

esp-idf-smtp-camera

Take a picture and Publish it via SMTP.
C
7
star
93

esp-idf-93Cx6

Three-Wire Serial EEPROM Access Library for esp-idf
C
7
star
94

esp-idf-sc16is750

sc16is750/752 driver for esp-idf
C
7
star
95

esp-idf-world-weather

Display the weather forecast on M5STACK
C
7
star
96

esp-idf-ds1307

DS1307 RTC Driver for esp-idf
C
6
star
97

esp-idf-mcp3002

Driver for A/D converter with SPI serial interface
C
6
star
98

Raspberry-93Cx6

Three-Wire Serial EEPROM Access Library for RaspberryPi
C
6
star
99

Raspberry-HT1621B

HT1621B Segment LED Example Code for RaspberryPi
C
6
star
100

esp-idf-irAEHA

M5Stick and M5StickC as a remote control transmitter
C
6
star