ESPHome Update seems to have ruined my cheap yellow display

I recently purchased a cheap yellow display. Yesterday I was able to connect it to HA with a very basic program to toggle some switches. I updated esphome (it was maybe two months out of date) and now my code does not work. I am in a circle of errors that seem to do with my configuration. Chatgpt cant get me out of the issue.

My hardware is esp32 2432s028 https://www.aliexpress.com/item/1005005616073472.html

My code that worked was:

font:
  - file: 'fonts/Arimo-Regular.ttf'
    id: arimo96
    size: 96
    glyphs: "ABKL"

# Create a Home Assistant blue color
color:
  - id: ha_blue
    hex: 51c0f2

# ============================================================ 
# Home Assistant related setup
#
light:
  - platform: monochromatic
    output: backlight_pwm
    name: Display Backlight
    id: backlight
    restore_mode: ALWAYS_ON

# Setup two binary sensors for the two areas for touch


binary_sensor:
  - platform: touchscreen
    name: "Button A"  # This is what Home Assistant sees
    x_min: 20
    x_max: 140
    y_min: 60
    y_max: 180
    id: button_a
    on_press:
      - logger.log: "Button A pressed"

  - platform: touchscreen
    name: "Button B"
    x_min: 180
    x_max: 300
    y_min: 60
    y_max: 180
    id: button_b
    on_press:
      - logger.log: "Button B pressed"


# ============================================================ 
# Hardware related setup
#
# Setup SPI for the display. The ESP32-2432S028R uses separate SPI buses for display and touch
spi:
  - id: tft
    clk_pin: GPIO14
    mosi_pin: GPIO13
    miso_pin: GPIO12
  - id: touch
    clk_pin: GPIO25
    mosi_pin: GPIO32
    miso_pin: GPIO39

# Setup a pin to control the backlight
output:
  - platform: ledc
    pin: GPIO21
    id: backlight_pwm
display:
  - platform: ili9xxx
    model: ili9342
    spi_id: tft
    cs_pin: GPIO15
    dc_pin: GPIO2
    invert_colors: true
    #rotation: 90
    lambda: |-
      it.fill(id(Color::BLACK));
      it.filled_rectangle(20, 60, 120, 120, id(ha_blue));
      it.filled_rectangle(180, 60, 120, 120, id(ha_blue));
      it.print(80, 120, id(arimo96), TextAlign::CENTER, "K");
      it.print(240, 120, id(arimo96), TextAlign::CENTER, "L");

touchscreen:
  platform: xpt2046
  spi_id: touch
  cs_pin: GPIO33
  interrupt_pin: GPIO36
  update_interval: 50ms
  threshold: 400
  calibration:
    x_min: 3860    # Flip X by swapping min and max
    x_max: 340     # Flip X by swapping min and max
    y_min: 3860    # Flip Y by swapping min and max
    y_max: 280     # Flip Y by swapping min and max
  transform:
    swap_xy: true  # Keep this to account for the original 90° rotation

The error I get is “x_min must be smaller than x_max. To mirror the direction use the ‘transform’ options.” But this code worked yesterday and when I fix this line it just seems to lead to another issue with my settings and on and on.

Any suggestions?

I cant get anything to work now with this display. I have tried doing very simple hello world code and I get endless complaints about my settings.

You could just try and do what the error message says.

x_min is larger than x_max.
And I believe the y_min and y_max also has to change

1 Like

Obviously then there is no hope left, sorry :frowning_face:

What? :astonished: Seriously? :person_shrugging:

It does appear to me some updates have broken a part of my code.

My code displays the letters a&b on the screen in landscape. It then waits for a tap signal. It looks like the touchscreen part of my code is in portrait. The old code did a transform on the input and that code worked. With the updates to esphome it seems this transform function no longer work. So, this code runs, but the touchscreen interprets the taps wrong.

I need to rotate the touchscreen inputs. I have tried several solutions.

captive_portal:
# ============================================================ 
# ESPHome Display related setup
#
# Create a font to use, add and remove glyphs as needed. 
font:
  - file: 'fonts/Arimo-Regular.ttf'
    id: arimo96
    size: 96
    glyphs: "AB"

# Create a Home Assistant blue color
color:
  - id: ha_blue
    hex: 51c0f2

