I got AZ Touch up and running with Homeassistant and ESPHome.
You get a description, schematic an some sample applications here on zihatec.
With ESPHome i followed
ILI9341 TFT LCD
XPT2046 Touch Screen Controller
among other things.
esphome:
name: touchmod01
esp32:
board: esp-wrover-kit
framework:
type: arduino
…
The buzzer is connectet to GPIO21. Use it as rttl. Play a melody as described here.
output:
# buzzer
- platform: ledc
pin: GPIO21
id: rtttl_out
# component buzzer
rtttl:
output: rtttl_out
on_finished_playback:
- logger.log: 'Song ended!'
# to play from HA
api:
services:
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play:
rtttl: !lambda 'return song_str;'
Define fonts, images and colors
font:
- file: '/config/esphome/font/slkscr.ttf'
id: font1
size: 8
image:
# for this example the display is in portrait orientation.
# It is dividet into a 12 squares grid
# that is why the image is resized to 80x80
- file: "/config/esphome/img/steckdose-color.png"
id: steckdose
resize: 80x80
type: RGB24
color:
- id: my_red
red: 100%
green: 0%
Setup your display
In this case it is a 2.4" touch-display. Connected over SPI.
spi:
clk_pin: GPIO18
mosi_pin: GPIO23
miso_pin: GPIO19
Backlight is connected to GPIO15
Add to output section
output:
# backlight
- platform: ledc
pin: 15
id: gpio_15_backlight_pwm
inverted: true
and add a light for HA user interface
light:
# backlight for HA
- platform: monochromatic
output: gpio_15_backlight_pwm
name: "ILI9341 Display Backlight"
id: back_light
restore_mode: ALWAYS_ON
Now, set up the display itself
display:
- platform: ili9341
model: TFT 2.4
id: touch_display
cs_pin: GPIO5
dc_pin: GPIO4
# if backlight is not controlled by pwm uncomment this
#led_pin:
# number: 15
# inverted: true
reset_pin: GPIO22
# play a little,
# draw colors, text, images
# to show the state of an entity, change the color or write some text
# in this example the image ist swapped depend from my device
# extended_color_light_3
# it is imported later as binary sensor
lambda: |-
it.fill(COLOR_BLACK);
// it.print(0, 0, id(font1), id(my_red), TextAlign::TOP_LEFT, "Hello World!");
// it.fill(my_red);
// it.image( 80, 80, id(steckdose));
// it.image(160, 160, id(tablelamp), id(my_red), id(my_yellow));
if (id(extended_color_light_3).state) {
it.image( 80, 80, id(steckdose_on));
} else {
it.image( 80, 80, id(steckdose));
}
// 3 x 4 grid
it.line( 80, 0, 80, 319);
it.line(160, 0, 160, 319);
it.line( 0, 80, 239, 80);
it.line( 0, 160, 239, 160);
it.line( 0, 240, 239, 240);
Set up the touch screen
:
id: touchscreen
cs_pin: 14
irq_pin: 27
update_interval: 50ms
report_interval: 1s
threshold: 400
dimension_x: 240
dimension_y: 320
calibration_x_min: 3860
calibration_x_max: 280
calibration_y_min: 340
calibration_y_max: 3860
swap_x_y: false
Set the touch actions
# my screen is divided in to 12 squares
# there are 12 touch areas named as touch_key0 to touch_key11
binary_sensor:
- platform: xpt2046
xpt2046_id: touchscreen
id: touch_key0
x_min: 0
x_max: 79
y_min: 0
y_max: 79
on_press:
- logger.log: "Key0 was touched"
- platform: xpt2046
xpt2046_id: touchscreen
id: touch_key4
x_min: 80
x_max: 159
y_min: 80
y_max: 159
# some light should be toggled
on_state:
if:
condition:
binary_sensor.is_on: touch_key4
then:
- homeassistant.service:
service: light.toggle
data:
entity_id: light.extended_color_light_3
- platform: xpt2046
xpt2046_id: touchscreen
id: touch_key11
x_min: 160
x_max: 239
y_min: 240
y_max: 319
on_state:
- lambda: 'ESP_LOGI("main", "key11: %s", (x ? "touch" : "release"));'
To show the state of an entity, additionaly it has to be imported as binary sensor…
- platform: homeassistant
id: extended_color_light_3
entity_id: light.extended_color_light_3
internal: true
It works so far.