For anyone interested, I spent all day poring over multiple sites and videos to get this working.
Parts:
4 in with touch == https://www.aliexpress.us/item/2251832829271342.html?spm=a2g0o.order_detail.order_detail_item.7.1fbbf19cSGM7m6&gatewayAdapt=glo2usa
esp32 == https://www.aliexpress.us/item/2251832696801305.html?spm=a2g0o.order_list.order_list_main.23.2bf81802a56ykm&gatewayAdapt=glo2usa
I followed this wiring diagram
I made the changes for IRQ to GPIO2 and I unplugged the display (MISO) so I just have T_D0 to 19(MISO)
YAML file
esphome:
name: feather
friendly_name: feather
esp32:
board: lolin_d32_pro
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
web_server:
local: true
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
captive_portal:
color:
- id: my_red
red: 100%
green: 0%
blue: 0%
- id: my_yellow
red: 100%
green: 100%
blue: 0%
- id: my_green
red: 0%
green: 100%
blue: 0%
- id: my_blue
red: 0%
green: 0%
blue: 100%
- id: my_gray
red: 50%
green: 50%
blue: 50%
font:
- file: "Arial.ttf"
id: arial_48
size: 48
- file: "Arial.ttf"
id: arial_36
size: 36
- file: "Arial.ttf"
id: arial_24
size: 24
- file: "Arial.ttf"
id: arial_12
size: 12
- file: "Arial.ttf"
id: arialbd_font
size: 12
time:
- platform: homeassistant
id: esptime
sensor:
- platform: homeassistant
id: inside_temperature
entity_id: sensor.ste1_thermo1_sht3x_temperature
internal: true
- platform: homeassistant
id: outside_temperature
entity_id: sensor.pumproom_thermo1_sht3x_temperature
internal: true
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: 13 #touch T_CS
interrupt_pin: 2 #touch T_IRQ
update_interval: 50ms
report_interval: 1s
threshold: 400
calibration_x_min: 3860
calibration_x_max: 280
calibration_y_min: 340
calibration_y_max: 3860
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
);
binary_sensor:
- platform: touchscreen
id: touch_key0
x_min: 0
x_max: 79
y_min: 0
y_max: 79
on_press:
- logger.log: "Key0 was touched"
- platform: touchscreen
id: touch_key1
x_min: 80
x_max: 159
y_min: 0
y_max: 79
on_state:
- lambda: 'ESP_LOGI("main", "key1: %s", (x ? "touch" : "release"));'
display:
- platform: ili9xxx
model: ili9488
cs_pin: 27 #display CS
dc_pin: 14 #display DC
reset_pin: 26 #display RESET
rotation: 180
id: tft_ha_test
lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height(), id(my_blue));
it.rectangle(0, 20, it.get_width(), it.get_height(), id(my_blue));
it.strftime((480 / 2), (140 / 3) * 1 + 5, id(arial_24), id(my_green), TextAlign::CENTER, "%Y-%m-%d", id(esptime).now());
it.strftime((480 / 2), (140 / 3) * 2 + 5, id(arial_48), id(my_green), TextAlign::CENTER, "%H:%M:%S", id(esptime).now());
if (id(inside_temperature).has_state()) {it.printf((120 / 2), (140 / 3) * 1 + 5, id(arial_24), id(my_green), TextAlign::CENTER, "%.1f°", id(inside_temperature).state); }
if (id(outside_temperature).has_state()) {it.printf((850 / 2), (140 / 3) * 1 + 5, id(arial_24), id(my_green), TextAlign::CENTER, "%.1f°", id(outside_temperature).state); }
it.print(240, 5, id(arial_12), id(my_green), TextAlign::TOP_CENTER, "Home Thermostat Upstairs");