ILI9341/XPT2046 displays will not function correctly

New displays arrived. Different sizes, different vendors, both highly reviewed. Neither of the touchscreens work with the ESP32 OR my arduino sketch. This HAS to be user error, but I just can’t see where. All 5 screens have the 4 pin ribbon cable for the touch screen, and all 5 have XPT2046 ICs on the back. I have wired, un-wired, and re-wired these things probably 15 or 20 times now, I even used new breadboards and dupont cables. 3 times. All 5 displays work correctly every time on Arduino, and ESP32. Yet not a single one has outputted touch coordinates in arduino or on the ESPs. This is driving me nuts!

Update: switched out the current limiting resistors to voltage dividers on the arduino and now all 5 touch displays function perfectly while playing a pong game.

I also had to set both chip selector pins high before outputting otherwise the screen would often go full white and become unresponsive. This must be why two SPI busses are now needed in esphome if I had to guess. The current arduino sketch is also not using the interrupt pin, as I guess there is already an interrupt using another pin in the XPT2046 IC. Now to try and get these into esphome again. At least there’s light at the end of the tunnel now…


Glad you got it working mate.

If you haven’t already can you add some input to the GitHub issue please? xpt2046 / ili9431 - No more touchscreen input on two devices · Issue #4319 · esphome/issues · GitHub

I’m still working on getting them to work with an ESP32 on esphome, but at least now I know the screens all work when they are run by an arduino uno. Now just to see how hard it’ll be figuring out why esphome won’t work with it.

Hello, any updates on this by any chance?
I’m using two SPI busses as recommended. But when i input first touch it starts spamming the logs with zeros…
Some background:
I have the same display in another sensor and it works perfectly. But when i install the config for the “old sensor” (running single spi bus) to this one it causes the screen to flicker and not show anything. I’ve found that if I add the interupt pin to config it shows image on startup but as soon as i touch it it will freeze the display and after a while the display just clears which stays like this until the next restart.

Any ideas on what should I do?

I never could get it to work with ESPHome. I just converted my project to run off an arduino and sacrificed interfacing it with home assistant for now.

Well thats a pitty, thank you for the answer tho :slight_smile: I’ll write here if i find any solution…

Alright i messed around with it quite a lot and made the solution with two SPI’s working. Note that the touch is pretty slow and I havent tested it much but its good enough for my purpose.

Here is what made it work (note: i needed to swich the pins around quite a lot to find a working setup for some reasons some pin combinations just wouldn’t work but I’m also a big noob so i might be missing something…)

I think the main problem i had is that the pages for st7789v seem to not work and break things. Luckily theres a workaround using swich, global and binary sensor.

I dont know how much will this help you, but I hope that if someone struggles with this and finds this this can help them…

#Pages not working workarond:
globals:
- id: page
  type: int
  initial_value: "1"

binary_sensor:  
  - platform: touchscreen
    name: NextPage
    x_min: 70
    x_max: 240
    y_min: 75
    y_max: 230
    on_press: 
      then:
        - lambda: |- 
            ESP_LOGI("PAGE ","%d " ,id(page));
            id(page) = (id(page) + 1);
            if (id(page) > 3) {
              id(page) = 1;
            }
#Spi setup 

spi:
  - id: spi_bus_a
    clk_pin: 18
    mosi_pin: 23
    miso_pin: 19
  - id: spi_bus_b
    clk_pin: 25
    mosi_pin: 33
    miso_pin: 32

#Touchscreen setup
touchscreen:
  platform: xpt2046
  spi_id: spi_bus_b
  id: my_touchscreen
  cs_pin: 14
  interrupt_pin: 27
  update_interval: 20ms
  report_interval: never
  threshold: 200
  swap_x_y: false
  calibration_x_min: 410
  calibration_x_max: 3831
  calibration_y_min: 208
  calibration_y_max: 3692
  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
              );

#Display setup
display:
  platform: st7789v
  spi_id: spi_bus_a
  id: my_display
  model: Custom
  height: 320
  width: 240
  rotation: 0
  eightbitcolor: true
  offset_height: 0
  offset_width: 0
  update_interval: 20ms
  cs_pin: 2
  dc_pin: 13
  backlight_pin : 16
  reset_pin: 5
  lambda: |-
          switch (id(page)){
            case 1:
              it.printf(75, 5, id(roboto), id(my_black), TextAlign::TOP_CENTER,  "%.1f°C", id(temp).state);
              it.graph (5, 80, id(temp_graph), my_grey);
              it.printf(27, 85, id(small), id(my_black), TextAlign::TOP_CENTER,  "1°C/div");
              
              it.printf(75, 161, id(roboto), id(my_grey), TextAlign::TOP_CENTER,  "%.1f%%", id(hum).state);
              it.graph (5, 236, id(hum_graph), my_grey);
              it.printf(27, 240, id(small), id(my_grey), TextAlign::TOP_CENTER,  "5%%/div");
              break;
            case 2: 
              it.printf(5, 5, id(roboto), id(my_black),  "%.1f°C", id(temp).state);
              it.graph (5, 80, id(temp_graph), my_grey);
              it.printf(27, 85, id(small), id(my_black), TextAlign::TOP_CENTER,  "1°C/div");
              
              it.printf(5, 161, id(roboto), id(my_purple), "%.1f mb", id(press).state);
              it.graph (5, 236, id(press_graph), my_grey);
              it.printf(7, 240, id(small), id(my_grey), "2mbar/div");
              break;
            case 3: 
              it.printf(150, 5, id(roboto), id(my_purple), TextAlign::TOP_CENTER,  "%.1f mbar", id(press).state);
              break;
          }