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