Skip to content

Commit

Permalink
Update GT911 example
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Jun 4, 2024
1 parent b474b4b commit 9cfc0b8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
53 changes: 34 additions & 19 deletions examples/TouchDrv_GT911_GetPoint/TouchDrv_GT911_GetPoint.ino
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ void setup()
Serial.begin(115200);
while (!Serial);

Wire.begin(SENSOR_SDA, SENSOR_SCL);
/*
* The touch reset pin uses hardware pull-up,
* and the function of setting the I2C device address cannot be used.
* Use scanning to obtain the touch device address.
* * */

If the touch reset pin and interrupt pin cannot be controlled by GPIO, the device address cannot be controlled and can only be obtained by scanning.

Wire.begin(SENSOR_SDA, SENSOR_SCL);
uint8_t touchAddress = 0;
Wire.beginTransmission(0x14);
if (Wire.endTransmission() == 0) {
Expand All @@ -79,40 +78,56 @@ void setup()
delay(1000);
}
}

touch.setPins(SENSOR_RST, SENSOR_IRQ);

if (!touch.begin(Wire, touchAddress, SENSOR_SDA, SENSOR_SCL )) {
while (1) {
Serial.println("Failed to find GT911 - check your wiring!");
delay(1000);
}
}
*
* * */

// If the reset pin and interrupt pin can be controlled by GPIO, the device address can be set arbitrarily
touch.setPins(SENSOR_RST, SENSOR_IRQ);
if (!touch.begin(Wire, GT911_SLAVE_ADDRESS_H, SENSOR_SDA, SENSOR_SCL )) {
while (1) {
Serial.println("Failed to find GT911 - check your wiring!");
delay(1000);
}
}

//Set to trigger on falling edge
touch.setInterruptMode(FALLING);

Serial.println("Init GT911 Sensor success!");

// Set the center button to trigger the callback , Only for specific devices, e.g LilyGo-EPD47 S3 GT911
touch.setHomeButtonCallback([](void *user_data) {
Serial.println("Home button pressed!");
}, NULL);

}

void loop()
{
if (touch.isPressed()) {
uint8_t touched = touch.getPoint(x, y, touch.getSupportTouchPoint());
for (int i = 0; i < touched; ++i) {
Serial.print("X[");
Serial.print(i);
Serial.print("]:");
Serial.print(x[i]);
Serial.print(" ");
Serial.print(" Y[");
Serial.print(i);
Serial.print("]:");
Serial.print(y[i]);
Serial.print(" ");
if (touched > 0) {
for (int i = 0; i < touched; ++i) {
Serial.print("X[");
Serial.print(i);
Serial.print("]:");
Serial.print(x[i]);
Serial.print(" ");
Serial.print(" Y[");
Serial.print(i);
Serial.print("]:");
Serial.print(y[i]);
Serial.print(" ");
}
Serial.println();
}
Serial.println();
}
delay(5);
}
Expand Down
12 changes: 9 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@
; src_dir = examples/TouchDrv_GT911_LilyGo_T_RGB
; src_dir = examples/TouchDrv_Interface_T_RGB
; src_dir = examples/TouchDrv_FT6232_GetPoint
; src_dir = examples/TouchDrv_GT911_GetPoint
src_dir = examples/TouchDrv_GT911_GetPoint
; src_dir = examples/TouchDrv_CHSC5816_GetPoint
; src_dir = examples/TouchDrv_CSTxxx_GetPoint


; default_envs = esp32-s3n4r2
; default_envs=esp32s3-opi
default_envs=esp32s3-opi
; default_envs=esp32s3-qspi
; default_envs=esp32c3
; default_envs=esp32dev
; default_envs = rp2040
default_envs = nrf52840
; default_envs = nrf52840

; Custom board variant
boards_dir = ./board
Expand Down Expand Up @@ -123,6 +123,12 @@ build_flags =
; -DSENSOR_IRQ=8
; -DSENSOR_RST=17

; T-EPD47 S3 GT911 2 Point touch✅
-DSENSOR_SDA=6
-DSENSOR_SCL=5
-DSENSOR_IRQ=15
-DSENSOR_RST=41

-DCORE_DEBUG_LEVEL=5
-Wnarrowing
-Wtype-limits
Expand Down

0 comments on commit 9cfc0b8

Please sign in to comment.