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/V5.x.
ESP-IDF V5.0 is required when using ESP32C2.
ESP-IDF V5.1 is required when using ESP32C6.

Installation for ESP-IDF V4.4

git clone -b v4.4 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 ESP32-S2
The tjpgd library is not included in the ESP32-S2 ROM because the ROM of the ESP32-S2 is small.
Therefore, JPEG files cannot be displayed.

Note for ESP32-C3
For some reason, there are development boards that cannot use GPIO06, GPIO08, GPIO09, GPIO19 for SPI clock pins.
According to the ESP32-C3 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.

Installation for ESP-IDF V5.x

git clone https://github.com/nopnop2002/esp-idf-ili9340
cd esp-idf-ili9340/
idf.py set-target {esp32/esp32s2/esp32s3/esp32c2/esp32c3/esp32c6}
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

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

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

PNG icon M5Stack-ICON


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

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

fontx-editor-1

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

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.
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-ili9340/font 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 here.

#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

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 physical coordinates.
    Physical coordinates are converted to logical coordinates.
    Then draw using logical coordinates.
    In TouchPenTest, when you touch the screen, a circle is drawn at the touched position, but if you touch the same position as the previous time, it is not drawn.
    This value is the threshold that determines whether the touch location is the same as the previous touch location.
    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 Clock speed

According to the datasheet, the minimum SPI clock cycles for each driver are as follows:
Maximum SPI clock frequency is the reciprocal of this.

Driver minimum SPI clock cycle maximum SPI clock frequency
ILI9225 100ns 10MHz
ILI9340 66ns 15MHz
ILI9341 100ns 10MHz
ST7735 66ns 15MHz
ST7796 66ns 15MHz

The SPI clock frequency used by this project is 10MHz.
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 = 15000000; // 15MHz
    spi_clock_speed(speed);
    spi_master_init(&dev, CONFIG_MOSI_GPIO, CONFIG_SCLK_GPIO, CONFIG_TFT_CS_GPIO, CONFIG_DC_GPIO,
        CONFIG_RESET_GPIO, CONFIG_BL_GPIO, XPT_MISO_GPIO, XPT_CS_GPIO, XPT_IRQ_GPIO, XPT_SCLK_GPIO, XPT_MOSI_GPIO);
    lcdInit(&dev, model, CONFIG_WIDTH, CONFIG_HEIGHT, CONFIG_OFFSETX, CONFIG_OFFSETY);

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 SPI TFT Adapter

I purchased this adapter on AliExpress.
It comes with an ESP32 and costs $4.
14pin-adapter-1 14pin-adapter-2

However, this adapter's T_IRQ is not connected anywhere.
To use the touch panel, you need to add a jumper.
14pin-adapter-3

As a result, the GPIO will be:

TFT ESP32
VCC -- 3.3V
GND -- GND
CS -- GPIO15
RES -- GPIO04
D/C -- GPIO02
MOSI -- GPIO23
SCK -- GPIO18
LED -- 3.3V *1
MISO -- N/C
T_CLK -- GPIO18
T_CS -- GPIO05
T_DIN -- GPIO23
T_OUT -- GPIO19
T_IRQ -- GPIO21

(*1) BL_EN is directly connected to 3.3V, so it cannot control BackLight.

When not using the touch panel.
config-14pin-adapter-1

When using the touch panel.
config-14pin-adapter-2

14pin-adapter-4


Reference

A TFT shield like this can be used with ESP-IDF.
TFT-Shield

It can be attached directly to this ESP32.
tzt-d1-esp32s3

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

esp-idf-ili9340's People

Contributors

alimoal avatar botbench avatar nopnop2002 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

esp-idf-ili9340's Issues

Often crashing on lcdDrawFillRect

Example:
lcdDrawFillRect(&dev, 67, 120, 79, 132, 0);
Display is st7735s 80x160

ESP-IDF 4.2.1, your code(esp-idf-ili9340-master) is from 25-5-2021

Any idea what is the problem and how to fix it
Thanks

assertion "ret_trans == trans_desc" failed: file "D:/ESP2_8/esp-idf/components/driver/spi_master.c", line 835, function: spi_device_transmit
assertion "ret_trans == trans_desc" failed: file "
abort() was called at PC 0x4014fc07 on core 0
0x4014fc07: __assert_func at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdlib/assert.c:62 (discriminator 8)

Backtrace:0x40088ecb:0x3ffcc840 0x40089575:0x3ffcc860 0x40090456:0x3ffcc880 0x4014fc07:0x3ffcc8f0 0x4010b1d5:0x3ffcc920 0x400d9ccd:0x3ffcc950 0x400d9d05:0x3ffcc9a0 0x400da7b9:0x3ffcc9c0 0x400d90b5:0x3ffcc9f0 0x4008957d:0x3ffcca60
0x40088ecb: panic_abort at D:/ESP2_8/esp-idf/components/esp_system/panic.c:330

