ESPhome with ili9341

My goal is to make a touch screen thermostat with 3 or 4 touchscreen buttons.
it will display the temperature in the middle and plus and minus touchscreen buttons to turn up and down the heat. and have a button on the top left to turn off the heating.
i have the screen working and got the touchscreen calibrated properly.
but thats where the fun ends…
-i cant seem to figure out how to turn off the backlight.
(turn off after no touch for 30sec)
i tried with monochromatic light. but no success
i figured out how to dim it, i think.
-for some reason i have to invert all commands for the backlight so on is off and off is on.
-for some reason the esp32 keeps rebooting every couple minutes.

  • also i got to have restore_mode: ALWAYS_OFF otherwise i just have no backlight at all

  • cant seem to figure out how touch buttons work with the screen.

esphome:
  name: testdevice

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Testdevice Fallback Hotspot"
    password: ""

captive_portal:
# Example configuration entry
globals:
  - id: x
    type: int
    restore_value: no
    initial_value: '0'
  - id: y
    type: int
    restore_value: no
    initial_value: '0'
  - id: touched
    type: bool   
color:
  - id: my_red
    red: 100%
    green: 3%
    blue: 5%
image:
  - file: "test.jpg"
    id: test
    type: RGB24
font:
  - file: "fonts/ComicSansMS.ttf"
    id: my_font
    size: 50
# Example configuration entry
# Define a PWM output on the ESP32
# Define a PWM output on the ESP32
# Define a PWM output on the ESP32
output:
  - platform: ledc
    pin: 15
    id: gpio_15_backlight_pwm
  - platform: gpio
    pin: 15
    id: gpio_backlight_off
    inverted: yes
    
    
# Define a monochromatic, dimmable light for the backlight
light:
  - platform: monochromatic
    output: gpio_15_backlight_pwm
    name: "ILI9341 Display Backlight"
    id: back_light
    restore_mode: ALWAYS_OFF
    on_turn_off:
      then:
        - delay: 10s
        - light.turn_on:
            id: back_light
spi:
  clk_pin: GPIO18
  mosi_pin: GPIO23
  miso_pin: GPIO19
# Example minimal configuration entry
display:
  - platform: ili9341
    model: TFT 2.4
    cs_pin: 5
    dc_pin: 4
    reset_pin: 22
    led_pin:
      number: 15
      inverted: no
    auto_clear_enabled: true
    update_interval: 1s
    rotation: 270
    lambda: |-
      it.image(0, 0, id(test));
      it.print(165, 130, id(my_font), Color::BLACK, TextAlign::CENTER, "21 C");
      if (id(touchscreen).touched)
        it.filled_circle(id(touchscreen).x, id(touchscreen).y, 10, id(my_red));

#     auto call = id(back_light).turn_on();  Display OFF
#     call.perform();
# Example configuration entry
xpt2046:
  id: touchscreen
  cs_pin: 14
  irq_pin: 27
  update_interval: 50ms
  report_interval: 1s
  threshold: 400
  dimension_x: 320
  dimension_y: 240
  calibration_x_min: 280
  calibration_x_max: 3860
  calibration_y_min: 340
  calibration_y_max: 3860
  swap_x_y: yes
  on_state:
    - lambda: |-
        if (touched)
          ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%d",
              id(touchscreen).x,
              id(touchscreen).y,
              id(touchscreen).x_raw,
              id(touchscreen).y_raw
              );
          auto call = id(back_light).turn_off();
          call.perform();



The image is not exact tho some pins werent correct but it gives an idea

Have you considered OPENHASP?

Ow damn if it supports my display, ill be using that over coding every little detail haha.
I just have to be sure it works offline too.
so that if home assistant crashes my heating doesn’t go down.
its too vital to trust a raspberry pi with.

after looking into it, it seems like it needs a connection with HA

1 Like

How are you turning your heating on and off? I assume via a GPIO on the esp32?

In any event openHASP can work offline, but is a little limited in that case - see Handle Offline State - openHASP

Thinking about it, maybe the offline option for openhasp is not really what you want.

In esphome the xpt2046 touch controller is set up as a series of binary sensors. Each “button” is defined by screen co-ordinates. When you touch within those co-ordinates the binary sensor changes state, just like a binary sensor for a physical push button. You then use an on_press or on_release on on_click (or on_whatever) to trigger the device to do something (like turn the temp up, or down, or turn the heater off/on or whatever you like. See Binary Sensor Component — ESPHome

backlight. Why not invert your pin?

led_pin:
      number: 15
      inverted: yes

I have no problem on esp32 and ili9341 displays with ESPHome, and resetting/rebooting. I have several including one on my work desk that I use all the time. You should be able to watch the ESP logs and see what is triggering the reboot, but in my experience there’s nothing wrong in the system its going to be your hardware or code. I actually don’t have a working setup with touchscreen to try to repro this for you, but feel confident that this should all just work reliably

I assume that as we haven’t heard from the OP for some time, he has lost interest.

1 Like

very sorry for not replying here,
'lost interest" would not be true
i just gave up on the ili display and went with nextion instead.
this than led me into a rabbit hole and weeks of work haha.
the ili is just too much work for something that nextion can do way better (tho not as cheap)