Skip to content

Lesson 05: Touchscreen Coordinate Reading

Applicable development board: CrowPanel Advanced 7 / 9 / 10.1inch ESP32-P4 HMI AI Display

Model compatibility: The 7-inch, 9-inch, and 10.1-inch models are fully interchangeable in terms of hardware interfaces and software code; only their physical dimensions differ. Select a model based on your actual display size and use case; no code changes are required for this lesson.

1. Course Introduction

Initialize the ESP32-P4 display/touch panel, read GT911 touch points, and print coordinates and touch strength to the serial monitor.

2. Learning Objectives

After completing this lesson, you should be able to:

  • Understand panel initialization in setup() and multi-touch reading in loop().
  • Obtain reproducible X/Y coordinates when touching the screen.

  • Compile and upload the project, and determine whether the hardware and program are functioning correctly based on the experimental observations in this lesson.

3. What You Need to Prepare

  • Prepare the CrowPanel Advanced 7 / 9 / 10.1inch ESP32-P4 HMI AI Display development board and a data-capable USB-C cable in the quantity required for this lesson.
  • The project directory must include the .ino file, board_config.h, and the configuration files provided with the project.

Code reference: https://github.com/Elecrow-RD/CrowPanel-Advanced-7inch-ESP32-P4-HMI-AI-Display-1024x600-IPS-Touch-Screen/tree/master/example

4. Software Operation Steps

Double-click to open the Lesson 5 code (.ino file).

Open the touchscreen project

Configure the options below accordingly.

  • Board: ESP32P4 Dev Module
  • Core Debug Level: Info
  • Flash Frequency / Mode / Size: 80MHz / QIO / 16MB (128Mb)
  • Partition Scheme: 16M Flash (3MB APP/9.9MB FATFS)
  • PSRAM: Enabled
  • USB Mode: Hardware CDC and JTAG
  • Port: After connecting the USB data cable to the board's UART0, select the newly appeared COM port under "Tools → Port".

Standard upload configuration screenshot from Lesson 1

Follow the library import steps explained in detail in Lesson 1 to import the library files required by this project into the development environment, ensuring that the code can correctly locate the relevant dependencies during compilation, so that the program runs properly.

P4_Arduino_01_Images_15

5. Hardware Operation Steps

Now that the code is ready, we need to flash the ESP32-P4 to see the results in action.

First, connect the Advance-P4 device to your computer host via a USB cable.

USB connect development board

Before uploading the code, first select the upload configuration as described in "4. Software Operation Steps".

Connect UART0 and compile and upload using the general configuration; keep the board powered.

Compile and upload the LED program

Tap or drag on the screen with your finger, set the serial monitor baud rate to 115200, and record the changes in X, Y, and strength.

(For how to open the serial monitor, please refer to Lesson 1, where we provide a detailed explanation.)

Illustration of touching the screen with a finger

image-20260727163716276

6. Key Code Explanation

6.1 Panel Initialization

panel = new ESP_Panel();
panel->init();
panel->begin();

panel->init() sets up the display bus, LCD, and GT911 touch controller; panel->begin() starts the panel and backlight. If initialization fails, the program halts to avoid continued reading while the hardware is not ready.

6.2 Multi-Touch Reading

ESP_PanelTouchPoint point[10];
int point_num = touch->readPoints(point, 10, 0);
for (int i = 0; i < point_num; ++i) {
  Serial.printf("x=%d, y=%d, strength=%d\n",
                point[i].x, point[i].y, point[i].strength);
}

The array holds up to 10 touch points; the loop prints the X/Y/strength of each point. When interrupt mode is not enabled, use delay(20) to limit the polling frequency and avoid saturating the CPU.

7. Experimental Observations

  • While touching, the serial port continuously prints coordinates; after release, no new touch points are generated.

8. Common Issues and Troubleshooting

  • If IDLE loop is printed continuously, check the GT911 power supply, the I2C pin macros, and the panel configuration.
  • If the coordinate axis orientation is abnormal, first verify the rotation/mapping configuration of the project.