esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
292 stars 36 forks source link

Touchscreen tt21100 no longer working after 2023.12.3 update #5274

Open woodshoes opened 11 months ago

woodshoes commented 11 months ago

The problem

Upgraded from 2023.11.6 to 2023.12.3 on my ESP32-S3-BOX (the old one) My touchscreen does not work - the screen or the home button directly below.
Reverted back to 2023.11.6 and it started working again. I know there is a breaking change for the touchscreen component as listed here but it doesn't look like I need to make any changes from my config? Nothing fancy going on for the box, just using it as a display with some touchscreen buttons to turn office lights on/off.

Which version of ESPHome has the issue?

2023.12.3

What type of installation are you using?

Home Assistant Add-on

Which version of Home Assistant has the issue?

2023.12.3

What platform are you using?

ESP32

Board

ESP32-S3-BOX

Component causing the issue

touchscreen

Example YAML snippet

---
esphome:
  name: flexbox
  friendly_name: ESP32 S3 Box
  platformio_options:
    board_build.flash_mode: dio
  project:
    name: esphome.voice-assistant
    version: "1.0"
  min_version: 2023.10.5
  includes:
    - common.h

esp32:
  board: esp32s3box
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
      CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
      CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"

logger:
  hardware_uart: USB_SERIAL_JTAG
  level: DEBUG
  logs:
    component: ERROR

api: 
  encryption:
    key: 3IzrqZs4csVkrt7/lmr238Z+HRP/vAZCbgqGCOe8zsQ=

ota:
  password: !secret ota_password

dashboard_import:
  package_import_url: github://esphome/firmware/voice-assistant/esp32-s3-box.yaml@main

packages:
  <<: !include_dir_named common  

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: True
  manual_ip:
    static_ip: 192.168.25.74
    gateway: 192.168.25.254
    subnet: 255.255.255.0
    dns1: 192.168.1.210

binary_sensor:
  - platform: tt21100
    name: Home-Button
    index: 0
    tt21100_id: my_touchscreen
    internal: False
  - platform: touchscreen
    name: "FanLo"
    x_min: 0
    x_max: 105
    y_min: 0
    y_max: 80
  - platform: touchscreen
    name: "FanMed"
    x_min: 106
    x_max: 210
    y_min: 0
    y_max: 80
  - platform: touchscreen
    name: "FanHi"
    x_min: 211
    x_max: 320
    y_min: 0
    y_max: 80
  - platform: touchscreen
    name: "FanOff"
    x_min: 106
    x_max: 210
    y_min: 81
    y_max: 160
  - platform: touchscreen
    name: "Lamp"
    x_min: 40
    x_max: 140
    y_min: 161
    y_max: 240
  - platform: touchscreen
    name: "FanLight"
    x_min: 180
    x_max: 280
    y_min: 161
    y_max: 240

output:
  - platform: ledc
    pin: GPIO45
    id: backlight_output

light:
  - platform: monochromatic
    output: backlight_output
    name: LCD Backlight
    id: led
    restore_mode: ALWAYS_ON
    disabled_by_default: true
    default_transition_length: 0s

#esp_adf:

#microphone:
#  - platform: esp_adf
#    id: box_mic

#speaker:
#  - platform: esp_adf
#    id: box_speaker

#external_components:
#  - source: github://pr#5230
#    components: esp_adf
#    refresh: 0s

spi:
  clk_pin: GPIO7
  mosi_pin: GPIO6

# some HW Components of the S3-Box
i2c:
  scl: GPIO18
  sda: GPIO8
  scan: true

touchscreen:
  platform: tt21100
  id: my_touchscreen
  # address: 0x24
  interrupt_pin: GPIO3

# source: https://gist.github.com/BrettSheleski/5a33f6880c5ad4033ac2dc4cb5797ac1
# material UI icons - from https://pictogrammers.github.io/@mdi/font/5.3.45/
font:
  - file: "gfonts://Roboto@500"
    id: font_large
    size: 70
    glyphs: "0123456789:APM."
  - file: "gfonts://Roboto@500"
    id: font_medium
    size: 30
  - file: "gfonts://Roboto@500"
    id: font_small
    size: 15
  - file: "Arial.ttf"
    id: font_arial_big
    size: 70
  - file: "materialdesignicons-webfont.ttf"
    id: font_icons
    size: 130
    glyphs:
      - "\U000F0594" # clear-night
      - "\U000F0590" # cloudy
      - "\U000F0591" # fog
      - "\U000F0592" # hail
      - "\U000F0593" # lightning
      - "\U000F067E" # lightning-rainy
      - "\U000F0F31" # night-partly-cloudy
      - "\U000F0595" # partly-cloudy
      - "\U000F0596" # pouring
      - "\U000F0597" # rainy
      - "\U000F0F36" # snowy
      - "\U000F067F" # snowy-rainy
      - "\U000F0599" # sunny
      - "\U000F059D" # windy
      - "\U000F059E" # windy-variant
      - "\U000F0F38" # exCentereptional
      # Garage and others Status
      - "\U000F06D9" # garage closed
      - "\U000F06DA" # garage opened

  - file: "materialdesignicons-webfont.ttf"
    id: font_icons_med
    size: 45     
    glyphs:
      # Small Weather Icons
      - "\U000F0594" # clear-night
      - "\U000F0590" # cloudy
      - "\U000F0591" # fog
      - "\U000F0592" # hail
      - "\U000F0593" # lightning
      - "\U000F067E" # lightning-rainy
      - "\U000F0F31" # night-partly-cloudy
      - "\U000F0595" # partly-cloudy
      - "\U000F0596" # pouring
      - "\U000F0597" # rainy
      - "\U000F0F36" # snowy
      - "\U000F067F" # snowy-rainy
      - "\U000F0599" # sunny
      - "\U000F059D" # windy
      - "\U000F059E" # windy-variant/wind avg
      - "\U000F0F38" # exCentereptional
      # Misc icons
      - "\U000F10C2" # Temperature High
      - "\U000F10C3" # Temperature Low
      - "\U000F054B" # umbrella
      - "\U000F02E3" # Bed
      - "\U000F0E2E" # Fireplace On
      - "\U000F0E2F" # Fireplace Off
      - "\U000F04B9" # sofa
      - "\U000F023F" # wind max
      - "\U000F140B" # lightning
      - "\U000F028F" # fridge
      - "\U000F11B1" # fridge problem
      - "\U000F1435" # no motion
      - "\U000F0D91" # motion detected
      - "\U000F17FF" # UV Sun
      - "\U000F059C" # Sunrise
      - "\U000F059B" # Sunset
      # moon phases
      - "\U000F0F61" # moon-first-quarter
      - "\U000F0F62" # moon-full
      - "\U000F0F63" # moon-last-quarter
      - "\U000F0F64" # moon-new
      - "\U000F0F65" # moon-waning-crescent
      - "\U000F0F66" # moon-waning-gibbous
      - "\U000F0F67" # moon-waxing-crescent
      - "\U000F0F68" # moon-waxing-gibbous
      # fan and light
      - "\U000F1472" # Fan speed 1
      - "\U000F1473" # Fan speed 2 
      - "\U000F1474" # Fan speed 3
      - "\U000F081D" # Fan off
      - "\U000F06B5" # Lamp
      - "\U000F0769" # Ceiling Light       

  - file: "materialdesignicons-webfont.ttf"
    id: font_icons_small
    size: 15
    glyphs:
      # Small Weather Icons
      - "\U000F0594" # clear-night
      - "\U000F0590" # cloudy
      - "\U000F0591" # fog
      - "\U000F0592" # hail
      - "\U000F0593" # lightning
      - "\U000F067E" # lightning-rainy
      - "\U000F0F31" # night-partly-cloudy
      - "\U000F0595" # partly-cloudy
      - "\U000F0596" # pouring
      - "\U000F0597" # rainy
      - "\U000F0F36" # snowy
      - "\U000F067F" # snowy-rainy
      - "\U000F0599" # sunny
      - "\U000F059D" # windy
      - "\U000F059E" # windy-variant/wind avg
      - "\U000F0F38" # exCentereptional
      # Misc icons
      - "\U000F10C2" # Temperature High
      - "\U000F10C3" # Temperature Low
      - "\U000F054B" # umbrella
      - "\U000F02E3" # Bed
      - "\U000F0E2E" # Fireplace On
      - "\U000F0E2F" # Fireplace Off
      - "\U000F04B9" # sofa
      - "\U000F023F" # wind max
      - "\U000F140B" # lightning
      - "\U000F028F" # fridge
      - "\U000F11B1" # fridge problem
      - "\U000F1435" # no motion
      - "\U000F0D91" # motion detected
      - "\U000F17FF" # UV Sun
      - "\U000F059C" # Sunrise
      - "\U000F059B" # Sunset
      # moon phases
      - "\U000F0F61" # moon-first-quarter
      - "\U000F0F62" # moon-full
      - "\U000F0F63" # moon-last-quarter
      - "\U000F0F64" # moon-new
      - "\U000F0F65" # moon-waning-crescent
      - "\U000F0F66" # moon-waning-gibbous
      - "\U000F0F67" # moon-waxing-crescent
      - "\U000F0F68" # moon-waxing-gibbous

  - file: "materialdesignicons-webfont.ttf"
    id: font_icons_tiny
    size: 32
    glyphs:
      - "\U000F005E" # arrow-up-thick
      - "\U000F0046" # arrow-down-thick

