Hi,
I am fiddling with the touch screen detection of the lilygo-T547.
I am using the GT911 touchscreen as you can see below. Also the i2c
scan works fine. It detects the GT911 either at
address: 0x5D # Either this or the one below is correct
address: 0x14
as you can see below
[12:09:35][I][i2c.arduino:096]: Results from i2c bus scan:
[12:09:35][I][i2c.arduino:102]: Found i2c device at address 0x14
But I did not find out, how I could use the scanned result dynamically in configuring the touch display
In the touchscreen definition I have to put in a fixed address which works, if I change it to the detected address
from the i2c scan, compile and are “lucky”. But after each deep sleep or start or reset
it gets a new address. See line 105ff of
I am fine, if I would have to change the address directly after on_boot but I have no clue how to do this,
what variable (?) I do have to change there in the lambda.
See the snippet I am talking about here. You can find a full YAML code here:
i2c:
- id: bus_a
sda: GPIO18
scl: GPIO17
frequency: 100khz
# There is some problems with i2c scan so turn scan off if problem appear on your board
scan: true
touchscreen:
platform: gt911
# platform: lilygo_t5_47
id: lilygo_touchscreen
# interrupt_pin: GPIO47
interrupt_pin: GPIO47
# address: 0x5D # Either this or the one below is correct
address: 0x14 # One should do it like here: https://github.com/Xinyuan-LilyGO/LilyGo-EPD47/blob/067ece6bddfd8d0fe6c2c18043930236cee4ac23/examples/touch/touch.ino
# lines from 108 which try both addresses, and just choose the right one.
setup_priority: -100
transform:
# because we use the display widescreen, buttons on top we have to transfer the touch
mirror_x: false
mirror_y: true
swap_xy: true
on_update:
- lambda: |-
for (auto touch: touches) {
if (touch.state <= 2) {
ESP_LOGD("cal", "x=%d, y=%d, x_raw=%d, y_raw=%0d",
touch.x,
touch.y,
touch.x_raw,
touch.y_raw
);
}
}
So how could I use the correctly found “address” from the scan in the touchscreen definition?
any hint appreciated.
HI @Karosm,
I just tried without setting address fixed. Scan found 0x51D and now it is working. I would have sworn, that I tried this before.
I hope it also works with 0x14D
16:31:01][I][i2c.arduino:102]: Found i2c device at address 0x14
it is not working. It seems that with the T457 0x14 and 0x51 are used for two different things when booting. And if I cannot use them dynamically like in the above, it is not reliable. It seems in the GT911 0x5D is fixed for touch, which won’t work with the T457
Hi @Karosm,
all I can say that it “sometimes works”, sometimes not. I sit at the machine, compile the new ESPHome yaml, and when it boots, it shows either
[17:18:01][I][i2c.arduino:096]: Results from i2c bus scan:
[17:18:01][I][i2c.arduino:102]: Found i2c device at address 0x51
[17:18:01][I][i2c.arduino:102]: Found i2c device at address 0x5D
or
[17:18:01][I][i2c.arduino:096]: Results from i2c bus scan:
[17:18:01][I][i2c.arduino:102]: Found i2c device at address 0x14
[17:18:01][I][i2c.arduino:102]: Found i2c device at address 0x5D
seems to be depending on what I set at address:
I “somehow” have to “tell” that this address: depends on what was found at the i2c scan.
if I do not use address, it seems it only works, if 0x51 is choosen. If I see the address in the first scan after compile, and than change it and recompile it works at the moment, until “someone” in the chip decides to use the other address. To me it looks random, but I cannot do anything about it.
Did you check the link from the manufacturer? There from line 105 on, they check for those addresses. I asked them and only got back: You have to do it, but we do not know how to do it in ESPHome.
I have absolutely zero idea how I can do this in ESPHome either. I hoped to do it during boot, but my knowledge is not enough to get this working.
I am playing with this since 2 month now with no luck. At least I can reliably give the user feedback on the ePaper, that he cannot use touch.
But other than that, I can’t change between those addresses, which seems to be necessary with the lilygo T457.
touchscreen:
# platform: gt911
platform: lilygo_t5_47
id: lilygo_touchscreen
interrupt_pin: GPIO47
# address: 0x5D # Either this or the one below is correct
# address: 0x14 # One should do it like here: https://github.com/Xinyuan-LilyGO/LilyGo-EPD47/blob/067ece6bddfd8d0fe6c2c18043930236cee4ac23/examples/touch/touch.ino
# lines from 108 which try both addresses, and just choose the right one.
setup_priority: -100
transform:
# because we use the display widescreen, buttons on top we have to transfer the touch
mirror_x: false
mirror_y: true
swap_xy: true
on_update:
- lambda: |-
for (auto touch: touches) {
if (touch.state <= 2) {
ESP_LOGD("cal", "x=%d, y=%d, x_raw=%d, y_raw=%0d",
touch.x,
touch.y,
touch.x_raw,
touch.y_raw
);
}
}
it seems to give the correct
[18:03:32][I][i2c.arduino:096]: Results from i2c bus scan:
[18:03:32][I][i2c.arduino:102]: Found i2c device at address 0x14
[18:03:32][I][i2c.arduino:102]: Found i2c device at address 0x51
scan results, but down low, it is using a totally different address
maybe the external display source somehow cannot work with the touch. But these are wild speculations.
Using Gt911 instead of lilygo_t5_47 for touch screen was the closest I could get it to work at least sometimes.
Hi @Karosm,
I read this documentation as well, but GPIO13 definitely does not work for my touch screen; if I address it with GT911 it always is GPIO47, the only problem I have are the two different addresses that are used… On my board V2.4 is printed, the latest foto I saw was V2.2 in the internet. And if I got it right, 2.2 was already shown in 2023.
Do you have an idea, where else I could find help. With chatgpt I am turning in circles, I also think that writing a complete new extra driver is not necessary. To me it feels, that 10 lines of code at the right spot would do the job for me.
Do you know, if I could change the address later on at the ESP with a lambda function, directly after boot of the ESP?
It’s kind of strange it works with 0x5D but not with 0x14. Since the address is not hard coded anywhere, it means esphome somehow pics it automatically.
So maybe the *Pcf8563 RTC 0x51 is making confusion here. Do you have some configuration for that on your code?
Hi @Karosm,
you got me wrong. With GT911 it works perfectly with 0x51 and 0x14 addresses, BUT only if on boot the the ESP “somehow” takes the 0x51 or 0x14 which is either fixed during compile with address: or “somehow” by luck choosen the same way.
So the addresses are perfect, but the rest of the code does not care about, what I2C scan finds. It “just” pics up randomly (it seems to me) tierh 0x51 or 0x14, regardless, what I2C scan founds.
I do not know how to debug this behaviour, or how to get deeper into the code. I personally feel, that I would start with the GT911 code you showed.
So problem is, that not the correct address is taken, from I2C scan, which I2C scan finds, but any other address. I have the feelling, that if I fix it with address:to 0x51 or 0x14 it seems to work more often (but not reliably), as maybe the code that uses this addres picks another address from I2C scan. During boot I see alsway two devices found on different addresses
[17:18:01][I][i2c.arduino:096]: Results from i2c bus scan:
[17:18:01][I][i2c.arduino:102]: Found i2c device at address 0x51
[17:18:01][I][i2c.arduino:102]: Found i2c device at address 0x5D
but the system should only take the 0x14 or 0x51 never the 0x5D I see there.
[17:18:01][I][i2c.arduino:096]: Results from i2c bus scan:
[17:18:01][I][i2c.arduino:102]: Found i2c device at address 0x51
[17:18:01][I][i2c.arduino:102]: Found i2c device at address 0x5D
or
[17:18:01][I][i2c.arduino:096]: Results from i2c bus scan:
[17:18:01][I][i2c.arduino:102]: Found i2c device at address 0x14
[17:18:01][I][i2c.arduino:102]: Found i2c device at address 0x5D
as above and is not picking 0x5D or 0x14 I just checked, I switch between fixed 0x14 and 0x5D in my ESPHome YAML.
Still: I see no way to choose the correcly found 0x14 or 0x5D from the I2C scan.
Hi @Karosm,
I can confirm, that I2C Scan produces 2 found devices:
[11:54:33][I][i2c.arduino:096]: Results from i2c bus scan:
[11:54:33][I][i2c.arduino:102]: Found i2c device at address 0x51
[11:54:33][I][i2c.arduino:102]: Found i2c device at address 0x5D
I just booted now 10 times, and get always those two, so this works at the moment. I’ll add what I get different, if I get other scan results, but I assume I see the 0x14 instead of the 0x5D
As above: I see two results.
thank you
Juergen
I now tried to fix the address to 0x51.
During boot I see
[12:12:38][I][i2c.arduino:096]: Results from i2c bus scan:
[12:12:38][I][i2c.arduino:102]: Found i2c device at address 0x51
[12:12:38][I][i2c.arduino:102]: Found i2c device at address 0x5D
I check in the ESP code
if (id(lilygo_touchscreen).is_failed()) {
which does not fail. But the touch does not react (as expected). The “is_failed” is reliable, if tested for 0x5D and 0x14