0x40089575: esp_system_abort at D:/ESP2_8/esp-idf/components/esp_system/system_api.c:106

0x40090456: abort at D:/ESP2_8/esp-idf/components/newlib/abort.c:46

0x4014fc07: __assert_func at /builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/xtensa-esp32-elf/src/newlib/newlib/libc/stdlib/assert.c:62 (discriminator 8)

0x4010b1d5: spi_device_transmit at D:/ESP2_8/esp-idf/components/driver/spi_master.c:835 (discriminator 1)

0x400d9ccd: spi_master_write_byte at D:\W21\ESP\VS2\scanapp15N\build/../components/ili9340/driver/ili9340.c:106

0x400d9d05: spi_master_write_comm_byte at D:\W21\ESP\VS2\scanapp15N\build/../components/ili9340/driver/ili9340.c:122

0x400da7b9: lcdDrawFillRect at D:\W21\ESP\VS2\scanapp15N\build/../components/ili9340/driver/ili9340.c:624

0x400d90b5: http_get_task at D:\W21\ESP\VS2\scanapp15N\build/../main/http_sntp1.c:215

0x4008957d: vPortTaskWrapper at D:/ESP2_8/esp-idf/components/freertos/xtensa/port.c:143

Guide how to use as esp-idf component

Hello!

Can you provide instructions on how to use this properly as a component in another idf project? I was able to run your demo, but wasn't able to integrate your code into another project. Even if I copy all the stuff into the main folder of my app, I ran into linker errors because it can't find the lcd* functions.

Any help would be appreciated!

Thanks in advance!

License

Hi,

I'm looking into using your library but I noticed that most files don't have any licensing information, would you mind adding a top level COPYING or LICENSE file with the license of your choice. Two files are already MIT licensed so that would make sense but it's really up to you.

Thanks!

Use this library with platformio

Hi guys,

First of all: Thanks for this great library!

I am pretty new to the esp idf and just arrived from Arduino world. Could someone help to get it working as a library inside my platformio esp32-idf project?

I know I have to adjust the src/CMakeLists.txt in order to make the lib work.

Thanks in advance!

I already added the build flags to the platform.ini:

 
build_flags = 
    -std=c++17
    -D CONFIG_ILI9341
    -D CONFIG_MOSI_GPIO=1
    -D CONFIG_SCLK_GPIO=1
    -D CONFIG_CS_GPIO=1
    -D CONFIG_DC_GPIO=1
    -D CONFIG_RESET_GPIO=1
    -D CONFIG_BL_GPIO=1
    -D CONFIG_WIDTH=240
    -D CONFIG_HEIGHT=320
    -D CONFIG_OFFSETX=0
    -D CONFIG_OFFSETY=0

A question.

I wanna know that what is the difference between the "DC GPIO" and "BACKLIGHT GPIO"?

How to add new images/icons?

Hello,
I'd like to ask for a tip how to add any new image or icon. I added a .png file into a folder "images" but when I chose this file using the ShowPngImage function nothing shows. I suppose that there is neccesary any additional operation. Could you give me an advice?
Best Regards.
majorBien

About coordinate systems

There are two coordinate systems, physical and logical coordinates.
Logical coordinates are the positions of pixels on the TFT screen.
For a 240x320 TFT, the logical X coordinates range from 0 to 239, and the logical Y coordinates range from 0 to 319.
Logical coordinates can be changed according to the memory access control settings.

Physical coordinates are coordinates provided by hardware.
You can get the physical coordinates from XPT2046.

By performing calibration, you will get the conversion factor that will be converted from physical coordinates to logical coordinates.

Converts from physical coordinates to logical coordinates using the conversion factor.

  • When you touch the location of A:
    physical coordinates from XPT2046 are x=134 y=114.
    Physical coordinates are different values ​​for each TFT.
    For a 240x320 TFT, logical coordinates after conversion using the conversion factor are X = 239 and Y = 0.
    For a 320x480 TFT, logical coordinates after conversion using the conversion factor are X = 319 and Y = 0.
    The logical coordinates depend on the maximum resolution of the TFT.

  • When you touch the location of B:
    physical coordinates from XPT2046 are x=1809 y=1772.
    For a 240x320 TFT, logical coordinates after conversion are X=0,Y=319.
    For a 320x480 TFT, logical coordinates after conversion are X=0,Y=479.

  • For a 240x320 TFT, the conversion coefficient is as follows.
    X=fx(134)=239
    Y=fy(114)=0
    X=fx(1809)=0
    Y=fy(1772)=319

  • For a 320x480 TFT, the conversion coefficient is as follows.
    X=fx(134)=319
    Y=fy(114)=0
    X=fx(1809)=0
    Y=fy(1772)=479

+----------------------+
|                    B |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
| A                    |
+----------------------+

When you move the touch pen from A to a, only the X coordinate is updated.

