I am trying to get the touch screen and display working on my ESP8266 + TFT ST7796S. However, only one of them works at a time.
Below is my pin configuration:
| Function | Device | NodeMCU Pin | GPIO |
|---|---|---|---|
| TFT_CS | ST7796S | D8 | 15 |
| TFT_DC | ST7796S | D1 | 5 |
| TFT_RST | ST7796S | D4 | 2 |
| TFT_MOSI | ST7796S | D7 | 13 |
| TFT_SCK | ST7796S | D5 | 14 |
| TFT_MISO | ST7796S | D6 | 12 |
| Touch_CS | XPT2046 | D2 | 4 |
| Touch_IRQ | XPT2046 | D3 | 0 |
| VCC | All | 3.3V | — |
| GND | All | GND | — |
Below is a working sketch to detect tuch co-ordinates and print on the serial monitor:
#include <SPI.h>
#include <TFT_eSPI.h> // Uses existing User_Setup.h
#include "XPT2046.h" // Touch driver
// ---- Touch Configuration ----
#define TOUCH_CS_PIN D2 // GPIO4
#define TOUCH_IRQ_PIN D3 // GPIO0 (optional)
// ---- Touch Calibration ----
XPT2046::Calibration cal = {
0.0644197, -0.0003023, -11.8842955,
-0.0002274, 0.0898521, -14.7727499,
240, 320, 0
};
// ---- Objects ----
TFT_eSPI tft = TFT_eSPI();
XPT2046 touch(TOUCH_CS_PIN, TOUCH_IRQ_PIN);
void setup() {
Serial.begin(115200);
delay(300);
Serial.println("\n--- ST7796 + XPT2046 Touch Test ---");
// ✅ Initialize TFT
tft.init();
tft.setRotation(1);
tft.fillScreen(TFT_BLUE); // Fill the *entire* screen blue
tft.setTextColor(TFT_YELLOW, TFT_BLUE);
tft.setTextSize(3);
tft.setTextDatum(MC_DATUM); // Middle center alignment
tft.drawString("Hello, World!", tft.width()/2, tft.height()/2);
Serial.println("TFT Initialized and filled with blue.");
// ✅ Initialize Touch
SPI.begin(); // Initialize default hardware SPI
touch.begin();
touch.setRotation(1);
touch.setCalibration(cal);
touch.setSampleCount(20);
touch.setDebounceTimeout(100);
touch.setTouchPressure(3.5);
touch.setDeadZone(50);
touch.setPowerDown(true);
Serial.println("Touch Initialized. Tap the screen...");
}
void loop() {
if (touch.touched()) {
XPT2046::Point pos = touch.getTouchPosition();
if (touch.valid(pos)) {
Serial.printf("Touch X: %d, Y: %d\n", pos.x, pos.y);
}
}
delay(100);
}
I tried shorting the diode as discussed here.
Need a working code where both touch screen and display works. Thanks a ton in advance!

only one of them works at a time.... what does that mean? ... please edit your post with a description of what actually happens