I have configured 2 ILI9341 displays on separate SPI busses.
Display 1 has touch wired and enabled
Display 2 is just a display
I have an issue where when powering up the system, the touch does not work on Display 1.
If I power cycle once or twice then the touch will work. I am wondering if it has to do with the initialization sequence on power up, and what state the connections are in
Here is my config:
substitutions:
enc_id: esp32_dual_4
esphome:
name: "esp32-dual-4"
friendly_name: "esp32-dual-4"
esp32:
board: esp-wrover-kit
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "kjOvLHLwXB4lIccmThp0ktTHh8EyKc6TNOwNF20+L/8="
ota:
password: "6dd5d918481accaf043975fad923ef92"
wifi:
manual_ip:
static_ip: xxx.xxx.xxx
gateway: xxx.xxx.xxx
subnet: 255.255.255.0
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp32-Dual-Test-2"
password: "xxxxxxxxxxxxx"
captive_portal:
font:
- file: "Roboto-Regular.ttf"
id: my_font
size: 18
- file: "Roboto-Regular.ttf"
id: my_font_2
size: 18
- file: "Roboto-Medium.ttf"
id: my_font_2m
size: 18
- file: "Roboto-Regular.ttf"
id: my_font_3
size: 12
- file: "Roboto-Regular.ttf"
id: my_font_5
size: 14
- file: "Roboto-Regular.ttf"
id: my_font_4
size: 36
- file: "Roboto-Regular.ttf"
id: my_font_6
size: 10
- file: "Roboto-Regular.ttf"
id: my_font_7
size: 24
- file: "Roboto-Regular.ttf"
id: my_font_8
size: 30
- file: "Roboto-Regular.ttf"
id: my_font_10
size: 10
- file: "Roboto-Medium.ttf"
id: my_font_10m
size: 10
color:
- id: my_red
red: 100%
green: 20%
blue: 25%
white: 0%
- id: my_white
white: 100%
blue: 5%
red: 55%
green: 35%
- id: my_blue
blue: 100%
- id: my_green
green: 100%
- id: my_blue_bold
blue: 100%
# ------------------------------------------------------
# ------------------------------------------------------
time:
- platform: homeassistant
id: esptime
# ------------------------------------------------------
# ------------------------------------------------------
spi:
- id: first
clk_pin: GPIO18
mosi_pin: GPIO23
miso_pin: GPIO19
- id: second
clk_pin: GPIO14
mosi_pin: GPIO13
miso_pin: GPIO12
i2c:
- id: bus_a
sda: GPIO25
scl: GPIO26
scan: true
tca9548a :
- address: 0x70
id: multiplex0
i2c_id: bus_a
channels:
- bus_id: multiplex0channel0
channel: 0
- bus_id: multiplex0channel1
channel: 1
- bus_id: multiplex0channel2
channel: 2
- bus_id: multiplex0channel3
channel: 3
- bus_id: multiplex0channel4
channel: 4
- bus_id: multiplex0channel5
channel: 5
- bus_id: multiplex0channel6
channel: 6
- bus_id: multiplex0channel7
channel: 7
pcf8574:
- id: 'pcf8574_hub'
i2c_id: bus_a
address: 0x20
pcf8575: true
#--------------------------------------------------------
#--------------------------------------------------------
sensor:
- platform: ina219
i2c_id: multiplex0channel0
address: 0x40
shunt_resistance: 0.1 ohm
current:
name: "INA219 Current ${enc_id}-0"
id: ${enc_id}_ina219_current0
power:
name: "INA219 Power ${enc_id}-0"
id: ${enc_id}_ina219_power0
bus_voltage:
name: "INA219 Bus Voltage ${enc_id}-0"
id: ${enc_id}_ina219_bus_v0
shunt_voltage:
name: "INA219 Shunt Voltage ${enc_id}-0"
id: ${enc_id}_ina219_shunt_v0
max_voltage: 8.0V
max_current: 3.2A
update_interval: 60s
- platform: ina219
i2c_id: multiplex0channel1
address: 0x40
shunt_resistance: 0.1 ohm
current:
name: "INA219 Current ${enc_id}-1"
id: ${enc_id}_ina219_current1
power:
name: "INA219 Power ${enc_id}-1"
id: ${enc_id}_ina219_power1
bus_voltage:
name: "INA219 Bus Voltage ${enc_id}-1"
id: ${enc_id}_ina219_bus_v1
shunt_voltage:
name: "INA219 Shunt Voltage ${enc_id}-1"
id: ${enc_id}_ina219_shunt_v1
max_voltage: 12.8V
max_current: 3.2A
update_interval: 60s
- platform: internal_temperature
name: "${enc_id}-Internal Temperature"
id: internal_cpu
unit_of_measurement: "°C"
update_interval: 10s
#--------------------------------------------------------
#--------------------------------------------------------
- platform: wifi_signal
name: "${enc_id} WiFi Signal Sensor"
id: my_wifi_2
update_interval: 60s
#--------------------------------------------------------
#--------------------------------------------------------
text_sensor:
- platform: wifi_info
ip_address:
id: myip_2
name: ${enc_id} ESP IP Address
ssid:
id: myssid_2
name: ${enc_id} ESP Connected SSID
#--------------------------------------------------------
#--------------------------------------------------------
button:
- platform: restart
name: "ESP32 Restart"
id: restart_button
#--------------------------------------------------------
#--------------------------------------------------------
binary_sensor:
- platform: gpio
name: "${enc_id}_MV1_Off"
publish_initial_state: true
internal: false
pin:
pcf8574: pcf8574_hub
number: 0
mode: INPUT
inverted: true
- platform: gpio
name: "${enc_id}_MV1_On"
publish_initial_state: true
internal: false
pin:
pcf8574: pcf8574_hub
number: 1
mode: INPUT
inverted: true
- platform: gpio
name: "${enc_id}_MV2_Off"
publish_initial_state: true
internal: false
pin:
pcf8574: pcf8574_hub
number: 2
mode: INPUT
inverted: true
- platform: gpio
name: "${enc_id}_MV2_On"
publish_initial_state: true
internal: false
pin:
pcf8574: pcf8574_hub
number: 3
mode: INPUT
inverted: true
- platform: gpio
name: "${enc_id}_MV3_Off"
publish_initial_state: true
internal: false
pin:
pcf8574: pcf8574_hub
number: 4
mode: INPUT
inverted: true
- platform: gpio
name: "${enc_id}_MV3_On"
publish_initial_state: true
internal: false
pin:
pcf8574: pcf8574_hub
number: 5
mode: INPUT
inverted: true
#--------------------------------------------------------
#-------------------------------------------------------------
- platform: gpio
name: "${enc_id}-ResetButton"
internal: true
pin:
pcf8574: pcf8574_hub
number: 13
mode: INPUT
inverted: true
on_press:
- lambda: id(restart_button).press();
#-------------------------------------------------------------
#-------------------------------------------------------------
- platform: homeassistant
name: "${enc_id} Master Bath Flood"
id: mas_bath_flood
entity_id: binary_sensor.z_wave_wireless_flood_freeze_sensor_sensor_state_water
- platform: homeassistant
name: "${enc_id} Wtr Htr Flood"
id: wtr_htr_flood
entity_id: binary_sensor.water_heater_flood_detector_sensor_state_water_2
- platform: homeassistant
name: "${enc_id} Kit Sink Flood"
id: kit_sink_flood
entity_id: binary_sensor.kitchen_sink_leak_detector_sensor_state_water_2
- platform: homeassistant
name: "${enc_id} Guest Bath Flood"
id: guest_bath_flood
entity_id: binary_sensor.guest_bath_leak_sensor_sensor_state_water_2
- platform: homeassistant
name: "${enc_id} Guest Sink Flood"
id: guest_bath_sink_flood
entity_id: binary_sensor.gbr_sink_leak_detector_sensor_state_water_2
- platform: homeassistant
name: "${enc_id} Master Sink Flood"
id: mas_bath_sink_flood
entity_id: binary_sensor.mbr_sink_leak_detector_sensor_state_water_2
#---------------------------------------------------------------------------
#---------------------------------------------------------------------------
- platform: homeassistant
name: "${enc_id} Insteon Master Bath Sink"
id: ins_mas_bath_sink
entity_id: binary_sensor.masterbathsink_dry
- platform: homeassistant
name: "${enc_id} Insteon Master Bath"
id: ins_mas_bath
entity_id: binary_sensor.mas_bath_leak_dry
- platform: homeassistant
name: "${enc_id} Insteon Kitchen Sink"
id: ins_kit_sink
entity_id: binary_sensor.kitchen_sink_dry
- platform: homeassistant
name: "${enc_id} Insteon Guest Bath"
id: ins_guest_bath
entity_id: binary_sensor.70_79_88_1_dry
- platform: homeassistant
name: "${enc_id} Insteon Refrigerator"
id: ins_fridge
entity_id: binary_sensor.70_76_fc_1_dry
- platform: homeassistant
name: "${enc_id} Insteon Dishwasher"
id: ins_dishwasher
entity_id: binary_sensor.70_7a_18_1_dry
- platform: homeassistant
name: "${enc_id} Insteon Water Htr "
id: ins_wtr_htr
entity_id: binary_sensor.water_heater_dry
#--------------------------------------------------------
- platform: homeassistant
id: mv1_off
entity_id: binary_sensor.esp32_dual_4_esp32_dual_4_mv1_off
- platform: homeassistant
id: mv1_on
entity_id: binary_sensor.esp32_dual_4_esp32_dual_4_mv1_on
- platform: homeassistant
id: mv2_off
entity_id: binary_sensor.esp32_dual_4_esp32_dual_4_mv2_off
- platform: homeassistant
id: mv2_on
entity_id: binary_sensor.esp32_dual_4_esp32_dual_4_mv2_on
- platform: homeassistant
id: mv3_off
entity_id: binary_sensor.esp32_dual_4_esp32_dual_4_mv3_off
- platform: homeassistant
id: mv3_on
entity_id: binary_sensor.esp32_dual_4_esp32_dual_4_mv3_on
#--------------------------------------------------------
- platform: touchscreen
id: touch_key0
x_min: 2
x_max: 58
y_min: 19
y_max: 56
on_press:
- logger.log: "V1 toggle was touched"
- lambda: id(valve_sw0).toggle();
- platform: touchscreen
id: touch_key1
x_min: 2
x_max: 58
y_min: 59
y_max: 96
on_press:
- logger.log: "V1 toggle was touched"
- lambda: id(valve_sw1).toggle();
- platform: touchscreen
id: touch_key2
x_min: 2
x_max: 58
y_min: 99
y_max: 136
on_press:
- logger.log: "V2 toggle was touched"
- lambda: id(valve_sw2).toggle();
#--------------------------------------------------------
switch:
- platform: gpio
name: "${enc_id}-Valve1"
id: valve_sw0
pin:
pcf8574: pcf8574_hub
number: 8
mode: OUTPUT
inverted: true
- platform: gpio
name: "${enc_id}-Valve2"
id: valve_sw1
pin:
pcf8574: pcf8574_hub
number: 10
mode: OUTPUT
inverted: true
- platform: gpio
name: "${enc_id}-Valve3"
id: valve_sw2
pin:
pcf8574: pcf8574_hub
number: 12
mode: OUTPUT
inverted: true
#--------------------------------------------------------
#--------------------------------------------------------
- platform: output
output: gpio_33_backlight_pwm
name: "${enc_id}-ILI9341 Display Backlight"
id: back_light
restore_mode: ALWAYS_ON
#--------------------------------------------------------
#--------------------------------------------------------
output:
- platform: gpio
pin: GPIO33
inverted: false
id: gpio_33_backlight_pwm
#--------------------------------------------------------
#--------------------------------------------------------
touchscreen:
spi_id: first
platform: xpt2046
display: my_tft
id: my_touchscreen
cs_pin: 33
interrupt_pin: 27
update_interval: 50ms
report_interval: 1s
threshold: 400
calibration_x_min: 265
calibration_x_max: 3868
calibration_y_min: 3863
calibration_y_max: 395
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:
- platform: ili9xxx
spi_id: first
id: my_tft
model: ili9341
rotation: 270
cs_pin: GPIO5
dc_pin: GPIO21
reset_pin: GPIO32
pages:
- id: page_tft_1_1
lambda: |-
auto white = Color(255, 255, 255);
auto yellow = Color(255, 255, 0);
auto blue = Color(0, 0, 255);
auto red = Color(255, 0, 0);
auto green = Color(0, 255, 0);
it.fill(Color::BLACK);
it.rectangle(0, 18, 60, 37, yellow);
it.printf(0, 20, id(my_font_2), green, " Main");
it.printf(0, 35, id(my_font_2), green, " Valve");
it.filled_rectangle(60, 26, 30, 7, white);
it.filled_rectangle(60, 41, 30, 7, white);
it.filled_rectangle(90, 26, 7, 22, white);
if (id(valve_sw0).state) {
it.filled_rectangle(97, 33, 30, 7, green);
it.printf(132, 27, id(my_font_5), green, "Relay On");
} else {
it.filled_rectangle(97, 33, 30, 7, red);
it.printf(132, 27, id(my_font_5), red, "Relay Off");
}
if (id(mv1_on).state) {
it.filled_rectangle(195, 33, 30, 7, green);
it.printf(230, 27, id(my_font_5), green, "MV1 Open");
} else if (id(mv1_off).state) {
it.filled_rectangle(195, 33, 30, 7, red);
it.printf(230, 27, id(my_font_5), red, "MV1 Closed");
} else if (id(valve_sw0).state) {
it.filled_rectangle(195, 33, 30, 7, blue);
it.printf(230, 27, id(my_font_5), blue, "Opening");
} else {
it.filled_rectangle(195, 33, 30, 7, blue);
it.printf(230, 27, id(my_font_5), blue, "Closing");
}
it.rectangle(0, 58, 60, 37, yellow);
it.printf(0, 60, id(my_font_2), green, " Irrig");
it.printf(0, 75, id(my_font_2), green, " Valve");
it.filled_rectangle(60, 66, 30, 7, white);
it.filled_rectangle(60, 81, 30, 7, white);
it.filled_rectangle(90, 66, 7, 22, white);
if (id(valve_sw1).state) {
it.filled_rectangle(97, 73, 30, 7, green);
it.printf(132, 67, id(my_font_5), green, "Relay On");
} else {
it.filled_rectangle(97, 73, 30, 7, red);
it.printf(132, 67, id(my_font_5), red, "Relay Off");
}
if (id(mv2_on).state) {
it.filled_rectangle(195, 73, 30, 7, blue);
it.printf(230, 67, id(my_font_5), green, "MV2 Open");
} else if (id(mv2_off).state) {
it.filled_rectangle(195, 73, 30, 7, red);
it.printf(230, 67, id(my_font_5), red, "MV2 Closed");
} else if (id(valve_sw1).state) {
it.filled_rectangle(195, 73, 30, 7, blue);
it.printf(230, 67, id(my_font_5), blue, "Opening");
} else {
it.filled_rectangle(195, 73, 30, 7, blue);
it.printf(230, 67, id(my_font_5), blue, "Closing");
}
it.rectangle(0, 98, 60, 37, yellow);
it.printf(0, 100, id(my_font_2), green, " Hot W");
it.printf(0, 115, id(my_font_2), green, " Valve");
it.filled_rectangle(60, 106, 30, 7, white);
it.filled_rectangle(60, 121, 30, 7, white);
it.filled_rectangle(90, 106, 7, 22, white);
if (id(valve_sw2).state) {
it.filled_rectangle(97, 113, 30, 7, green);
it.printf(132, 107, id(my_font_5), green, "Relay On");
} else {
it.filled_rectangle(97, 113, 30, 7, red);
it.printf(132, 107, id(my_font_5), red, "Relay Off");
}
if (id(mv3_on).state) {
it.filled_rectangle(195, 113, 30, 7, green);
it.printf(230, 107, id(my_font_5), green, "MV3 Open");
} else if (id(mv3_off).state) {
it.filled_rectangle(195, 113, 30, 7, red);
it.printf(230, 107, id(my_font_5), red, "MV3 Closed");
} else if (id(valve_sw2).state) {
it.filled_rectangle(195, 113, 30, 7, blue);
it.printf(230, 107, id(my_font_5), blue, "Opening");
} else {
it.filled_rectangle(195, 113, 30, 7, blue);
it.printf(230, 107, id(my_font_5), blue, "Closing");
}
it.filled_rectangle(0, 160, 320, 5, blue);
it.printf(70, 170, id(my_font_3), "CPU_Temperature- %.1f° C", id(internal_cpu).state);
it.filled_rectangle(0, 190, 320, 5, blue);
it.strftime(5, 200, id(my_font_3), "Time:%H:%M:%S", id(esptime).now());
it.printf(160, 200, id(my_font_3), "SSID:%s", id(myssid_2).state.c_str());
it.printf(5, 220, id(my_font_3), "Signal:%.1f dbm", id(my_wifi_2).state);
it.printf(160, 220, id(my_font_3), "IP:%s", id(myip_2).state.c_str());
- platform: ili9xxx
spi_id: second
id: my_tft2
model: ili9341
rotation: 90
cs_pin: GPIO15
dc_pin: GPIO22
reset_pin: GPIO4
pages:
- id: page_tft_2_1
lambda: |-
auto white = Color(255, 255, 255);
auto yellow = Color(255, 255, 0);
auto blue = Color(0, 0, 255);
auto red = Color(255, 0, 0);
auto green = Color(0, 255, 0);
it.fill(Color::BLACK);
it.printf(10, 5, id(my_font_7), blue, "Valve Control/Leak Sensors");
it.printf(80, 32, id(my_font_5), "Configuration Version 3.1");
it.printf(10, 47, id(my_font_3), green, "5V USB Power");
it.filled_rectangle(10, 62, 75, 3, blue);
it.printf(10, 65, id(my_font_3), "AMPS: %.3f A", id(${enc_id}_ina219_current1).state);
it.printf(10, 80, id(my_font_3), "Bus: %.3f V", id(${enc_id}_ina219_bus_v1).state);
it.printf(10, 95, id(my_font_3), "PWR: %.3f W", id(${enc_id}_ina219_power1).state);
it.printf(180, 47, id(my_font_3), green, "12V Valve Power");
it.filled_rectangle(180, 62, 90, 3, blue);
it.printf(180, 65, id(my_font_3), "Valve-Cur: %.3f A", id(${enc_id}_ina219_current0).state);
it.printf(180, 80, id(my_font_3), "Valve Bus: %.3f V", id(${enc_id}_ina219_bus_v0).state);
it.printf(180, 95, id(my_font_3), "Valve PWR: %.3f W", id(${enc_id}_ina219_power0).state);
it.filled_rectangle(0, 115, 320, 5, blue);
it.printf(80, 125, id(my_font_10m), "Insteon Wtr Htr");
if (id(ins_wtr_htr).state) {
static int i1 = 0;
i1++;
if ((i1 % 2) == 0){
it.printf(165, 125, id(my_font_5), red, "WET");
}else{
it.printf(165, 125, id(my_font_5), white, "WET");
}
}else{
it.printf(165, 125, id(my_font_10m), id(my_green), "DRY");
}
it.printf(10, 135, id(my_font_10m), "Master Bath");
if (id(mas_bath_flood).state) {
static int i2 = 0;
i2++;
if ((i2 % 2) == 0){
it.printf(90, 135, id(my_font_5), red, "WET");
}else{
it.printf(90, 135, id(my_font_5), white, "WET");
}
} else {
it.printf(90, 135, id(my_font_10m), id(my_green), "DRY");
}
it.printf(10, 145, id(my_font_10m),"Sensor 2");
if (id(wtr_htr_flood).state) {
static int i3 = 0;
i3++;
if ((i3 % 2) == 0){
it.printf(90, 145, id(my_font_5), red, "WET");
}else{
it.printf(90, 145, id(my_font_5), white, "WET");
}
} else {
it.printf(90, 145, id(my_font_10m), id(my_green), "DRY");
}
it.printf(10, 155, id(my_font_10m),"Kit Sink");
if (id(kit_sink_flood).state) {
static int i4 = 0;
i4++;
if ((i4 % 2) == 0){
it.printf(90, 155, id(my_font_5), red, "WET");
}else{
it.printf(90, 155, id(my_font_5), white, "WET");
}
} else {
it.printf(90, 155, id(my_font_10m), id(my_green), "DRY");
}
it.printf(10, 165, id(my_font_10m),"Guest Bath");
if (id(guest_bath_flood).state) {
static int i5 = 0;
i5++;
if ((i5 % 2) == 0){
it.printf(90, 165, id(my_font_5), red, "WET");
}else{
it.printf(90, 165, id(my_font_5), white, "WET");
}
} else {
it.printf(90, 165, id(my_font_10m), id(my_green), "DRY");
}
it.printf(10, 175, id(my_font_10m),"Guest Bath Sink");
if (id(guest_bath_sink_flood).state) {
static int i6 = 0;
i6++;
if ((i6 % 2) == 0){
it.printf(90, 175, id(my_font_5), red, "WET");
}else{
it.printf(90, 175, id(my_font_5), white, "WET");
}
} else {
it.printf(90, 175, id(my_font_10m), id(my_green), "DRY");
}
it.printf(10, 185, id(my_font_10m),"Mas Bath Sink");
if (id(mas_bath_sink_flood).state) {
static int i7 = 0;
i7++;
if ((i7 % 2) == 0){
it.printf(90, 185, id(my_font_5), red, "WET");
}else{
it.printf(90, 185, id(my_font_5), white, "WET");
}
} else {
it.printf(90, 185, id(my_font_10m), id(my_green), "DRY");
}
it.printf(120, 135, id(my_font_10m), "Ins Mas Bath Sink");
if (id(ins_mas_bath_sink).state) {
static int i8 = 0;
i8++;
if ((i8 % 2) == 0){
it.printf(210, 135, id(my_font_5), red, "WET");
}else{
it.printf(210, 135, id(my_font_5), white, "WET");
}
} else {
it.printf(210, 135, id(my_font_10m), id(my_green), "DRY");
}
it.printf(120, 145, id(my_font_10m),"Ins Master Bath");
if (id(ins_mas_bath).state) {
static int i9 = 0;
i9++;
if ((i9 % 2) == 0){
it.printf(210, 145, id(my_font_5), red, "WET");
}else{
it.printf(210, 145, id(my_font_5), white, "WET");
}
} else {
it.printf(210, 145, id(my_font_10m), id(my_green), "DRY");
}
it.printf(120, 155, id(my_font_10m),"Ins Kitchen Sink");
if (id(ins_kit_sink).state) {
static int ii = 0;
ii++;
if ((ii % 2) == 0){
it.printf(210, 155, id(my_font_5), red, "WET");
}else{
it.printf(210, 155, id(my_font_5), white, "WET");
}
} else {
it.printf(210, 155, id(my_font_10m), id(my_green), "DRY");
}
it.printf(120, 165, id(my_font_10m),"Ins Guest Bath");
if (id(ins_guest_bath).state) {
static int ii1 = 0;
ii1++;
if ((ii1 % 2) == 0){
it.printf(210, 165, id(my_font_5), red, "WET");
}else{
it.printf(210, 165, id(my_font_5), white, "WET");
}
} else {
it.printf(210, 165, id(my_font_10m), id(my_green), "DRY");
}
it.printf(120, 175, id(my_font_10m),"Ins Refrigerator");
if (id(ins_fridge).state) {
static int ii2 = 0;
ii2++;
if ((ii2 % 2) == 0){
it.printf(210, 175, id(my_font_5), red, "WET");
}else{
it.printf(210, 175, id(my_font_5), white, "WET");
}
} else {
it.printf(210, 175, id(my_font_10m), id(my_green), "DRY");
}
it.printf(120, 185, id(my_font_10m),"Ins Dishwasher");
if (id(ins_dishwasher).state) {
static int ii3 = 0;
ii3++;
if ((ii3 % 2) == 0){
it.printf(210, 185, id(my_font_5), red, "WET");
}else{
it.printf(210, 185, id(my_font_5), white, "WET");
}
} else {
it.printf(210, 185, id(my_font_10m), id(my_green), "DRY");
}