display:
  - platform: ili9xxx
    model: S3BOX
    cs_pin: GPIO5
    dc_pin: GPIO4
    reset_pin: GPIO48
    id: lcd
    lambda: |-
      #define ICON_fan1     "\U000F1472"
      #define ICON_fan2     "\U000F1473"
      #define ICON_fan3     "\U000F1474"
      #define ICON_fanoff   "\U000F081D"
      #define ICON_lamp     "\U000F06B5"
      #define ICON_ceiling  "\U000F0769"   
      auto bg = Color(250, 250, 250);
      auto text = Color(250, 250, 250);
      auto border_color = Color(60, 60, 60);
      auto button_bg_on = Color(36, 180, 245);
      auto button_bg_off = Color(158, 158, 158);
      auto red = Color(255, 0, 0);
      auto green = Color(0, 255, 0);
      auto blue = Color(0, 0, 255);
      if (id(home_pressed).state == "off") {
      it.image(0,0, id(background_image), ImageAlign::TOP_LEFT);
      it.printf(160, 35, id(font_arial_big), TextAlign::CENTER, "%s", id(readable_ha_time).state.c_str());
      it.strftime(160, 90, id(font_medium), text, TextAlign::CENTER, "%A", id(time_ha).now());
      it.strftime(160, 125, id(font_medium), text, TextAlign::CENTER, "%m/%d/%Y", id(time_ha).now());
      if (id(backyard_temp).has_state()) {
        it.printf(0, 185, id(font_medium), text, TextAlign::LEFT, "Out: %.f°F", id(backyard_temp).state);
      }
      if (id(hitemp).has_state()) {
        it.printf(165, 185, id(font_small), text, TextAlign::LEFT, "Hi: %s°F", id(hitemp).state.c_str());
      }
      if (id(lowtemp).has_state()) {
        it.printf(165, 200, id(font_small), text, TextAlign::LEFT, "Lo: %s°F", id(lowtemp).state.c_str());
      }
      if (id(sunup).has_state()) {
        it.printf(235, 185, id(font_small), text, TextAlign::LEFT, "Rise: %s", id(sunup).state.c_str());
      }
      if (id(sundown).has_state()) {
        it.printf(235, 200, id(font_small), text, TextAlign::LEFT, "  Set: %s", id(sundown).state.c_str());
      }
      // moon phase
      auto moonIcon = moonToIcon(id(moon).state);      
      it.printf(20, 90, id(font_icons_med), TextAlign::LEFT, moonIcon.c_str());
      it.printf(40, 150, id(font_small), TextAlign::CENTER, id(moon_eng).state.c_str());
      // current condition icon
      auto dayTime = id(sun).state == "above_horizon";
      auto conditionIcon = conditionToIcon(id(w_condition).state, dayTime);
      it.printf(260, 90, id(font_icons_med), TextAlign::LEFT, conditionIcon.c_str());
      it.printf(280, 150, id(font_small), TextAlign::CENTER, id(condition_eng).state.c_str());
      it.printf(160, 230, id(font_small), TextAlign::CENTER, id(open_doors).state.c_str());
      } else {
      it.image(0,0, id(background_image), ImageAlign::TOP_LEFT);
      it.printf(40, 40, id(font_icons_med), TextAlign::CENTER, ICON_fan1);
      it.printf(40, 70, id(font_small), text, TextAlign::CENTER, "Low");
      it.printf(160, 40, id(font_icons_med), TextAlign::CENTER, ICON_fan2);
      it.printf(160, 70, id(font_small), text, TextAlign::CENTER, "Med");
      it.printf(280, 40, id(font_icons_med), TextAlign::CENTER, ICON_fan3);
      it.printf(280, 70, id(font_small), text, TextAlign::CENTER, "High");
      it.printf(160, 120, id(font_icons_med), TextAlign::CENTER, ICON_fanoff);
      it.printf(160, 150, id(font_small), text, TextAlign::CENTER, "Off"); 
      it.printf(90, 190, id(font_icons_med), TextAlign::CENTER, ICON_lamp);
      it.printf(90, 220, id(font_small), text, TextAlign::CENTER, "Lamp"); 
      it.printf(230, 190, id(font_icons_med), TextAlign::CENTER, ICON_ceiling); 
      it.printf(230, 220, id(font_small), text, TextAlign::CENTER, "Fan Light");

      }

sensor:
  - platform: homeassistant
    id: backyard_temp
    entity_id: sensor.back_porch_fan_button_temperature
    internal: True

text_sensor:    
  - platform: homeassistant
    id: current_time
    entity_id: sensor.time
    internal: true
  - platform: homeassistant
    name: Readable_time
    entity_id: sensor.12h_time
    id: readable_ha_time   
  - platform: homeassistant
    id: lowtemp
    entity_id: sensor.temp_low
    internal: True
  - platform: homeassistant
    id: hitemp
    entity_id: sensor.temp_hi
    internal: True
  - platform: homeassistant
    id: sundown
    entity_id: sensor.sun_down
    internal: True
  - platform: homeassistant
    id: sunup
    entity_id: sensor.sun_up
    internal: True
  - platform: homeassistant
    id: moon
    entity_id: sensor.moon_phase
    internal: True
  - platform: homeassistant
    id: moon_eng
    entity_id: sensor.moon_phase_eng
    internal: True
  - platform: homeassistant
    id: condition_eng
    entity_id: sensor.condition_eng
    internal: True
  - platform: homeassistant
    entity_id: weather.blenheimdmz
    id: w_condition
    internal: true
  - platform: homeassistant
    entity_id: sun.sun
    id: sun
    internal: true
  - platform: homeassistant
    entity_id: sensor.open_doors
    id: open_doors
    internal: true
  - platform: homeassistant
    id: home_pressed
    entity_id: input_boolean.flexbox_home_pressed
    internal: True    

image:
  - file: "images/Graphic-Design-Background-320x240.jpg"
    id: background_image
    resize: 320x240
    type: rgba

time:
  - platform: homeassistant
    id: time_ha
    timezone: America/Chicago

psram:
  mode: octal
  speed: 80MHz

Anything in the logs that might be useful for us?

Even with VERY_VERBOSE logging turned on (and removing the component: ERROR) I see nothing in the logs for touchscreen events.

Additional information

No response

nielsnl68 commented 11 months ago

Sadly i do not own a display with the tt21100 controller. Would you help me out and create a small script with only the display and the touchscreen ?

and change the yaml code for the touchscreen in:

esphome:
  name: flexbox
  friendly_name: ESP32 S3 Box
  platformio_options:
    board_build.flash_mode: dio
  project:
    name: esphome.voice-assistant
    version: "1.0"
  min_version: 2023.10.5

esp32:
  board: esp32s3box
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
      CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
      CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"

logger:
  hardware_uart: USB_SERIAL_JTAG
  level: DEBUG

api: 
  encryption:
    key: 3IzrqZs4csVkrt7/lmr238Z+HRP/vAZCbgqGCOe8zsQ=

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: True
  manual_ip:
    static_ip: 192.168.25.74
    gateway: 192.168.25.254
    subnet: 255.255.255.0
    dns1: 192.168.1.210

psram:
  mode: octal
  speed: 80MHz

spi:
  clk_pin: GPIO7
  mosi_pin: GPIO6

# some HW Components of the S3-Box
i2c:
  scl: GPIO18
  sda: GPIO8
  scan: true

display:
  - platform: ili9xxx
    model: S3BOX
    cs_pin: GPIO5
    dc_pin: GPIO4
    reset_pin: GPIO48
    id: lcd

