ESP32 CYD Touch Calibration: Read XPT2046 Coordinates
Calibrate the touch path after the LCD orientation is correct. This guide applies to an identified ESP32-2432S028R reference with XPT2046 resistive touch. A capacitive CYD uses another controller and should follow its own driver documentation.
Check the independent touch wiring
The reference board uses touch SCK25, MOSI32, MISO39, CS33 and IRQ36. These are different from the LCD and microSD connections. Confirm the board revision using the CYD pinout guide before using these numbers.
Read coordinates without a GUI
Install the XPT2046_Touchscreen library and upload this diagnostic for the identified reference board. Open Serial Monitor at 115200 baud. It reads touch samples only; it does not draw calibration targets or configure the LCD.
#include <SPI.h>
#include <XPT2046_Touchscreen.h>
// Reference: identified ESP32-2432S028R resistive-touch board ONLY.
// This diagnostic does not initialize the LCD or microSD.
SPIClass touchBus(VSPI);
XPT2046_Touchscreen touch(33, 36);
void setup() {
Serial.begin(115200);
touchBus.begin(25, 39, 32, 33); // SCK, MISO, MOSI, CS
touch.begin(touchBus);
touch.setRotation(0);
Serial.println("x,y,pressure");
}
void loop() {
if (touch.touched()) {
TS_Point point = touch.getPoint();
Serial.printf("%d,%d,%d\n", point.x, point.y, point.z);
}
delay(50);
}
This is a source-level reference, not a physical-unit accuracy test. Use the existing LCD image or a temporary removable guide to identify intended touch locations without scratching the panel.
Collect stable calibration points
- Fix the final display orientation and leave the touch-driver orientation unchanged while collecting samples.
- Touch near each corner, inset from the bezel, and at the center. Collect several samples at each position rather than one reading.
- Record the raw coordinate pair and its intended display coordinate. Look for reversed axes or X/Y exchange.
- Use the calibration format expected by your actual touch driver. Different libraries can use different parameters.
For an axis-aligned mapping, a coordinate can be scaled using pixel = (raw - raw_min) × (pixel_max - pixel_min) / (raw_max - raw_min) + pixel_min. Check that the denominator is nonzero, allow reversed endpoints where appropriate, and handle swapped axes explicitly. Clamp the final coordinate to the canvas bounds.
Validate away from the calibration points
Test a grid of points across the screen, including the center and edges. Calibration cannot guarantee one-pixel accuracy or repair a faulty controller. Keep the original readings so you can distinguish electrical noise, mapping errors and mechanical touch limits.
For mirrored positions, rotation changes or saved settings, continue with touch mapping and calibration troubleshooting. For the broader input workflow use the CYD touchscreen setup guide.
References
Article illustrations

Example build check
The diagnostic sketch above compiled for esp32:esp32:esp32 with ESP32 Arduino core 3.3.0 and XPT2046_Touchscreen source revision f956c5d8ce3b. The compiled configuration matches this page’s example. This confirms the build, not physical display or touch behavior.
