ILI9341/XPT2046 displays will not function correctly

As the title states, I can not seem to get the xpt2046 touchscreen integration to function properly. All the suggestions in the facebook group as well as the esphome discord have so far been unsuccessful.

Hardware:
ESP32 devkitv1 x2
ESP32S2 x1
3.2" ili9341/xpt 2046 touchscreen x3

So far, the display component on all 3 displays work (one suggestion was to try a new display, so I bought 2 more). However, the touch function keeps yielding odd results within the logs when I attempt to calibrate them as shown in the esphome docs.

I have tried 3 different ESP32s, all brand new. All 3 displays are also new. I have tried 4 different wiring configs on breadboard. Someone suggested breadboard can be problematic, so I soldered it all up on a prototype board and the issue is still there.

As of now, upon touching the screen after bootup, 1 of 2 things will happen.

When report_interval: is set to 1s, touching the screen lists [21:07:52][I][cal:071]: x=0, y=395, x_raw=0, y_raw=0, and continues to repeat indefinitely about 3 times per second until you power cycle the ESP. Touching the display when this is happening does nothing. No touch is reported other than the log entry above.

When report_interval: is set to never, the display does not respond at all, and no logs are generated. Although when report_interval: is set to never, the log reports it as being set to a random number, [19:28:30][C][xpt2046:154]: Report interval: 4294967295.

All 3 displays and 3 esp32s show the same behavior.

Current config:

captive_portal:
spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23
  miso_pin: GPIO19

display:
  - platform: ili9xxx
    id: my_display
    rotation: 0
    model: TFT 2.4
    dc_pin: GPIO02
    cs_pin: GPIO15
    reset_pin: GPIO04

touchscreen:
  platform: xpt2046
  id: my_touchscreen
  cs_pin: 21
  update_interval: never
  report_interval: never
  on_touch:
    - lambda: |-
          ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%0d",
              id(my_touchscreen).x,
              id(my_touchscreen).y,
              id(my_touchscreen).x_raw,
              id(my_touchscreen).y_raw
              );
  interrupt_pin: 27
  threshold: 400
  calibration_x_min: 0
  calibration_x_max: 4095
  calibration_y_min: 0
  calibration_y_max: 4095
  swap_x_y: false

font:
  - file: "gfonts://Roboto"
    id: roboto
    size: 20

  - file:
      type: gfonts
      family: Roboto
      weight: 400
    id: font1
    size: 35

color:
  - id: white
    red: 100%
    green: 100%
    blue: 100%

  - id: BLACK
    red: 0%
    green: 0%
    blue: 0%

  - id: lcdpurple
    hex: FF3399

Current wiring layout:
VCC: 5v
GND: GND
CS: GPIO 21
RESET: GPIO 4
DC: GPIO 2
MOSI: GPIO 23
SCK: GPIO 18
LED: 3.3v
MISO: GPIO 19
T_CLK: GPIO 18 (shared with SPI CLK)
T_CS: GPIO 21
T_DIN: GPIO 19 (shared with SPI MISO)
T_DO: GPIO 23 (shared with SPI MOSI)
T_IRQ: GPIO 27

Can anybody see why this is not working? I feel like the report_interval: behavior is quite odd, but I can’t get it to work by adjusting it. I know there are strapping pins with the current config; the current config is mirrored to this project that many have had success with: GitHub - DustinWatts/ESP32_TFT_Combiner: A PCB making it easy to combine an ESP32 and a TFT Touchsceen.

Sorry for the long first post, but I am losing my mind trying to get this display working. I am open to try anything again, no matter if you think 5 other people suggested it previously. Thanks in advance

I had a similar issue with a 4" screen although using a st7796 driver.
I had to set up a second spi: bus and wire that to the touch screen as it appeared that it did not share the spi bus with the display after all.
Posting from my phone, I can post more details later if needed.

I have a device that I stupidly upgraded to ESPHome 2023.3, touch screen no longer works. So yes it’s either a bug or a new feature - certainly the documentation doesn’t help. I will wait and see what @Kev1 has to say too.

Ok … This Project Is still a work In progres.

Here Is the board, display and logs.



My Spi: bus setup yaml.

spi:
- id: bus_a
  clk_pin: 14
  mosi_pin: 27
  miso_pin: 18
- id: bus_b
  clk_pin: 22
  mosi_pin: 23  
  #miso_pin: 19

Display yaml.

display:
  - platform: ili9xxx
    model: st7796
    spi_id: bus_a
    cs_pin: 13
    dc_pin: 21
    reset_pin: 33
    rotation: 90
    id: my_display

Xpt2046 Yaml.

touchscreen:
  platform: xpt2046
  spi_id: bus_b
  id: my_touchscreen
  cs_pin: 26  # This pin must be physically connected to ground.
  interrupt_pin: 25
  update_interval: 50ms
  report_interval: 1s
  threshold: 400
  calibration_x_min: 3840
  calibration_x_max: 225
  calibration_y_min: 3801
  calibration_y_max: 274
  swap_x_y: false

Please note the chip select Pin!!

This works but still some tidying to do.

Thanks @Kev1 - I think yours works because you have two SPI buses which is not an option if you use Dustin Watts TFT board. There is an open Github issue - xpt2046 / ili9431 - No more touchscreen input on two devices · Issue #4319 · esphome/issues · GitHub

