hello,
i have a lot of problem with touchscreen for a while, i buy 2 elecrow panel 7", the first screen i bought work normally whithout the i2c PCA stuff and script, the 2nd one doesnt work ass expected and i found that put a aluminium film at the back work when i touch it with a hand, and the screen xith other hand...i used it like that for month...
I then decided to buy 2 more, to see if its a hardware problem, but no luck, the 2 new 7" the touchscreen doesnt work.
6 month after i search a lot and found this post with the link to 7.0-V3.0esphome.yaml, try it and now my touchscreen work on my 4 elecrow 7" without any trouble!
here is my code :
esphome:
name: crowpanel7pouces
platformio_options:
build_flags: "-DBOARD_HAS_PSRAM"
board_build.esp-idf.memory_type: qio_opi
board_build.flash_mode: dio
on_boot:
- delay: 3s
- lvgl.widget.hide: boot_screen
esp32:
board: esp32-s3-devkitc-1
variant: esp32s3
framework:
type: esp-idf
#platform_version: 6.8.1
#version: 5.3.0
# Required to achieve sufficient PSRAM bandwidth
sdkconfig_options:
CONFIG_ESP32S3_DEFAULT_CPU_FREQ_240: y
CONFIG_ESP32S3_DATA_CACHE_64KB: y
CONFIG_ESP32S3_DATA_CACHE_LINE_64B: y
CONFIG_SPIRAM_FETCH_INSTRUCTIONS: y
CONFIG_SPIRAM_RODATA: y
# Enable logging
logger:
# Enable Home Assistant API
api:
on_client_connected:
- if:
condition:
lambda: 'return (0 == client_info.find("Home Assistant "));'
then:
- lvgl.widget.show: lbl_hastatus
- lvgl.widget.hide: top_layer
on_client_disconnected:
- if:
condition:
lambda: 'return (0 == client_info.find("Home Assistant "));'
then:
- lvgl.widget.hide: lbl_hastatus
ota:
- platform: esphome
password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx347"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_pwd
manual_ip:
static_ip: xxxxxxxxxx
gateway: xxxxxxxxxxxxxxx
subnet: 255.255.255.0
dns1: xxxxxxxxxx
fast_connect: on
power_save_mode: none
psram:
mode: octal
speed: 80MHz
# I2C bus configuration
i2c:
- id: i2c_bus
sda: GPIO19
scl: GPIO20
scan: true
# PCA9554 GPIO extender for display reset
pca9554:
- id: p_c_a
address: 0x20
i2c_id: i2c_bus
output:
- platform: ledc
pin: 2
frequency: 1220
id: gpio_backlight_pwm
light:
- platform: monochromatic
output: gpio_backlight_pwm
name: Huawei 7 pouces Display Backlight
id: back_light
restore_mode: ALWAYS_ON
touchscreen:
platform: gt911
id: my_touchscreen
i2c_id: i2c_bus
# address: 0x5D
display: my_display
# interrupt_pin: 38
on_touch:
- logger.log: "Ecran appuyé desssssssssssssssssssssssssssssssssssssssssssssssssus"
- if:
condition: lvgl.is_paused
then:
- light.turn_on: back_light
- lvgl.resume:
- lvgl.page.show: huawei_page
- lvgl.widget.hide: top_layer
- lvgl.widget.redraw:
- logger.log: "Ecran se reveilllllllllllllllllllllllllllllllllllllllllllle"
- logger.log:
format: Touch at (%d, %d)
args: [touch.x, touch.y]
- lambda: |-
ESP_LOGI("cal", "x=%d, y=%d, x_raw=%d, y_raw=%0d",
touch.x,
touch.y,
touch.x_raw,
touch.y_raw
);
on_update:
- lambda: |-
for (auto touch: touches) {
if (touch.state <= 2) {
ESP_LOGI("Touch points:", "id=%d x=%d, y=%d", touch.id, touch.x, touch.y);
}
}
on_release:
- if:
condition: lvgl.is_paused
then:
- logger.log: "LVGL resuming"
- lvgl.resume:
- lvgl.widget.redraw:
- light.turn_on:
id: back_light
brightness: 100%
time:
- platform: homeassistant
id: time_ha
timezone: UTC-4
on_time_sync:
- script.execute: time_update
on_time:
- minutes: '*'
seconds: 0
then:
- script.execute: time_update
script:
- id: init_touch
mode: queued
then:
- switch.turn_off: gt911_reset
- switch.turn_off: gt911_int
- delay: 20ms
- switch.turn_on: gt911_reset
- delay: 100ms
- switch.turn_off: gt911_int
- id: time_update
then:
- lvgl.label.update:
id: time_label
text: !lambda |-
static char time_buf[17];
auto now = id(time_ha).now();
bool is_pm = now.hour >= 12;
int hour_12 = now.hour % 12;
if (hour_12 == 0) {
hour_12 = 12; // 12 AM/PM should be displayed as 12, not 0
}
snprintf(time_buf, sizeof(time_buf), "%2d:%02d %s", hour_12, now.minute, is_pm ? "pm" : "am");
return time_buf;
- lvgl.label.update:
id: date_label
text: !lambda |-
static const char * const mon_names[] = {"JANVIER", "FEVRIER", "MARS", "AVRIL", "MAI", "JUIN", "JUILLET", "AOUT", "SEPTEMBRE", "OCTOBRE", "NOVEMBRE", "DECEMBRE"};
static char date_buf[20];
auto now = id(time_ha).now();
snprintf(date_buf, sizeof(date_buf), "%2d %s %4d", now.day_of_month, mon_names[now.month-1], now.year);
return date_buf;
- lvgl.label.update:
id: day_label
text: !lambda |-
static const char * const day_names[] = {"DIMANCHE", "LUNDI", "MARDI", "MERCREDI", "JEUDI", "VENDREDI", "SAMEDI"};
return day_names[id(time_ha).now().day_of_week - 1];
display:
- platform: mipi_rgb
model: RPI
id: my_display
data_pins:
red:
- 14
- 21
- 47
- 48
- 45
green:
- 9
- 46
- 3
- 8
- 16
- 1
blue:
- 15
- 7
- 6
- 5
- 4
de_pin: 41
hsync_pin: 39
vsync_pin: 40
hsync_front_porch: 40
hsync_pulse_width: 48
hsync_back_porch: 13
vsync_front_porch: 1
vsync_pulse_width: 31
vsync_back_porch: 13
pclk_pin: 0
pclk_frequency: 12MHz
pclk_inverted: true
color_order: RGB
auto_clear_enabled: false
update_interval: 30s
dimensions:
width: 800
height: 480
lvgl:
on_idle:
- timeout: 240s
then:
- logger.log: idle timeout
- lvgl.pause:
- light.turn_off:
id: back_light
transition_length: 5s
you're right, the script seems to be called anywhere...but it works ... Perhaps its called with the "touch" function...
anyway, thanks for your post, its work great for me now, on my 4 elecroc panel 7" !!!