+----------------------+
|                    B |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
|                      |
| A----------------->a |
+----------------------+

When you move the touch pen from A to a, only the Y coordinate is updated.

+----------------------+
| a                  B |
| ^                    |
| |                    |
| |                    |
| |                    |
| |                    |
| |                    |
| |                    |
| |                    |
| |                    |
| |                    |
| |                    |
| |                    |
| |                    |
| |                    |
| |                    |
| A                    |
+----------------------+

How to display jpeg or rgb565 from memory buffer ?

I want to display images from camera frame buffer captured by esp32-cam. Following is the code snippet.

TickType_t realtime_image_test(TFT_t * dev, camera_fb_t * fb, int width, int height) {

	TickType_t startTick, endTick, diffTick;
	startTick = xTaskGetTickCount();

	// lcdFillScreen(dev, BLACK);  // not filling can make it look better

	int _width = width;
	if (width > 240) _width = 240;
	int _height = height;
	if (height > 320) _height = 320;

	int image_width = fb->width;
	int image_height = fb->height;

	uint16_t jpegWidth = width;
	uint16_t offsetX = 0;
	if (width > image_width) {
		jpegWidth = image_width;
		offsetX = (width - image_width) / 2;
	}
	ESP_LOGD(__FUNCTION__, "jpegWidth=%d offsetX=%d", jpegWidth, offsetX);

	uint16_t jpegHeight = height;
	uint16_t offsetY = 0;
	if (height > image_height) {
		jpegHeight = image_height;
		offsetY = (height - image_height) / 2;
	}
	ESP_LOGD(__FUNCTION__, "jpegHeight=%d offsetY=%d", jpegHeight, offsetY);

	// when the buffer itself is in rgb888 format
	// uint8_t *pixels = fb->buf;  

	// when the buffer is in jpeg format
	uint8_t *pixels = malloc(fb->width * fb->height * 3);
	if (!fmt2rgb888(fb->buf, fb->len, fb->format, pixels)) {
		ESP_LOGE(TAG, "Conversion from jpeg to rgb888 failed");
	}

	uint16_t *colors = (uint16_t*)malloc(sizeof(uint16_t) * jpegWidth);
	uint8_t r,g,b;
	for(int y = 0; y < jpegHeight; y++){
		for(int x = 0;x < jpegWidth; x++){
			r = pixels[y*jpegWidth + x*3];
			g = pixels[y*jpegWidth + x*3 + 1];
			b = pixels[y*jpegWidth + x*3 + 2];
			colors[x] = rgb565(r,g,b); // convert rgb888 to rgb565
		}
		lcdDrawMultiPixels(dev, offsetX, y+offsetY, jpegWidth, colors);
		vTaskDelay(1);
	}
	free(colors);
	free(pixels); // no need to free when the original buffer of camera is used

	endTick = xTaskGetTickCount();
	diffTick = endTick - startTick;
	ESP_LOGI(__FUNCTION__, "elapsed time[ms]:%"PRIu32,diffTick*portTICK_PERIOD_MS);
	return diffTick;
}

What this code does is convert the image present as jpeg in buffer to rgb888 format and reformats it as rgb565 which is presume is the one used by tft display. The exact display is st7735.

The problem is that, the image displayed isn't correct. What am I doing wrong ?
image

Cant display ascii>127

Tried with couple fonts incl. provided with your exampe Gothic and the last ASCII char that could be displayed is 127 (some tall rectangle in your Gothic font) next characters with ascii > 127 are not displayed?

	strcpy((char *)ascii, "127: \x7f\x81\xa1\xa2\xa6\xa7");  // only symbol for 0x7f (127) displayed (rectangle)
	lcdDrawString(&dev, fx16G, xpos, ypos, ascii, color);

not able to show icons on the display.

Hello, i am using esp32-s2 and interface ili9341. If i run the whole main file, then there is not output on the display. But if i run some commands from the function like from fill rectangle it will show output. Now i want to display icon on the display. Can you tell which arguments i have to pass the function so that it will shoe icon image on display.

Turn DMA off

I need to use SPI without DMA for some purposes. But when I turn it off for SPI, LCD shows wrong data. what should I do?

xpt2046 issue

Hi
i have downloaded and compiled sucessfully.
TFT ili9341 works fine all graphics and pics.
The touch calibrates but when i am in Touchtest it does not do any thing out.
when i press the touch from right or left edges it draws a line across whole screnn.
Not working elsewhere except edges.
Plz help in this regard
20211223_195336_001

Slow loading speed

I was testing this on the st7735 lcd display 128x128 but the loading speed is too slow , i have used the esp32s3 module for this drawing fill circle is comming as line by line.

Blank Display

Hi, I'm trying to use the library but I can't make it work. I already did the configuration as you show in the pictures, the program compile and runs well but never shows anything on the display. I also test the display with and Arduino library and works perfect. Could you give some idea to make it work? Thanks.

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.