ESPHome & ILI9341 touchscreen

Just for every one here. This is how I got solved it with the help of @pepe59

ESPHome version 2023.8.2

  • mosi_pin is connected to SDI(MOSI) and T_DIN
  • miso_pin is only connected to T_DO only.
  • clk_pin is connected to SCK and T_CLK

Please make sure you connect the T_IRQ to the interrupt_pin. It is required for the touch to work.

Hi, the components are updated and your code is not accepted in ESPHome anymore. Did you update your code and would you be able to share the updated code ? Thanks!

See 2 posts above.
I put the working code including touch on github.
For calibration, proceed according to the documentation.

1 Like

Thank you for pointing to the github. Unfortunately i still do not get it to work. Maybe you know what i am doing wrong ?

ESPHome Console error:
[23:53:16][W][component:204]: Component ili9xxx.display took a long time for an operation (0.13 s). [23:53:16][W][component:205]: Components should block for at most 20-30ms.

font:

  - file: "gfonts://Roboto"

    id: my_font

    size: 20

color:

  - id: my_red

    red: 100%

spi:

 clk_pin: 18 #display SCK/touch T_CLK

 mosi_pin: 23 #display SDI(MOSI)/touch T_DIN

 miso_pin: 19 #touch T_DO

touchscreen:

  platform: xpt2046

  id: my_touchscreen

  cs_pin: 17 #touch T_CS

  interrupt_pin: 16 #touch T_IRQ

  update_interval: 50ms

  report_interval: 1s

  threshold: 400

  calibration_x_min: 283

  calibration_x_max: 3776

  calibration_y_min: 3870

  calibration_y_max: 392

  swap_x_y: False

display:

  - platform: ili9xxx

    model: TFT 2.4

    cs_pin: 13 #display CS

    dc_pin: 27 #display DC

    reset_pin: 33 #display RESET

    rotation: 90

    id: tft_ha_test

    lambda: |-

      it.fill(Color::BLACK);

      it.print(0, 0, id(my_font), id(my_red), TextAlign::TOP_LEFT, "Hello World!");

# Define a PWM output on the ESP32

output:

  - platform: ledc

    pin: 32 #display LED

    id: gpio_32_backlight_pwm

# Define a monochromatic, dimmable light for the backlight

light:

  - platform: monochromatic

    output: gpio_32_backlight_pwm

    name: "Display HA test podsvícení"

    id: back_light

    restore_mode: ALWAYS_ON


ignore the wires on this picture, but it folows these pins
image

What display do you have?
I use ILI9341 2.8" and 2.4"
Then in the yaml code

display:
  - platform: ili9xxx
    model: ili9341

The error you describe is known.
Just add it to yaml

logger:
  logs:
    component: ERROR

Thanks for helping out!
I use a 2.4 TFT 14P screen
https://nl.aliexpress.com/item/1005005916960027.html?spm=a2g0o.order_list.order_list_main.59.27d779d25mrl54&gatewayAdapt=glo2nld

I got it to work i think. It looks like the model isn’t TFT 2.4 but TFT 2.4R. At least the strange noise on the screen is gone

Try TFT 2.4R
You were faster :grinning:

1 Like

Appreciate your quick reply’s! Really helped me out a lot! Now the fun stuf can start of programming the screen. Goal is to show what music is playing on spotify/sonos, and later add in some controles to skip tracks and so on.

Have a great day!

1 Like

I’m working on something similar right now.
Touch control for squeezebox (LMS)

1 Like

Unfortunately my screen appears to not have touchscreen (it does have the headers) so maybe i order it but first want to see if it works with buttons and i will use the display. Will share the code if i get it to work

Thinking on printing one of the following cases. the first gives me room for physical buttons

2 Likes

So I have this weird issue.

This is my config

esphome:
  name: "lcd-with-touch-esp32"
  friendly_name: LCD-With-Touch-ESP32

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "0y8By35x9D8mqZSghntlGOja1GpZg6Fr8gFcNvjxXQg="

ota:
  password: "4e3b4930a3ff2672415c158b17331a0d"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip: 
    static_ip: 192.168.0.85
    gateway: 192.168.0.1
    subnet: 255.255.255.0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Lcd-Esp32 Fallback Hotspot"
    password: "vxLa8dfwFIL1"

captive_portal:

web_server:
  port: 80

spi:
 clk_pin: 18
 mosi_pin: 23
 miso_pin: 14

touchscreen:
  platform: xpt2046
  id: my_touchscreen
  cs_pin: 33
  interrupt_pin: 19
  update_interval: 20ms

  calibration_x_max: 3691
  calibration_x_min: 319
  calibration_y_max: 453
  calibration_y_min: 3873
  on_touch:
    - lambda: |-
          ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%d",
              id(my_touchscreen).x,
              id(my_touchscreen).y,
              id(my_touchscreen).x_raw,
              id(my_touchscreen).y_raw
              );

display:
  - platform: ili9xxx
    model: ILI9341
    cs_pin: 27
    dc_pin: 26
    reset_pin: 5
    rotation: 270
    lambda: |-
      auto red = Color(255, 0, 0);
      auto green = Color(0, 255, 0);
      auto blue = Color(0, 0, 255);
      auto white = Color(255, 255, 255);
      it.fill(green);
      if (id(my_touchscreen).touched)
        it.filled_circle(id(my_touchscreen).x, id(my_touchscreen).y, 10, red);

switch:
  - platform: gpio
    pin: 
      number: 4
    restore_mode: ALWAYS_ON

    name: "Living Room Dehumidifier"

Now if i start the esp32 with the display connected and try touching the screen. It does not work.

Then while the power is still connected and the ESP32 is on, If i disconnect the display and reconnect it, the touch starts to work( i can see in the logs the touch coordinates) , but the display doesn’t show any colors on the screen (Some blue color is displayed instead of Green).

Next, If i continues to install the same image over wireless option using OTA, the OTA finishes, it reboots the device and I can see both the display as well as the touch input.

If I follow these exact steps without turning off the ESP32, it works… As soon as I turn it off and turn it on again, the touch stops working.

Can someone let me know what am I doing wrong? Is it the pins I have chosen causing a problem?

What are you physically connected to
miso_pin: 14
?

miso_pin: 14 is connected to only T_DO

I further narrowed it down to one pin that is interrupt_pin. If i disconnect and connect it back while the ESP32 is powered on, it works fine.

What could be the issue then?

Look here at the bottom of the page.
I put a pin description yaml in there which works fine

Yes… I was exactly referring to the same config and I am still have this issue with the interrupt pin. If i disconnect and connect it back again then it works.

I really have no idea. Here it works fine on both 2.8" and 2.4" ILI9341.
Have you checked the strength of the wire connections and sufficient power supply?
I can’t think of anything else.

No problem. Thanks for all the help. @pepe59

It looks like the interrupt pin get stuck to some state on boot up and only after disconnecting and reconnecting it, it works fine.

I am using a 2.8 inch ILI9341 display. Should I try using 5v instead of 3.3v as input?

Yes, sure. I have VCC 5V on all ILI9341.
Maybe that’s the problem.

I think there is a J1 jumper on the back of the ILI that is used when connecting to the VCC 3V power supply. The connection bypasses the voltage regulator on the ILI.