Interesting… I will definitely try this here in a bit. From what I was seeing on GitHub, it looks like the touchscreen component was updated recently so perhaps that’s why it’s no longer working as outlined in the documents. They really need to update their documentation on that if that’s the case.

This isn’t actually a big deal. I just ordered 5 of Dustin’s PCBs, I’ll just have to cut a few traces on the boards and run jumpers to the pins. Not a huge deal seeing as it’s only a few wires.

Although I wonder if this breaking update requiring two SPI buses was intentional. If so, hopefully someone informs Dustin so he can update his PCB layout.

@Kev1

Would you mind clarifying if you are using the MISO pin on your SPI bus_b? I see it’s commented out, I suspect because the display doesn’t need a data input in order to output touch data?

I made the changes you suggested, and I am still having the same issue. Upon touching the display, the log output shows:

[09:17:47][C][api:141]:   Using noise encryption: YES
[09:17:53][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:17:54][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:17:55][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:17:56][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:17:57][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:17:58][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:17:59][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:00][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:01][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:02][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:03][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:04][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:05][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:06][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:07][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:08][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:09][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0
[09:18:10][I][cal:066]: x=0, y=320, x_raw=0, y_raw=0

Which keeps repeating until power cycle as before… Could all 3 of my displays be trash?

Did you ground the xpt cs line?

Yes. This is my new config:

spi:
- id: bus_a
  clk_pin: GPIO18
  mosi_pin: GPIO23
  miso_pin: GPIO19

- id: bus_b
  clk_pin: 13
  mosi_pin: 16  
  miso_pin: 19
  
display:
  - platform: ili9xxx
    spi_id: bus_a
    id: my_display
    rotation: 0
    model: TFT 2.4 
    dc_pin: GPIO02
    cs_pin: GPIO15
    reset_pin: GPIO04

touchscreen:
  platform: xpt2046
  spi_id: bus_b
  id: my_touchscreen
  cs_pin: 21 #tie to GND
  update_interval: 50ms
  report_interval: 1s
  interrupt_pin: 27
  threshold: 400
  calibration_x_min: 0
  calibration_x_max: 4095
  calibration_y_min: 0
  calibration_y_max: 4095
  swap_x_y: false
  on_touch:
    - lambda: |-
          ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%0d",
              id(my_touchscreen).x,
              id(my_touchscreen).y,
              id(my_touchscreen).x_raw,
              id(my_touchscreen).y_raw
              );

I have tried messing with the report interval again, but it’s doing the same thing as before. I also tried with the xpt miso line commented out like you had in your config, made no change.

I know these displays have touch, based on the capacitive layer on the LCD and the XPT2046 chip on the back. That and the fact that the logs are silent until the second I touch it. That’s when the logs start printing that same line again and again every 1s. The reviews for this display are also well praised for use with Arduino. I have no idea why this isn’t working. Very frustrating lol

To make matters more confusing, I fixed the config pin schema to please my OCD (pin: 21 to pin: GPIO21), and now the logs show all 0’s instead of y=320. I am beyond confused, surely this is a config error?

[11:14:34][I][cal:074]: x=0, y=0, x_raw=0, y_raw=0
[11:14:35][I][cal:074]: x=0, y=0, x_raw=0, y_raw=0
[11:14:36][I][cal:074]: x=0, y=0, x_raw=0, y_raw=0
[11:14:37][I][cal:074]: x=0, y=0, x_raw=0, y_raw=0

Forgive the sloppy wiring job, this was not meant to last beyond proof of concept. The yellow line is the T_CS pin, tied to ground and the pin on the ESP32. Is this what you meant? I tested continuity between the other wires, and found no shorts just to be sure.

I do see that you have both miso’s as pin 19, could that have led to a wiring error?

The picture doesn’t show it well, but those blobs at the top right of the PCB were where the mosi, miso, and clk pins originally tied together. Instead of redoing all of it, I just snipped the t_din, t_do, and clk wires from the xpt, and re-ran them to their own pins for spi bus_b. None of the display spi and touch spi pins are connected now.

Wait, I see what you meant now. You weren’t referencing the wiring. That is an error for sure, I will check that now to make sure it isn’t wired wrong and correct that and test again. Good catch, I looked over my config 3 times and missed that.

It was just a config error, should have been pin 17, not 19. Corrected it and uploaded after verifying the wiring was correct, and no change. Still spams the logs after the first touch.

Dunno what to suggest next mate, apart from maybe starting from scratch and go direct from the display to esp using dupont jumpers?

I will do that, I don’t know what else to try. I will use another new esp32, and another lcd.

update:
New ESP32, different display, same issue.

[14:18:54][I][cal:080]: x=0, y=0, x_raw=0, y_raw=0
[14:18:55][I][cal:080]: x=0, y=0, x_raw=0, y_raw=0
[14:18:56][I][cal:080]: x=0, y=0, x_raw=0, y_raw=0

Also, apparently there is a post limit for new accounts, so I will be unable to reply to posts for 17 more hours. But I can edit existing posts for now. Lol

Update:
Touchscreen is inoperable on Arduino also, ordering new displays to test again. I will post back here pending the outcome of the new displays.

Not sure that Dustin cares too much about ESPhome. If you look at the issue on GitHub the guy who did the PR for the display changes wasn’t aware he had caused an issue, thus probably not deliberate.

@zoogara
Dustin posted his board design yesterday; anybody is free to take it and run with it.