Code Monkey home page Code Monkey logo

esp-idf-ili9340's Introduction

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/esp32c3}
idf.py menuconfig
idf.py flash

Note for ESP32S2
Pull Up of the RESET pin may be required. I inserted a 100 ohm resistor between Vcc and RESET.

Note for ESP32S3
Pull Up of the RESET pin may be required. I inserted a 100 ohm resistor between Vcc and RESET.

Note for ESP32C2
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.
    The TFT backlight is more stable when supplied from an external power source.
    TFT MISO is not use.

config-menu


Tested TFT

M5Stack
4.0" ST7796S 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

spi-tft


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


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


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

There is a TFT equipped with XPT2046.
XPT2046-3

A library of XPT2046 Touch Screen is included in this project.
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.

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 ESP32-S3 ESP32-C3
VCC -- 3.3V 3.3V 3.3V 3V3
GND -- GND GND GND GND
CS -- GPIO14 GPIO34 GPIO34 GPIO9
RES -- GPIO33 GPIO41 GPIO41 GPIO1 (*1)
D/C -- GPIO27 GPIO40 GPIO40 GPIO10 (*1)
MOSI -- GPIO23 GPIO35 GPIO35 GPIO19 (*2)
SCK -- GPIO18 GPIO36 GPIO36 GPIO18 (*2)
LED -- 3.3V 3.3V 3.3V 3.3V (*3)
MISO -- N/C N/C N/C N/C
T_CLK -- GPIO18 GPIO36 GPIO36 GPIO18 (*2)
T_CS -- GPIO22 GPIO38 GPIO42 GPIO5 (*4)
T_DIN -- GPIO23 GPIO35 GPIO35 GPIO19 (*2)
T_OUT -- GPIO19 GPIO37 GPIO37 GPIO3 (*2)
T_IRQ -- GPIO21 GPIO39 GPIO45 GPIO4 (*4)

(*1) You can change any pin.

(*2) SPI is shared by TFT and XPT2046.

(*3) It can be controlled using gpio. However, you need to switch 3.3V using a transistor.

(*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

Calibration

Keep touching the point.
XPT2046-1 XPT2046-2

Draw with touch

If there is no touch for 10 seconds, it will end.
XPT2046-3


Reference

You can use TFT Shield like this:
TFT-Shield

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

esp-idf-ili9340's People

Contributors

botbench avatar nopnop2002 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.