touchscreen:
  platform: tt21100
  id: my_touchscreen
  # address: 0x24
  interrupt_pin: GPIO3
  on_touch:
    - lambda: |-
          ESP_LOGI("cal", "id=%d, x=%d, y=%d, x_raw=%d, y_raw=%0d",
              touch.id,
              touch.x,
              touch.y,
              touch.x_raw,
              touch.y_raw
              );     
  on_release:
    - lambda: |-
          ESP_LOGI("cal", "touches released",

Can you show the result of the log information when you touch and release the screen at the 4 corners?

thanks

woodshoes commented 11 months ago

Hello I had to "finish" your yaml above - not sure if you wanted more in it? I made the last section read:

on_release:

After that, it flashed OK - but there is NOTHING in the logs about touchscreen events. Attached is a log file I took over USB - and I was touching all over that screen with no result.

Wireless flash of YAML from esphome 2023.12.3 logs_flexdisplay_run.txt

USB logs flexdisplay_logs (2).txt

and the new YAML flexdisplay.txt

Thanks for the help!

nielsnl68 commented 11 months ago

can you try using the same with the Arduino framework?

woodshoes commented 11 months ago

Done. Had to remove a few lines for it to compile - but it is the exact same result. Nothing in the logs for touch events. Logs after reboot flexdisplay_logs (3).txt New yaml flexdisplay-arduino.txt

nielsnl68 commented 11 months ago

is this really all what you get in your log? I see only setup part but not the rest of the log.

clydebarrow commented 11 months ago

Change log level to VERBOSE and see what appears in the log.

logger:
  hardware_uart: USB_SERIAL_JTAG
  level: VERBOSE
clydebarrow commented 11 months ago

Hmmm, looks like this was removed from the original code:

  // Trigger initial read to activate the interrupt
  this->store_.touch = true;

I infer from this that it is necessary to read the chip once before any interrupts are fired.

nielsnl68 commented 11 months ago

// Trigger initial read to activate the interrupt this->store_.touch = true;

okay, restored this lines.

woodshoes commented 11 months ago

OK - not sure what to do now, do you still want to see logs w/ VERBOSE? It doesn't show touch events, not even with VERYVERBOSE. How can I test the "this->store.touch = true;" Thanks

clydebarrow commented 11 months ago

Add to your yaml:

external_components:
  - source: github://pr#6008
    components: [ tt21100 ]

That will pull in the fix. Report back and if that fixes it I will merge the PR.

woodshoes commented 10 months ago

OK This has made progress but it still is not working correctly. After pulling in the PR, the touch screen only works once. It never registers again after the first touch.
If I press the "home" button before I touch the screen, it works repeatedly as shown in the logs here flexdisplay_logs (4).txt

But once I touch the display anywhere (besides the home button) it logs once but then no touches register again, not even a home button press.
flexdisplay_logs (5).txt

And not sure if y'all want to see the yaml but its here flexdisplay (1).txt

Thanks everyone!

woodshoes commented 10 months ago

And just noticed that the PR was pulled in - upgraded to 2023.12.5 (removed the PR pull from yaml) - same results. Home button works until one screen touch - then it doesn't work any more AND the touch screen does not respond or log any more events.

nielsnl68 commented 10 months ago

Do you have any means to monitor the pin GIO3, somehow? I like to know how this pin behaves while you touch the screen.

woodshoes commented 10 months ago

Off the top of my head no, but could try to figure it out. What would I need?

nielsnl68 commented 10 months ago

You could start simply with a LED and a resister

woodshoes commented 10 months ago

Welp - looks like I wont be able to be much help on the hardware troubleshooting side. This device is already assembled with the screen and such (ESP32-S3-BOX). I got it partially apart but didnt see any pinout access for GPIO3. Anything else we can try? It works perfectly in 2023.11.6.

nielsnl68 commented 10 months ago

okay np, thanks for looking into it anyway.

tommck commented 10 months ago

I have one of these that I'm trying to setup for the first time. Should I jump in here?

clydebarrow commented 10 months ago

I'm going to have another look at this and will need testers - don't have the S3Box (only the -3 which is a different touch chip) to test on here. Stand by.

cptskippy commented 9 months ago

I think I am experiencing the same issue as @woodshoes.

After pulling in the PR, the touch screen only works once.

The binary sensor works perfectly...

i2c:
  sda: GPIO8
  scl: GPIO18
  scan: true

touchscreen:
  - platform: tt21100
    address: 0x24
    interrupt_pin: GPIO3
    on_touch:
      - logger.log: "Touchscreen:: Touched"

binary_sensor:
  - platform: tt21100
    index: 0
    name: "Home"

...UNTIL you touch the touchscreen. As soon as you touch the touchscreen the on_touch event fires and then the tt21100 stops responding.

[13:24:33][D][binary_sensor:036]: 'Home': Sending state ON
[13:24:33][D][binary_sensor:036]: 'Home': Sending state OFF
[13:24:36][D][binary_sensor:036]: 'Home': Sending state ON
[13:24:36][D][binary_sensor:036]: 'Home': Sending state OFF
[13:24:37][D][binary_sensor:036]: 'Home': Sending state ON
[13:24:37][D][binary_sensor:036]: 'Home': Sending state OFF
[13:24:37][D][binary_sensor:036]: 'Home': Sending state ON
[13:24:38][D][binary_sensor:036]: 'Home': Sending state OFF
[13:24:38][D][binary_sensor:036]: 'Home': Sending state ON
[13:24:38][D][binary_sensor:036]: 'Home': Sending state OFF
[13:24:39][D][binary_sensor:036]: 'Home': Sending state ON
[13:24:39][D][binary_sensor:036]: 'Home': Sending state OFF
[13:24:39][D][binary_sensor:036]: 'Home': Sending state ON
[13:24:40][D][binary_sensor:036]: 'Home': Sending state OFF
[13:24:40][D][binary_sensor:036]: 'Home': Sending state ON
[13:24:40][D][binary_sensor:036]: 'Home': Sending state OFF
[13:24:41][D][main:396]: Touchscreen:: Touched

Do you have any means to monitor the pin GIO3, somehow? I like to know how this pin behaves while you touch the screen.

@nielsnl68 I looked at the schematic for the board and there is a test pad for GPIO3 that's accessible. I probed it while using the device and it's high (3.3v) normally and when pressing the binary sensor, but as soon as the touchscreen is touched it drops low (0v) and stays there.

When the device is power cycled or reset then GPIO3 returns to high.

@clydebarrow let me know if there's any other tests you'd like me to try.

nielsnl68 commented 9 months ago

could you try this as external_components: https://github.com/esphome/esphome/pull/5997

This should have the fix.

cptskippy commented 9 months ago

could you try this as external_components: esphome/esphome#5997

I tried this:

external_components:
  - source: github://pr#5997
    components: [ tt21100 ]
    #components: [ touchscreen ]

And it fails to build:

Reading CMake configuration...
Dependency Graph
|-- noise-c @ 0.1.4
Compiling .pioenvs/voice-assistant-1/src/esphome/components/tt21100/touchscreen/tt21100.o
Compiling .pioenvs/voice-assistant-1/src/main.o
src/esphome/components/tt21100/touchscreen/tt21100.cpp: In member function 'virtual void esphome::tt21100::TT21100Touchscreen::setup()':
src/esphome/components/tt21100/touchscreen/tt21100.cpp:67:42: error: 'class esphome::display::Display' has no member named 'get_native_width'; did you mean 'get_width'?
       this->x_raw_max_ = this->display_->get_native_width();
                                          ^~~~~~~~~~~~~~~~
                                          get_width
src/esphome/components/tt21100/touchscreen/tt21100.cpp:70:42: error: 'class esphome::display::Display' has no member named 'get_native_height'; did you mean 'get_height'?
       this->x_raw_max_ = this->display_->get_native_height();
                                          ^~~~~~~~~~~~~~~~~
                                          get_height
*** [.pioenvs/voice-assistant-1/src/esphome/components/tt21100/touchscreen/tt21100.o] Error 1
========================= [FAILED] Took 47.80 seconds =========================
clydebarrow commented 9 months ago

As soon as you touch the touchscreen the on_touch event fires and then the tt21100 stops responding.

Try removing the interrupt pin definition. This will make it fall back to polling. Should hopefully work until a better fix comes along.

nielsnl68 commented 9 months ago

sorry you need to add:

external_components:
  - source: github://pr#5997
    components: [ display, touchscreen, tt21100 ]
woodshoes commented 9 months ago

Had the same problem compiling as cptskippy - If I do: external_components:

If I add all three like nielsnl68 says (display, touchscreen, tt21100) , it fails right away during compile.

INFO ESPHome 2023.12.9 INFO Reading configuration /config/esphome/flexdisplay.yaml... ERROR Unable to import component tt21100.binary_sensor: Traceback (most recent call last): File "/esphome/esphome/loader.py", line 169, in _lookup_module module = importlib.import_module(f"esphome.components.{domain}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/data/external_components/ea27d8aa/esphome/components/tt21100/binary_sensor/init.py", line 7, in from ..touchscreen import TT21100Touchscreen, TT21100ButtonListener File "/data/external_components/ea27d8aa/esphome/components/tt21100/touchscreen/init.py", line 5, in from esphome.components import i2c, touchscreen File "/data/external_components/ea27d8aa/esphome/components/touchscreen/init.py", line 7, in from esphome.const import ( ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py) ERROR Unable to import component touchscreen.binary_sensor: Traceback (most recent call last): File "/esphome/esphome/loader.py", line 169, in _lookup_module module = importlib.import_module(f"esphome.components.{domain}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1128, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/data/external_components/ea27d8aa/esphome/components/touchscreen/init.py", line 7, in from esphome.const import ( ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py) ERROR Unable to import component touchscreen.binary_sensor: Traceback (most recent call last): File "/esphome/esphome/loader.py", line 169, in _lookup_module module = importlib.import_module(f"esphome.components.{domain}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1128, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/data/external_components/ea27d8aa/esphome/components/touchscreen/init.py", line 7, in from esphome.const import ( ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py) ERROR Unable to import component touchscreen.binary_sensor: Traceback (most recent call last): File "/esphome/esphome/loader.py", line 169, in _lookup_module module = importlib.import_module(f"esphome.components.{domain}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1128, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/data/external_components/ea27d8aa/esphome/components/touchscreen/init.py", line 7, in from esphome.const import ( ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py) ERROR Unable to import component touchscreen.binary_sensor: Traceback (most recent call last): File "/esphome/esphome/loader.py", line 169, in _lookup_module module = importlib.import_module(f"esphome.components.{domain}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1128, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/data/external_components/ea27d8aa/esphome/components/touchscreen/init.py", line 7, in from esphome.const import ( ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py) ERROR Unable to import component touchscreen.binary_sensor: Traceback (most recent call last): File "/esphome/esphome/loader.py", line 169, in _lookup_module module = importlib.import_module(f"esphome.components.{domain}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1128, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/data/external_components/ea27d8aa/esphome/components/touchscreen/init.py", line 7, in from esphome.const import ( ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py) ERROR Unable to import component touchscreen.binary_sensor: Traceback (most recent call last): File "/esphome/esphome/loader.py", line 169, in _lookup_module module = importlib.import_module(f"esphome.components.{domain}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1128, in _find_and_load_unlocked File "", line 241, in _call_with_frames_removed File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/data/external_components/ea27d8aa/esphome/components/touchscreen/init.py", line 7, in from esphome.const import ( ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py) ERROR Unable to import component touchscreen: Traceback (most recent call last): File "/esphome/esphome/loader.py", line 169, in _lookup_module module = importlib.import_module(f"esphome.components.{domain}") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1206, in _gcd_import File "", line 1178, in _find_and_load File "", line 1149, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/data/external_components/ea27d8aa/esphome/components/touchscreen/init.py", line 7, in from esphome.const import ( ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py) WARNING GPIO45 is a strapping PIN and should only be used for I/O with care. Attaching external pullup/down resistors to strapping pins can cause unexpected failures. See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins Failed config

binary_sensor.tt21100: [source :60]

Platform not found: 'binary_sensor.tt21100'. platform: tt21100 name: Home-Button index: 0 tt21100_id: my_touchscreen internal: False binary_sensor.touchscreen: [source :65]

Platform not found: 'binary_sensor.touchscreen'. platform: touchscreen name: FanLo x_min: 0 x_max: 105 y_min: 0 y_max: 80 binary_sensor.touchscreen: [source :71]

Platform not found: 'binary_sensor.touchscreen'. platform: touchscreen name: FanMed x_min: 106 x_max: 210 y_min: 0 y_max: 80 binary_sensor.touchscreen: [source :77]

Platform not found: 'binary_sensor.touchscreen'. platform: touchscreen name: FanHi x_min: 211 x_max: 320 y_min: 0 y_max: 80 binary_sensor.touchscreen: [source :83]

Platform not found: 'binary_sensor.touchscreen'. platform: touchscreen name: FanOff x_min: 106 x_max: 210 y_min: 81 y_max: 160 binary_sensor.touchscreen: [source :89]

Platform not found: 'binary_sensor.touchscreen'. platform: touchscreen name: Lamp x_min: 40 x_max: 140 y_min: 161 y_max: 240 binary_sensor.touchscreen: [source :95]

Platform not found: 'binary_sensor.touchscreen'. platform: touchscreen name: FanLight x_min: 180 x_max: 280 y_min: 161 y_max: 240 touchscreen: [source :148]

Component not found: touchscreen. platform: tt21100 id: my_touchscreen interrupt_pin: GPIO3

nielsnl68 commented 9 months ago

~can you give me the touchscreen part of your YAML? then i test it local (altrough i dont have a display with the tt21100 myself). But compiling should be okay. ~

nielsnl68 commented 9 months ago

Okay, just tested the PR with the Current version and found out that the PR has more changes that cant be loaded via the extended_components. (that a bummer) But i just updated the PR so it can be used with the current version.

cptskippy commented 9 months ago

@nielsnl68 I just tried building with the latest PR and it's not working for me but seems to be a different issue than @woodshoes.

INFO ESPHome 2023.12.9
INFO Reading configuration /config/esphome/voice-assistant-1.yaml...
ERROR Unable to import component touchscreen:
Traceback (most recent call last):
  File "/esphome/esphome/loader.py", line 169, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/data/external_components/ea27d8aa/esphome/components/touchscreen/__init__.py", line 7, in <module>
    from esphome.const import (
ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py)
ERROR Unable to import component tt21100.binary_sensor:
Traceback (most recent call last):
  File "/esphome/esphome/loader.py", line 169, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/data/external_components/ea27d8aa/esphome/components/tt21100/binary_sensor/__init__.py", line 7, in <module>
    from ..touchscreen import TT21100Touchscreen, TT21100ButtonListener
  File "/data/external_components/ea27d8aa/esphome/components/tt21100/touchscreen/__init__.py", line 5, in <module>
    from esphome.components import i2c, touchscreen
  File "/data/external_components/ea27d8aa/esphome/components/touchscreen/__init__.py", line 7, in <module>
    from esphome.const import (
ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py)
INFO Detected timezone 'America/Los_Angeles'
WARNING GPIO45 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
WARNING GPIO0 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
Failed config

touchscreen: [source <unicode string>:169]

  Component not found: touchscreen.
  - platform: tt21100
    address: 36
    interrupt_pin: GPIO3
    on_touch: 
      - logger.log: Touchscreen:: Touched
binary_sensor.tt21100: [source <unicode string>:316]

  Platform not found: 'binary_sensor.tt21100'.
  platform: tt21100
  name: Home
  index: 0
  on_press: 
    then: 
      - globals.set: 
          id: display_rotation
          value: !lambda |-
            return !id(display_rotation);
nielsnl68 commented 9 months ago

Can you do me a favor and add

external_components:
  - source: github://pr#5997
    components: [ display, touchscreen, tt21100 ]
    refresh: 0sec
cptskippy commented 9 months ago

Can you do me a favor and add

external_components:
  - source: github://pr#5997
    components: [ display, touchscreen, tt21100 ]
    refresh: 0sec

That allows it to compile, however it is still becoming unresponsive after one touch. Also it is now showing a touchscreen event in the log:

[12:11:47][D][touchscreen:114]: Touch status: 0/7: raw:( 160,  192) calc:(   0,    0)
[12:11:47][D][main:402]: Touchscreen:: Touched

This is my config:

## BEGIN - Touchscreen
external_components:
  - source: github://pr#5997
    components: [ display, touchscreen, tt21100 ]
    refresh: 0sec    

i2c:
  sda: GPIO8
  scl: GPIO18
  scan: true

touchscreen:
  - platform: tt21100
    address: 0x24
    interrupt_pin: GPIO3
    on_touch:
      - logger.log: "Touchscreen:: Touched"
    on_release:
      - logger.log: "Touchscreen:: Released"
## END - Touchscreen
cptskippy commented 9 months ago

Try removing the interrupt pin definition. This will make it fall back to polling. Should hopefully work until a better fix comes along.

@clydebarrow the yaml won't compile without the interrupt, it's required for the tt21100.

nielsnl68 commented 9 months ago

My excuses, i forget to change one place where the interrupt pin was expected to be there. Now it is checked for existence.

When you still get stuck after the first touch, do you have time to dig into it with me to see where it is hanging from? I do not own a S3box so it is hard to test for me local.

For now please recompile and set logging to verbose. to see what happens.

cptskippy commented 9 months ago

When you still get stuck after the first touch, do you have time to dig into it with me to see where it is hanging from?

I'm going on holiday this week but I'll do what I can until then.

I stripped down my yaml so that has the minimum functionality:

substitutions:
  device_name: voice-assistant-1
  device_verbose_name: "Voice Assistant 1"

  wifi_ssid: !secret wifi_ssid
  wifi_password: !secret wifi_password
  wifi_hotspot_password: !secret wifi_hotspot_password

  api_encryption_key: !secret api_encryption_key
  ota_password: !secret ota_password

packages:
  device: !include templates/esp32.s3.template.yaml
  base: !include templates/wifi.template.yaml

logger:
  level: VERBOSE

psram:
  mode: octal
  speed: 80MHz

external_components:
  - source: github://pr#5997
    components: [ display, touchscreen, tt21100 ]
    refresh: 0sec

## BEGIN - Touchscreen
i2c:
  sda: GPIO8
  scl: GPIO18
  scan: true

touchscreen:
  - platform: tt21100
    address: 0x24
    interrupt_pin: GPIO3
    #reset_pin: GPIO48
    on_touch:
      - logger.log: "Touchscreen:: Touched"
    on_release:
      - logger.log: "Touchscreen:: Released"
## END - Touchscreen

## BEGIN - LCD Backlight
output:
  - platform: ledc
    id: gpio_45
    pin: GPIO45

light:
  - platform: monochromatic
    name: "LCD Backlight"
    id: lcd_backlight
    output: gpio_45
    restore_mode: ALWAYS_ON
    disabled_by_default: true
    default_transition_length: 0s
## END - LCD Backlight

## BEGIN - LCD
spi:
  clk_pin: GPIO7
  mosi_pin: GPIO6

display:
  - platform: ili9xxx
    id: lcd
    model: s3box
    cs_pin: GPIO5
    dc_pin: GPIO4
    reset_pin: GPIO48
    update_interval: never
    lambda: |-
      // Draw a line from [0,0] to [100,50]
      it.line(0, 0, 319, 239);
## END - LCD

binary_sensor:
  - platform: gpio
    id: settings
    name: "Settings"
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: true
    on_press:
      - logger.log: "Settings:: Pressed"
    on_release:
      - logger.log: "Settings:: Released"

  - platform: tt21100
    name: "Home"
    index: 0
    on_press:
      - logger.log: "Home:: Touched"
    on_release:
      - logger.log: "Home:: Released"

Here's what the verbose logging output. In this case I touched "Home" button 10 times, then the touchscreen itself 10 times, the "Home" button 10 more times, and then finally the "Settings" button.

INFO Upload took 2.86 seconds, waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from [redacted] using esphome API
INFO Successfully connected to voice-assistant-1 @ [redacted] in 7.227s
INFO Successful handshake with voice-assistant-1 @ [redacted] in 0.082s
[10:43:34][I][app:102]: ESPHome version 2023.12.9 compiled on Jan 29 2024, 10:39:39
[10:43:34][C][wifi:573]: WiFi:
[10:43:34][C][wifi:405]:   Local MAC: [redacted]
[10:43:34][C][wifi:410]:   SSID: [redacted]
[10:43:34][C][wifi:411]:   IP Address: [redacted]
[10:43:34][C][wifi:413]:   BSSID: [redacted]
[10:43:34][C][wifi:414]:   Hostname: 'voice-assistant-1'
[10:43:34][C][wifi:416]:   Signal strength: -41 dB ▂▄▆█
[10:43:34][V][wifi:418]:   Priority: 0.0
[10:43:34][C][wifi:420]:   Channel: 6
[10:43:34][C][wifi:421]:   Subnet: [redacted]
[10:43:34][C][wifi:422]:   Gateway: [redacted]
[10:43:34][C][wifi:423]:   DNS1: [redacted]
[10:43:34][C][wifi:424]:   DNS2: [redacted]
[10:43:34][C][logger:439]: Logger:
[10:43:34][C][logger:440]:   Level: VERBOSE
[10:43:34][C][logger:441]:   Log Baud Rate: 0
[10:43:34][C][logger:443]:   Hardware UART: USB_SERIAL_JTAG
[10:43:34][C][i2c.idf:061]: I2C Bus:
[10:43:34][C][i2c.idf:062]:   SDA Pin: GPIO8
[10:43:34][C][i2c.idf:063]:   SCL Pin: GPIO18
[10:43:34][C][i2c.idf:064]:   Frequency: 50000 Hz
[10:43:35][C][i2c.idf:067]:   Recovery: bus successfully recovered
[10:43:35][I][i2c.idf:077]: Results from i2c bus scan:
[10:43:35][I][i2c.idf:083]: Found i2c device at address 0x18
[10:43:35][I][i2c.idf:083]: Found i2c device at address 0x24
[10:43:35][I][i2c.idf:083]: Found i2c device at address 0x40
[10:43:35][I][i2c.idf:083]: Found i2c device at address 0x68
[10:43:35][C][spi:067]: SPI bus:
[10:43:35][C][spi:068]:   CLK Pin: GPIO7
[10:43:35][C][spi:069]:   SDI Pin: 
[10:43:35][C][spi:070]:   SDO Pin: GPIO6
[10:43:35][C][spi:072]:   Using HW SPI: SPI2_HOST
[10:43:35][C][ledc.output:164]: LEDC Output:
[10:43:35][C][ledc.output:165]:   Pin GPIO45
[10:43:35][C][ledc.output:166]:   LEDC Channel: 0
[10:43:35][C][ledc.output:167]:   PWM Frequency: 1000.0 Hz
[10:43:35][C][ledc.output:168]:   Bit depth: 14
[10:43:35][V][ledc.output:169]:   Max frequency for bit depth: 4882.812500
[10:43:35][V][ledc.output:171]:   Min frequency for bit depth: 76.298599
[10:43:35][V][ledc.output:172]:   Max frequency for bit depth-1: 9765.625000
[10:43:35][V][ledc.output:174]:   Min frequency for bit depth-1: 152.597198
[10:43:35][V][ledc.output:175]:   Max frequency for bit depth+1: 2441.406250
[10:43:35][V][ledc.output:177]:   Min frequency for bit depth+1: 38.149300
[10:43:35][V][ledc.output:178]:   Max res bits: 14
[10:43:35][V][ledc.output:179]:   Clock frequency: 80000000.000000
[10:43:35][C][ili9xxx:069]: ili9xxx
[10:43:35][C][ili9xxx:069]:   Rotations: 0 °
[10:43:35][C][ili9xxx:069]:   Dimensions: 320px x 240px
[10:43:35][C][ili9xxx:070]:   Width Offset: 0
[10:43:35][C][ili9xxx:071]:   Height Offset: 0
[10:43:35][C][ili9xxx:077]:   Color mode: 16bit
[10:43:35][C][ili9xxx:086]:   Data rate: 40MHz
[10:43:35][C][ili9xxx:088]:   Reset Pin: GPIO48
[10:43:35][C][ili9xxx:089]:   CS Pin: GPIO5
[10:43:35][C][ili9xxx:090]:   DC Pin: GPIO4
[10:43:35][C][ili9xxx:092]:   Swap_xy: NO
[10:43:35][C][ili9xxx:093]:   Mirror_x: YES
[10:43:35][C][ili9xxx:094]:   Mirror_y: YES
[10:43:35][C][ili9xxx:099]:   Update Interval: never
[10:43:35][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Settings'
[10:43:35][C][gpio.binary_sensor:016]:   Pin: GPIO0
[10:43:35][C][tt21100:138]: TT21100 Touchscreen:
[10:43:35][C][tt21100:139]:   Address: 0x24
[10:43:35][C][tt21100:140]:   Interrupt Pin: GPIO3
[10:43:35][C][light:103]: Light 'LCD Backlight'
[10:43:35][C][light:105]:   Default Transition Length: 0.0s
[10:43:35][C][light:106]:   Gamma Correct: 2.80
[10:43:35][C][psram:020]: PSRAM:
[10:43:35][C][psram:021]:   Available: YES
[10:43:35][C][psram:024]:   Size: 8191 KB
[10:43:35][C][tt21100.binary_sensor:015]: TT21100 Button 'Home'
[10:43:35][C][tt21100.binary_sensor:016]:   Index: 0
[10:43:35][C][captive_portal:088]: Captive Portal:
[10:43:35][C][mdns:115]: mDNS:
[10:43:35][C][mdns:116]:   Hostname: voice-assistant-1
[10:43:35][V][mdns:117]:   Services:
[10:43:35][V][mdns:119]:   - _esphomelib, _tcp, 6053
[10:43:35][V][mdns:121]:     TXT: version = 2023.12.9
[10:43:35][V][mdns:121]:     TXT: mac = [redacted]
[10:43:35][V][mdns:121]:     TXT: platform = ESP32
[10:43:35][V][mdns:121]:     TXT: board = esp32s3box
[10:43:35][V][mdns:121]:     TXT: network = wifi
[10:43:35][V][mdns:121]:     TXT: api_encryption = Noise_NNpsk0_25519_ChaChaPoly_SHA256
[10:43:35][C][ota:097]: Over-The-Air Updates:
[10:43:35][C][ota:098]:   Address: voice-assistant-1.local:3232
[10:43:35][C][ota:101]:   Using Password.
[10:43:35][C][api:139]: API Server:
[10:43:35][C][api:140]:   Address: voice-assistant-1.local:6053
[10:43:35][C][api:142]:   Using noise encryption: YES
[10:45:03][V][tt21100:095]: Button report: Len=14, ID=3, Time=32309, Value=[1], Signal=[00ED][0000][0000][0000]
[10:45:03][D][binary_sensor:036]: 'Home': Sending state ON
[10:45:03][D][main:196]: Home:: Touched
[10:45:03][V][tt21100:095]: Button report: Len=14, ID=3, Time=32559, Value=[0], Signal=[0000][0000][0000][0000]
[10:45:03][D][binary_sensor:036]: 'Home': Sending state OFF
[10:45:03][D][main:202]: Home:: Released
[10:45:04][V][tt21100:095]: Button report: Len=14, ID=3, Time=33560, Value=[1], Signal=[009A][0000][0000][0000]
[10:45:04][D][binary_sensor:036]: 'Home': Sending state ON
[10:45:04][D][main:196]: Home:: Touched
[10:45:04][V][tt21100:095]: Button report: Len=14, ID=3, Time=33660, Value=[0], Signal=[0000][0000][0000][0000]
[10:45:04][D][binary_sensor:036]: 'Home': Sending state OFF
[10:45:04][D][main:202]: Home:: Released
[10:45:05][V][tt21100:095]: Button report: Len=14, ID=3, Time=34711, Value=[1], Signal=[0081][0000][0000][0000]
[10:45:05][D][binary_sensor:036]: 'Home': Sending state ON
[10:45:05][D][main:196]: Home:: Touched
[10:45:05][V][tt21100:095]: Button report: Len=14, ID=3, Time=34811, Value=[0], Signal=[0000][0000][0000][0000]
[10:45:05][D][binary_sensor:036]: 'Home': Sending state OFF
[10:45:05][D][main:202]: Home:: Released
[10:45:07][V][tt21100:095]: Button report: Len=14, ID=3, Time=36813, Value=[1], Signal=[011B][0000][0000][0000]
[10:45:07][D][binary_sensor:036]: 'Home': Sending state ON
[10:45:07][D][main:196]: Home:: Touched
[10:45:07][V][tt21100:095]: Button report: Len=14, ID=3, Time=36913, Value=[0], Signal=[0000][0000][0000][0000]
[10:45:07][D][binary_sensor:036]: 'Home': Sending state OFF
[10:45:07][D][main:202]: Home:: Released
[10:45:08][V][tt21100:095]: Button report: Len=14, ID=3, Time=37513, Value=[1], Signal=[00B3][0000][0000][0000]
[10:45:08][D][binary_sensor:036]: 'Home': Sending state ON
[10:45:08][D][main:196]: Home:: Touched
[10:45:08][V][tt21100:095]: Button report: Len=14, ID=3, Time=37663, Value=[0], Signal=[0000][0000][0000][0000]
[10:45:08][D][binary_sensor:036]: 'Home': Sending state OFF
[10:45:08][D][main:202]: Home:: Released
[10:45:08][V][tt21100:095]: Button report: Len=14, ID=3, Time=38214, Value=[1], Signal=[0068][0000][0000][0000]
[10:45:08][D][binary_sensor:036]: 'Home': Sending state ON
[10:45:08][D][main:196]: Home:: Touched
[10:45:09][V][tt21100:095]: Button report: Len=14, ID=3, Time=38364, Value=[0], Signal=[0000][0000][0000][0000]
[10:45:09][D][binary_sensor:036]: 'Home': Sending state OFF
[10:45:09][D][main:202]: Home:: Released
[10:45:09][V][tt21100:095]: Button report: Len=14, ID=3, Time=39014, Value=[1], Signal=[00A5][0000][0000][0000]
[10:45:09][D][binary_sensor:036]: 'Home': Sending state ON
[10:45:09][D][main:196]: Home:: Touched
[10:45:09][V][tt21100:095]: Button report: Len=14, ID=3, Time=39114, Value=[0], Signal=[0000][0000][0000][0000]
[10:45:09][D][binary_sensor:036]: 'Home': Sending state OFF
[10:45:09][D][main:202]: Home:: Released
[10:45:10][V][tt21100:095]: Button report: Len=14, ID=3, Time=39515, Value=[1], Signal=[00DA][0000][0000][0000]
[10:45:10][D][binary_sensor:036]: 'Home': Sending state ON
[10:45:10][D][main:196]: Home:: Touched
[10:45:10][V][tt21100:095]: Button report: Len=14, ID=3, Time=39665, Value=[0], Signal=[0000][0000][0000][0000]
[10:45:10][D][binary_sensor:036]: 'Home': Sending state OFF
[10:45:10][D][main:202]: Home:: Released
[10:45:10][V][tt21100:095]: Button report: Len=14, ID=3, Time=39965, Value=[1], Signal=[00B4][0000][0000][0000]
[10:45:10][D][binary_sensor:036]: 'Home': Sending state ON
[10:45:10][D][main:196]: Home:: Touched
[10:45:10][V][tt21100:095]: Button report: Len=14, ID=3, Time=40115, Value=[0], Signal=[0000][0000][0000][0000]
[10:45:10][D][binary_sensor:036]: 'Home': Sending state OFF
[10:45:10][D][main:202]: Home:: Released
[10:45:11][V][tt21100:095]: Button report: Len=14, ID=3, Time=40465, Value=[1], Signal=[012B][0000][0000][0000]
[10:45:11][D][binary_sensor:036]: 'Home': Sending state ON
[10:45:11][D][main:196]: Home:: Touched
[10:45:11][V][tt21100:095]: Button report: Len=14, ID=3, Time=40565, Value=[0], Signal=[0000][0000][0000][0000]
[10:45:11][D][binary_sensor:036]: 'Home': Sending state OFF
[10:45:11][D][main:202]: Home:: Released
[10:45:12][V][tt21100:109]: Touch report: Len=17, ID=1, Time=41478, LargeObject=0, RecordNum=0, RecordCounter=0, NoiseEffect=2
[10:45:12][V][tt21100:120]: Touch 0: Type=0, Tip=0, EventId=0, TouchId=20, X=146, Y=132, Pressure=24, MajorAxisLen=0, Orientation=0
[10:45:12][D][touchscreen:114]: Touch status: 0/7: raw:( 146,  132) calc:(   0,    0)
[10:45:12][D][main:218]: Touchscreen:: Touched
[10:45:33][D][binary_sensor:036]: 'Settings': Sending state ON
[10:45:33][D][main:144]: Settings:: Pressed
[10:45:33][D][binary_sensor:036]: 'Settings': Sending state OFF
[10:45:33][D][main:150]: Settings:: Released

As soon as the on_touch event fires the TT21100 Touchscreen becomes unresponsive and doesn't report any further events. However the "Settings" button demonstrates that the device is still functioning.

nielsnl68 commented 9 months ago

@woodshoes , can you tell what is going one with this repeat repaid of the following section? Is that you doing or is this something executed by the tt21100?

nielsnl68 commented 9 months ago

As @clydebarrow already suggested earlier. Please disable the "interupt_pin" for now. And connect pin gpo3 to the a bineary_sensor: so we can monitor that pin for later use.

and update your testscript with:

substitutions:
  device_name: voice-assistant-1
  device_verbose_name: "Voice Assistant 1"

  wifi_ssid: !secret wifi_ssid
  wifi_password: !secret wifi_password
  wifi_hotspot_password: !secret wifi_hotspot_password

  api_encryption_key: !secret api_encryption_key
  ota_password: !secret ota_password

packages:
  device: !include templates/esp32.s3.template.yaml
  base: !include templates/wifi.template.yaml

logger:
  level: VERBOSE

psram:
  mode: octal
  speed: 80MHz

external_components:
  - source: github://nielsnl68/esphome#nvds-t2119-fix2
    components: [ display, touchscreen, tt21100 ]
    refresh: 0sec

## BEGIN - Touchscreen
i2c:
  sda: GPIO8
  scl: GPIO18
  scan: false

touchscreen:
  - platform: tt21100
  - update_interval: 50ms
    address: 0x24
    # interrupt_pin: GPIO3
    # reset_pin: GPIO48
    on_touch:
      - logger.log: "Touchscreen:: Touched"
    on_release:
      - logger.log: "Touchscreen:: Released"
## END - Touchscreen

## BEGIN - LCD Backlight
output:
  - platform: ledc
    id: gpio_45
    pin: GPIO45

light:
  - platform: monochromatic
    name: "LCD Backlight"
    id: lcd_backlight
    output: gpio_45
    restore_mode: ALWAYS_ON
    disabled_by_default: true
    default_transition_length: 0s
## END - LCD Backlight

## BEGIN - LCD
spi:
  clk_pin: GPIO7
  mosi_pin: GPIO6

display:
  - platform: ili9xxx
    id: lcd
    model: s3box
    cs_pin: GPIO5
    dc_pin: GPIO4
    reset_pin: GPIO48
    update_interval: never
    lambda: |-
      // Draw a line from [0,0] to [100,50]
      it.line(0, 0, 319, 239);
## END - LCD

binary_sensor:
  - platform: gpio
    id: settings
    name: "interupt pin"
    pin:
      number: GPIO3
      mode: INPUT_PULLUP
      inverted: true

  - platform: tt21100
    name: "Home_button"
    index: 0
    on_press:
      - logger.log: "Home:: Touched"
    on_release:
      - logger.log: "Home:: Released"
cptskippy commented 9 months ago

@nielsnl68 there's an issue with that branch preventing compilation:

INFO ESPHome 2023.12.9
INFO Reading configuration /config/esphome/voice-assistant-1.yaml...
INFO Updating https://github.com/nielsnl68/esphome.git@None
ERROR Unable to import component touchscreen:
Traceback (most recent call last):
  File "/esphome/esphome/loader.py", line 169, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/data/external_components/e67b79ba/esphome/components/touchscreen/__init__.py", line 6, in <module>
    from esphome.const import (
ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py)
ERROR Unable to import component tt21100.binary_sensor:
Traceback (most recent call last):
  File "/esphome/esphome/loader.py", line 169, in _lookup_module
    module = importlib.import_module(f"esphome.components.{domain}")
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/data/external_components/e67b79ba/esphome/components/tt21100/binary_sensor/__init__.py", line 7, in <module>
    from ..touchscreen import TT21100Touchscreen, TT21100ButtonListener
  File "/data/external_components/e67b79ba/esphome/components/tt21100/touchscreen/__init__.py", line 5, in <module>
    from esphome.components import i2c, touchscreen
  File "/data/external_components/e67b79ba/esphome/components/touchscreen/__init__.py", line 6, in <module>
    from esphome.const import (
ImportError: cannot import name 'CONF_MIRROR_X' from 'esphome.const' (/esphome/esphome/const.py)
WARNING GPIO45 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
WARNING GPIO0 is a strapping PIN and should only be used for I/O with care.
Attaching external pullup/down resistors to strapping pins can cause unexpected failures.
See https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
Failed config

touchscreen: [source <unicode string>:36]

  Component not found: touchscreen.
  - platform: tt21100
    address: 36
    on_touch: 
      - logger.log: Touchscreen:: Touched
    on_release: 
      - logger.log: Touchscreen:: Released
binary_sensor.tt21100: [source <unicode string>:98]

  Platform not found: 'binary_sensor.tt21100'.
  platform: tt21100
  name: Home
  index: 0
  on_press: 
    - logger.log: Home:: Touched
  on_release: 
    - logger.log: Home:: Released

Using the PR 5997 branch and disabling the interrupt pin allows the screen to function. Here's an excerpt:

[06:11:29][V][tt21100:109]: Touch report: Len=17, ID=1, Time=19935, LargeObject=0, RecordNum=0, RecordCounter=0, NoiseEffect=2
[06:11:29][V][tt21100:120]: Touch 0: Type=0, Tip=0, EventId=0, TouchId=20, X=184, Y=148, Pressure=24, MajorAxisLen=0, Orientation=0
[06:11:29][D][touchscreen:114]: Touch status: 0/7: raw:( 184,  148) calc:(   0,    0)
[06:11:29][D][main:209]: Touchscreen:: Touched
[06:11:29][V][tt21100:109]: Touch report: Len=17, ID=1, Time=19941, LargeObject=0, RecordNum=0, RecordCounter=0, NoiseEffect=4
[06:11:29][V][tt21100:120]: Touch 0: Type=0, Tip=0, EventId=0, TouchId=24, X=184, Y=148, Pressure=24, MajorAxisLen=0, Orientation=0
[06:11:29][D][touchscreen:114]: Touch status: 0/7: raw:( 184,  148) calc:(   0,    0)
[06:11:29][V][tt21100:109]: Touch report: Len=17, ID=1, Time=19964, LargeObject=0, RecordNum=0, RecordCounter=0, NoiseEffect=6
[06:11:29][V][tt21100:120]: Touch 0: Type=0, Tip=0, EventId=0, TouchId=24, X=184, Y=148, Pressure=24, MajorAxisLen=0, Orientation=0

...

[06:11:29][D][touchscreen:114]: Touch status: 0/7: raw:( 143,  160) calc:(   0,    0)
[06:11:29][V][tt21100:109]: Touch report: Len=17, ID=1, Time=20421, LargeObject=0, RecordNum=0, RecordCounter=0, NoiseEffect=0
[06:11:29][V][tt21100:120]: Touch 0: Type=0, Tip=0, EventId=0, TouchId=12, X=143, Y=160, Pressure=37, MajorAxisLen=0, Orientation=0
[06:11:29][D][touchscreen:114]: Touch status: 0/7: raw:( 143,  160) calc:(   0,    0)
[06:11:29][V][tt21100:109]: Touch report: Len=7, ID=1, Time=20471, LargeObject=0, RecordNum=0, RecordCounter=0, NoiseEffect=2
[06:11:29][D][touchscreen:114]: Touch status: 0/0: raw:( 143,  160) calc:(   0,    0)
[06:11:29][D][main:214]: Touchscreen:: Released

The on_touch and on_release events are firing and it continues to work after multiple touches.

And connect pin gpo3 to the a bineary_sensor: so we can monitor that pin for later use.

I'll try to find some time to disassemble the box so I can solder a wire to the test pad. I was just using a probe and holding it precariously to test previously.

nielsnl68 commented 9 months ago

I see that i made a type while creating the branch Instead of making it nvds-tt21100 i made it nvds-t2119-fix2**

I updated the YAML example above.

nielsnl68 commented 9 months ago

not sure why yet but it seams that the display width and height are not taken over from the display settings. could you add:

calibration:
   x_min: 0
   y_min: 0
   x: max: "display_width_value"
   y_max:  "display_heigtj_value"

You need to replace : "display_width_value", "display_height_value" that you use with this display.

tommck commented 9 months ago

@nielsnl68 if you need me to test things while @cptskippy is on holiday, let me know. I have an ESP32-S3-BOX that I can test this with.

nielsnl68 commented 9 months ago

@nielsnl68 if you need me to test things while @cptskippy is on holiday, let me know. I have an ESP32-S3-BOX that I can test this with.

Thanks. can you replicate @cptskippy issue?

tommck commented 9 months ago

I'm trying to figure out the entire file contents I need to have in my YAML. Can you post all of what you want me to test?

tommck commented 9 months ago

I don't have these 3 secrets... are they needed?

wifi_hotspot_password: !secret wifi_hotspot_password
api_encryption_key: !secret api_encryption_key
ota_password: !secret ota_password
tommck commented 9 months ago

I'm also getting errors reading the packages

  device: !include templates/esp32.s3.template.yaml
  base: !include templates/wifi.template.yaml
tommck commented 9 months ago

@nielsnl68 by the way, the screen is 320x240 pixels in case you needed to know that for the display calibration

Lots of specs here: https://github.com/espressif/esp-box/blob/v0.5.0/docs/hardware_overview/esp32_s3_box/hardware_overview_for_box.md

nielsnl68 commented 9 months ago

The only part you need is the "touchscreen" part the other stuff you can use the default parts you use in other esphome devices,

nielsnl68 commented 9 months ago

i should have said: "The only parts you need are the "display" and "touchscreen" parts ... "

tommck commented 9 months ago

Right now I have this and it complains about the touchscreen component not being found ("Component not found: touchscreen. ". I'm pretty new at this, so forgive any ignorance:

---
substitutions:
  name: esp32-s3-box
  friendly_name: ESP32 S3 Box

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: true
  platformio_options:
    board_build.flash_mode: dio
  min_version: 2023.11.5

esp32:
  board: esp32s3box
  flash_size: 16MB
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
      CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
      CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"

psram:
  mode: octal
  speed: 80MHz

external_components:
  - source: github://nielsnl68/esphome#nvds-t2119-fix2
    components: [ display, touchscreen, tt21100 ]
    refresh: 0sec

spi:
  clk_pin: 7
  mosi_pin: 6

display:
  - platform: ili9xxx
    id: s3_box_lcd
    model: S3BOX
    data_rate: 40MHz
    cs_pin: 5
    dc_pin: 4
    reset_pin: 48
    update_interval: never

## BEGIN - Touchscreen
i2c:
  sda: GPIO8
  scl: GPIO18
  scan: false

touchscreen:
  - platform: tt21100
    update_interval: 50ms
    address: 0x24
    interrupt_pin: GPIO3
    # reset_pin: GPIO48
    on_touch:
      - logger.log: "Touchscreen:: Touched"
    on_release:
      - logger.log: "Touchscreen:: Released"

## END - Touchscreen
tommck commented 9 months ago

Ahh.. the URL was supposed to have an @, not # in it... github://nielsnl68/esphome@nvds-t2119-fix2

tommck commented 9 months ago

@nielsnl68 I got it loaded finally. I touch it and it only responds the first time :(

tommck commented 9 months ago

This is my current setup:

---
substitutions:
  name: esp32-s3-box
  friendly_name: ESP32 S3 Box
  loading_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/loading_320_240.png
  idle_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/idle_320_240.png
  listening_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/listening_320_240.png
  thinking_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/thinking_320_240.png
  replying_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/replying_320_240.png
  error_illustration_file: https://github.com/esphome/firmware/raw/main/voice-assistant/casita/error_320_240.png

  loading_illustration_background_color: '000000'
  idle_illustration_background_color: '000000'
  listening_illustration_background_color: 'FFFFFF'
  thinking_illustration_background_color: 'FFFFFF'
  replying_illustration_background_color: 'FFFFFF'
  error_illustration_background_color: '000000'

  voice_assist_idle_phase_id: '1'
  voice_assist_listening_phase_id: '2'
  voice_assist_thinking_phase_id: '3'
  voice_assist_replying_phase_id: '4'
  voice_assist_not_ready_phase_id: '10'
  voice_assist_error_phase_id: '11'  
  voice_assist_muted_phase_id: '12'

esphome:
  name: ${name}
  friendly_name: ${friendly_name}
  name_add_mac_suffix: true
  project:
    name: esphome.voice-assistant
    version: "1.0"
  platformio_options:
    board_build.flash_mode: dio
  min_version: 2023.11.5
  on_boot:
      priority: 600
      then: 
        - script.execute: draw_display
        - delay: 30s
        - if:
            condition:
              lambda: return id(init_in_progress);
            then:
              - lambda: id(init_in_progress) = false;
              - script.execute: draw_display

esp32:
  board: esp32s3box
  flash_size: 16MB
  framework:
    type: esp-idf
    sdkconfig_options:
      CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: "y"
      CONFIG_ESP32S3_DATA_CACHE_64KB: "y"
      CONFIG_ESP32S3_DATA_CACHE_LINE_64B: "y"

psram:
  mode: octal
  speed: 80MHz

external_components:
  - source: github://pr#5230
    components: esp_adf
    refresh: 0s
  - source: github://nielsnl68/esphome@nvds-t2119-fix2
    components: [ display, touchscreen, tt21100 ]
    refresh: 0sec

api:
  on_client_connected:
    - script.execute: draw_display
  on_client_disconnected:
    - script.execute: draw_display

ota:
logger:
  hardware_uart: USB_SERIAL_JTAG

dashboard_import:
  package_import_url: github://esphome/firmware/voice-assistant/esp32-s3-box.yaml@main

wifi:
  ap:
  on_connect:
    - script.execute: draw_display
    - delay: 5s # Gives time for improv results to be transmitted 
    - ble.disable:  
  on_disconnect:
    - script.execute: draw_display
    - ble.enable:

improv_serial:

esp32_improv:
  authorizer: none

button:
  - platform: factory_reset
    id: factory_reset_btn
    name: Factory reset

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO1
      inverted: true
    name: "Mute"
    disabled_by_default: true
    entity_category: diagnostic

  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: true
    name: Top Left Button
    disabled_by_default: true
    entity_category: diagnostic
    on_multi_click:
      - timing:
          - ON for at least 10s
        then:
          - button.press: factory_reset_btn

output:
  - platform: ledc
    pin: GPIO45
    id: backlight_output

light:
  - platform: monochromatic
    id: led
    name: LCD Backlight
    entity_category: config
    output: backlight_output
    restore_mode: RESTORE_DEFAULT_ON
    default_transition_length: 250ms

esp_adf:

microphone:
  - platform: esp_adf
    id: box_mic

speaker:
  - platform: esp_adf
    id: box_speaker

voice_assistant:
  id: va
  microphone: box_mic
  speaker: box_speaker
  use_wake_word: true
  noise_suppression_level: 2
  auto_gain: 31dBFS
  volume_multiplier: 2.0
  vad_threshold: 3
  on_listening:
    - lambda: id(voice_assistant_phase) = ${voice_assist_listening_phase_id};
    - script.execute: draw_display
  on_stt_vad_end:
    - lambda: id(voice_assistant_phase) = ${voice_assist_thinking_phase_id};
    - script.execute: draw_display
  on_tts_stream_start:
    - lambda: id(voice_assistant_phase) = ${voice_assist_replying_phase_id};
    - script.execute: draw_display
  on_tts_stream_end:
    - lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
    - script.execute: draw_display
  on_error:
    - if:
        condition:
          lambda: return !id(init_in_progress);
        then:
          - lambda: id(voice_assistant_phase) = ${voice_assist_error_phase_id};  
          - script.execute: draw_display
          - delay: 1s
          - if:
              condition:
                switch.is_off: mute
              then:
                - lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
              else:
                - lambda: id(voice_assistant_phase) = ${voice_assist_muted_phase_id};
          - script.execute: draw_display
  on_client_connected: 
    - if:
        condition:
          switch.is_off: mute
        then:
          - wait_until:
              not: ble.enabled
          - voice_assistant.start_continuous:
          - lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
        else:
          - lambda: id(voice_assistant_phase) = ${voice_assist_muted_phase_id};
    - lambda: id(init_in_progress) = false; 
    - script.execute: draw_display
  on_client_disconnected:
    - lambda: id(voice_assistant_phase) = ${voice_assist_not_ready_phase_id};  
    - script.execute: draw_display

script:
  - id: draw_display
    then:
      - if:
          condition:
            lambda: return !id(init_in_progress);
          then:
            - if:
                condition:
                  wifi.connected:
                then:
                  - if:
                      condition:
                        api.connected:
                      then:
                        - lambda: |
                            switch(id(voice_assistant_phase)) {
                              case ${voice_assist_listening_phase_id}:
                                id(s3_box_lcd).show_page(listening_page);
                                id(s3_box_lcd).update();
                                break;
                              case ${voice_assist_thinking_phase_id}:
                                id(s3_box_lcd).show_page(thinking_page);
                                id(s3_box_lcd).update();
                                break;
                              case ${voice_assist_replying_phase_id}:
                                id(s3_box_lcd).show_page(replying_page);
                                id(s3_box_lcd).update();
                                break;
                              case ${voice_assist_error_phase_id}:
                                id(s3_box_lcd).show_page(error_page);
                                id(s3_box_lcd).update();
                                break;
                              case ${voice_assist_muted_phase_id}:
                                id(s3_box_lcd).show_page(muted_page);
                                id(s3_box_lcd).update();
                                break;
                              case ${voice_assist_not_ready_phase_id}:
                                id(s3_box_lcd).show_page(no_ha_page);
                                id(s3_box_lcd).update();
                                break;
                              default:
                                id(s3_box_lcd).show_page(idle_page);
                                id(s3_box_lcd).update();
                            }
                      else:
                        - display.page.show: no_ha_page
                        - component.update: s3_box_lcd
                else:
                  - display.page.show: no_wifi_page
                  - component.update: s3_box_lcd
          else:
            - display.page.show: initializing_page
            - component.update: s3_box_lcd

switch:
  - platform: template
    name: Mute
    id: mute
    optimistic: true
    restore_mode: RESTORE_DEFAULT_OFF
    entity_category: config
    on_turn_off:
      - if:
          condition:
            lambda: return !id(init_in_progress);
          then:      
            - lambda: id(va).set_use_wake_word(true);
            - lambda: id(voice_assistant_phase) = ${voice_assist_idle_phase_id};
            - if:
                condition:
                  not:
                    - voice_assistant.is_running
                then:
                  - voice_assistant.start_continuous
            - script.execute: draw_display
    on_turn_on:
      - if:
          condition:
            lambda: return !id(init_in_progress);
          then:      
            - voice_assistant.stop
            - lambda: id(va).set_use_wake_word(false);
            - lambda: id(voice_assistant_phase) = ${voice_assist_muted_phase_id};
            - script.execute: draw_display

globals:
  - id: init_in_progress
    type: bool
    restore_value: no
    initial_value: 'true'
  - id: voice_assistant_phase
    type: int
    restore_value: no
    initial_value: ${voice_assist_not_ready_phase_id}

image:
  - file: ${error_illustration_file}
    id: casita_error
    resize: 320x240
    type: RGB24
    use_transparency: true
  - file: ${idle_illustration_file}
    id: casita_idle
    resize: 320x240
    type: RGB24
    use_transparency: true
  - file: ${listening_illustration_file}
    id: casita_listening
    resize: 320x240
    type: RGB24
    use_transparency: true
  - file: ${thinking_illustration_file}
    id: casita_thinking
    resize: 320x240
    type: RGB24
    use_transparency: true
  - file: ${replying_illustration_file}
    id: casita_replying
    resize: 320x240
    type: RGB24
    use_transparency: true
  - file: ${loading_illustration_file}
    id: casita_initializing
    resize: 320x240
    type: RGB24
    use_transparency: true
  - file: https://github.com/esphome/firmware/raw/main/voice-assistant/error_box_illustrations/error-no-wifi.png
    id: error_no_wifi
    resize: 320x240
    type: RGB24
    use_transparency: true
  - file: https://github.com/esphome/firmware/raw/main/voice-assistant/error_box_illustrations/error-no-ha.png
    id: error_no_ha
    resize: 320x240
    type: RGB24
    use_transparency: true

color:
  - id: idle_color
    hex: ${idle_illustration_background_color}
  - id: listening_color
    hex: ${listening_illustration_background_color}
  - id: thinking_color
    hex: ${thinking_illustration_background_color}
  - id: replying_color
    hex: ${replying_illustration_background_color}
  - id: loading_color
    hex: ${loading_illustration_background_color}
  - id: error_color
    hex: ${error_illustration_background_color}

spi:
  clk_pin: 7
  mosi_pin: 6

display:
  - platform: ili9xxx
    id: s3_box_lcd
    model: S3BOX
    data_rate: 40MHz
    cs_pin: 5
    dc_pin: 4
    reset_pin: 48
    update_interval: never
    pages:
      - id: idle_page
        lambda: |-
          it.fill(id(idle_color));
          it.image((it.get_width() / 2), (it.get_height() / 2), id(casita_idle), ImageAlign::CENTER);
      - id: listening_page
        lambda: |-
          it.fill(id(listening_color));
          it.image((it.get_width() / 2), (it.get_height() / 2), id(casita_listening), ImageAlign::CENTER);
      - id: thinking_page
        lambda: |-
          it.fill(id(thinking_color));
          it.image((it.get_width() / 2), (it.get_height() / 2), id(casita_thinking), ImageAlign::CENTER);
      - id: replying_page
        lambda: |-
          it.fill(id(replying_color));
          it.image((it.get_width() / 2), (it.get_height() / 2), id(casita_replying), ImageAlign::CENTER);
      - id: error_page
        lambda: |-
          it.fill(id(error_color));
          it.image((it.get_width() / 2), (it.get_height() / 2), id(casita_error), ImageAlign::CENTER);
      - id: no_ha_page
        lambda: |-
          it.image((it.get_width() / 2), (it.get_height() / 2), id(error_no_ha), ImageAlign::CENTER);
      - id: no_wifi_page
        lambda: |-
          it.image((it.get_width() / 2), (it.get_height() / 2), id(error_no_wifi), ImageAlign::CENTER);
      - id: initializing_page
        lambda: |-
          it.fill(id(loading_color));
          it.image((it.get_width() / 2), (it.get_height() / 2), id(casita_initializing), ImageAlign::CENTER);
      - id: muted_page
        lambda: |-
          it.fill(Color::BLACK);

## BEGIN - Touchscreen
i2c:
  sda: GPIO8
  scl: GPIO18
  scan: false

touchscreen:
  - platform: tt21100
    update_interval: 50ms
    address: 0x24
    interrupt_pin: GPIO3
    # reset_pin: GPIO48
    display: s3_box_lcd
    on_touch:
      - logger.log: "Touchscreen:: Touched"
    on_release:
      - logger.log: "Touchscreen:: Released"
## END - Touchscreen

It only spits out "touched" and no "released" message