1.8 Touch Panel
Read touch coordinates from the FT6336U capacitive touch controller over I2C.
Overview
This example shows how to read multi-touch data from the FT6336U capacitive touch panel controller. On startup, it dumps the main configuration registers for debugging, then continuously scans for up to 2 simultaneous touch points.
Note
This example is based on the open-source ScanMultiTouch example from the Arduino-FT6336U library. For the LAFVIN ESP32-S3 Multimedia Kit, we adapted the I2C and touch-controller pin configuration, kept the multi-touch scanning behavior, and simplified the serial output so the results are easier to read during learning and demonstration.
What You’ll Learn
Initializing the FT6336U touch controller over I2C
Reading device configuration registers
Detecting touch points and reading X/Y coordinates
Understanding I2C device addressing
Before You Begin
Complete the setup steps in Preparation before continuing.
Note
Use the recommended Arduino IDE settings in Recommended Board Settings unless this lesson says otherwise.
Open the example sketch from the code package:
LAFVIN-ESP32-S3-Multimedia-Kit-main/1.Arduino/8.Touch/8.Touch.ino
This example uses the onboard touch panel. No external wiring is required.
Signal |
ESP32-S3 |
|---|---|
SDA |
GPIO 2 |
SCL |
GPIO 1 |
Upload and Test
Connect the board with a USB Type-C data cable.
Open
8.Touch.inoin Arduino IDE.In the Tools menu, select
ESP32S3 Dev Moduleas the board and choose the correct serial port.Click Upload.
Open Serial Monitor at
115200baud. On startup, the sketch prints the FT6336U configuration registers:FT6336U Device Mode: 0x00 FT6336U Threshold: 0x30 ... Chip ID: 0x06 Firmware ID: 0x05
Touch the screen. Coordinates appear in the Serial Monitor every 100 ms:
FT6336U TD Count 1 / TD1 (1, 150, 200) / TD2 (0, 0, 0)
The format is: touch status (1 = pressed), X coordinate, Y coordinate. The second touch point shows
0when only one finger is touching.
How the Code Works
Sensor Initialization
The FT6336U object is created with the board’s I2C pins and with reset and interrupt pins disabled.
#define I2C_SDA 2
#define I2C_SCL 1
#define RST_N_PIN -1
#define INT_N_PIN -1
FT6336U ft6336u(I2C_SDA, I2C_SCL, RST_N_PIN, INT_N_PIN);
Starting the Controller
The sketch starts the touch controller in setup() before reading any status or touch data.
void setup() {
Serial.begin(115200);
ft6336u.begin();
}
Reading Registers
On startup, the sketch reads the main FT6336U configuration registers and prints them to the Serial Monitor.
Serial.print("FT6336U Device Mode: ");
Serial.println(ft6336u.read_device_mode());
Serial.print("FT6336U Threshold: 0x");
Serial.println(ft6336u.read_touch_threshold(), HEX);
Serial.print("FT6336U Chip ID: 0x");
Serial.println(ft6336u.read_chip_id(), HEX);
Serial.print("FT6336U Firm ID: 0x");
Serial.println(ft6336u.read_firmware_id(), HEX);
Touch Scanning
The scan() method returns up to two touch points, and the sketch prints their status and coordinates as one formatted line.
tp = ft6336u.scan();
char tempString[128];
sprintf(tempString, "FT6336U TD Count %d / TD1 (%d, %4d, %4d) / TD2 (%d, %4d, %4d)",
tp.touch_count, tp.tp[0].status, tp.tp[0].x, tp.tp[0].y,
tp.tp[1].status, tp.tp[1].x, tp.tp[1].y);
Serial.println(tempString);
delay(100);
In the provided sketch:
The register dump includes the main FT6336U configuration and identification values
Touch scanning runs at 100 ms intervals, which is enough for a simple serial demonstration
Coordinates are reported in the display’s native coordinate space
Try This Next
Reduce the scan interval from 100 ms to 20 ms for more responsive touch updates
Experiment with the touch threshold register to change panel sensitivity
Use the touch coordinates as input for your own projects, such as drawing or button control