# ============================================================ 
# Home Assistant related setup
#
light:
  - platform: monochromatic
    output: backlight_pwm
    name: Display Backlight
    id: backlight
    restore_mode: ALWAYS_ON

# Setup two binary sensors for the two areas for touch
binary_sensor:
  - platform: touchscreen
    name: Button A
    x_min: 20
    x_max: 140
    y_min: 60
    y_max: 180

  - platform: touchscreen
    name: Button B
    x_min: 180
    x_max: 300
    y_min: 60
    y_max: 180

# ============================================================ 
# Hardware related setup
#
# Setup SPI for the display. The ESP32-2432S028R uses separate SPI buses for display and touch
spi:
  - id: tft
    clk_pin: GPIO14
    mosi_pin: GPIO13
    miso_pin: GPIO12
  - id: touch
    clk_pin: GPIO25
    mosi_pin: GPIO32
    miso_pin: GPIO39

# Setup a pin to control the backlight
output:
  - platform: ledc
    pin: GPIO21
    id: backlight_pwm

# Setup the ili9xxx platform
#
# Display is used as 240x320 by default so we rotate it to 90°
#
# We print date and time wth the strftime() function, see the ESPHome documentation to 
# format date and atime to your locale.
#
display:
  - platform: ili9xxx
    id: esp_display
    model: ili9342
    spi_id: tft
    cs_pin: GPIO15
    dc_pin: GPIO2
    invert_colors: true
    lambda: |-
      it.fill(id(Color::BLACK));
      it.filled_rectangle(20, 60, 120, 120, id(ha_blue));
      it.filled_rectangle(180, 60, 120, 120, id(ha_blue));
      it.print(80, 120, id(arimo96), TextAlign::CENTER, "A");
      it.print(240, 120, id(arimo96), TextAlign::CENTER, "B");



touchscreen:
  platform: xpt2046
  spi_id: touch
  cs_pin: GPIO33
  interrupt_pin: GPIO36
  update_interval: 50ms
  threshold: 400
  calibration:
    x_min: 280      # Smaller value
    x_max: 3860     # Larger value
    y_min: 340      # Smaller value
    y_max: 3860     # Larger value
  transform:
    swap_xy: false  # Set to true if X and Y axes are swapped

Anyone interested. I am pretty convinced the recent esphome deprecated some functionality. I had a raft of errors to do with calibrating my screen. One issue I think I have is my screen is the one with USB c and mini. Anyway, after much slogging I was able to get some code working in esphome. I will share it here. I managed to get the screen and the touch area properly rotated.

globals:
  - id: wifi_iconstring
    type: std::string
    restore_value: no
    initial_value: '"󰤮"'
  - id: recent_touch
    type: bool
    restore_value: no
    initial_value: "true"

# Create a font to use, add and remove glyphs as needed
font:
  - file: 'fonts/materialdesignicons-webfont.ttf'
    id: mdi_large
    size: 48
    glyphs: [
        "󰗺",  # regular kettle icon
        "󱌙",  # steaming kettle icon
        "󰌵",  # regular light bulb icon
        "󰛨",  # light bulb icon when light is on
    ]
    
  - file: "fonts/materialdesignicons-webfont.ttf"
    id: mdi_medium
    size: 24
    glyphs: [
        "󰤮",  # no-wifi
        "󰤫",  # low-wifi
        "󰤟",  # wifi-1
        "󰤢",  # wifi-2
        "󰤥",  # wifi-3
        "󰤨",  # wifi-4
    ]

# Create a Home Assistant blue color
color:
  - id: ha_blue
    hex: 51c0f2  # Blue color (for off state)
  - id: ha_yellow
    hex: FFA500 # Yellow color (for on state)

# ============================================================ 
# Home Assistant related setup
#
light:
  - platform: monochromatic
    output: backlight_pwm
    name: Display Backlight
    id: backlight
    restore_mode: ALWAYS_ON
  - platform: rgb
    name: LED
    id: led
    red: output_red
    green: output_green
    blue: output_blue
    restore_mode: ALWAYS_OFF

# Binary sensors for touch
binary_sensor:
  - platform: touchscreen
    name: Light On
    x_min: 20
    x_max: 140
    y_min: 60
    y_max: 180

  - platform: touchscreen
    name: Light Off
    x_min: 180
    x_max: 300
    y_min: 60
    y_max: 180

# ============================================================ 
# Hardware related setup
#
# Setup SPI for the display. The ESP32-2432S028R uses separate SPI buses for display and touch
spi:
  - id: tft
    clk_pin: GPIO14
    mosi_pin: GPIO13
    miso_pin: GPIO12
  - id: touch
    clk_pin: GPIO25
    mosi_pin: GPIO32
    miso_pin: GPIO39

output:
  - platform: ledc
    pin: GPIO21
    id: backlight_pwm
  - platform: ledc
    id: output_red
    pin: GPIO4
    inverted: true
  - platform: ledc
    id: output_green
    pin: GPIO16
    inverted: true
  - platform: ledc
    id: output_blue
    pin: GPIO17
    inverted: true

script:
  - id: update_ui_values
    then:
      - lambda: |-
          if (isnan(id(wifi_signal_pct).state))
              id(wifi_iconstring) = "󰤮"; // No-wifi
          else if (id(wifi_signal_pct).state < 10)
              id(wifi_iconstring) = "󰤟";  // low-wifi
          else if (id(wifi_signal_pct).state < 30)
              id(wifi_iconstring) = "󰤟"; // wifi-1
          else if (id(wifi_signal_pct).state < 50)
              id(wifi_iconstring) = "󰤢"; // wifi-2
          else if (id(wifi_signal_pct).state < 75)
              id(wifi_iconstring) = "󰤥"; // wifi-3
          else
              id(wifi_iconstring) = "󰤨"; // wifi-4

interval:
  - interval: 10s
    then:
      - script.execute: update_ui_values

  - interval: 30s
    then:
      - if:
          condition:
            - lambda: |-
                return !id(recent_touch);
          then: 
            light.turn_off:
              id: backlight
          else:
            - lambda: |-
                id(recent_touch) = false;

switch:
  - platform: homeassistant
    name: "Kettle Switch"
    entity_id: switch.kettle_switch
    id: switch_kettle_switch

  - platform: homeassistant
    name: "USB Light Switch"
    entity_id: light.usb_light
    id: light_usb_light

display:
  - platform: ili9xxx
    model: ili9342
    spi_id: tft
    cs_pin: GPIO15
    dc_pin: GPIO2
    invert_colors: true
    rotation: 180
    lambda: |-
      it.fill(id(Color::BLACK));

      // Check the state of the kettle switch and set the icon
      if (id(switch_kettle_switch).state) {
        it.filled_circle(80, 120, 60, id(ha_yellow));  // Kettle is yellow when ON
        it.print(80, 120, id(mdi_large), TextAlign::CENTER, "󱌙"); // Steaming kettle icon
      } else {
        it.filled_circle(80, 120, 60, id(ha_blue));   // Kettle is blue when OFF
        it.print(80, 120, id(mdi_large), TextAlign::CENTER, "󰗺"); // Regular kettle icon
      }

      // Check the state of the light switch and set the icon
      if (id(light_usb_light).state) {
        it.filled_circle(240, 120, 60, id(ha_yellow));  // Light is yellow when ON
        it.print(240, 120, id(mdi_large), TextAlign::CENTER, "󰛨"); // Light bulb icon when ON
      } else {
        it.filled_circle(240, 120, 60, id(ha_blue));   // Light is blue when OFF
        it.print(240, 120, id(mdi_large), TextAlign::CENTER, "󰌵"); // Regular light bulb icon
      }

      // Draw the Wi-Fi icon
      it.print(296, 0, id(mdi_medium), id(wifi_iconstring).c_str());

touchscreen:
  platform: xpt2046
  spi_id: touch
  cs_pin: GPIO33
  interrupt_pin: GPIO36
  update_interval: 50ms
  threshold: 400
  calibration:
    x_min: 180
    x_max: 3000
    y_min: 240
    y_max: 3860
  transform:
    swap_xy: true

  on_touch:
    then:
      - light.turn_on: backlight
      - lambda: |-
          id(recent_touch) = true;
      - script.execute: update_ui_values

sensor:
  - platform: wifi_signal
    name: "WiFi Signal Percent"
    filters:
      - lambda: return min(max(2 * (x + 100.0), 0.0), 100.0);
    unit_of_measurement: "Signal %"
    id: wifi_signal_pct
    update_interval: 60s
    entity_category: "diagnostic"