/* ESP32_SPI_9481_v1 * * Despite the script name I was supplied with a 9486 * * Basic attempt to get screen working * Screen working...eventually * I has to uncomment the following in the User_SetUp.h to get correct colours * //#define TFT_INVERSION_ON #define TFT_INVERSION_OFF * Touch working * * pins, note that touch and screen share a couple of pins...SPI * Pins in Order starting at screen VCC VCC 3.3v (My screen spec said it would accept 5 v on VCC not Logic pins GND > Gnd TFT_CS > ESP pin 15 // Chip select control pin TFT_RST > ESP pin 4 TFT_DC > ESP pin 2 // Data Command control pin TFT_MOSI (SDI) > ESP pin 23 TFT_SCLK > ESP pin 18 BL (LCD power) 3.3V TFT_MISO > ESP pin 19...although can be left disconnected if not trying to read back from screen Touch clock TCK > ESP pin 18 Touch Chip Select TCS > ESP pin 21 Touch data to screen TOI > ESP pin 23 Touch Data from screen TDI > ESP pin 19 PEN unused */ #include "TFT_eSPI.h" // Hardware-specific library #include "SPI.h" //#define TFT_RED 0xF800 /* 255, 0, 0 */ TFT_eSPI tft = TFT_eSPI(); // Invoke custom library with default width and height //touch variables int xTouch; //x position int yTouch; //y position unsigned long touchTimer;//keeps track of touch timings const int debounceSensitivity = 300;//300 milliseconds debounce //deals with screen being touched void screenPress() { uint16_t x, y; unsigned long currentMillis; currentMillis = millis(); //deals with debouncing if ((currentMillis - touchTimer) >= debounceSensitivity) { touchTimer = currentMillis; tft.getTouchRaw(&x, &y);//only bother getting readings when needed if (tft.getTouchRawZ() > 500) { //will need alterations if screen is rotated xTouch = (x - 380) / 10; //9.75 yTouch = (y - 248) / 7; //7.04 Serial.printf("x: %i ", x); Serial.printf("y: %i ", y); Serial.printf("z: %i \n", tft.getTouchRawZ()); Serial.print("X: "); Serial.print(xTouch); Serial.print(" Y: "); Serial.println(yTouch); } } } void setup() { Serial.begin(115200); Serial.println("ESP32_SPI_9481_v1"); tft.begin(); tft.init(); tft.setRotation(0); tft.fillScreen(TFT_RED); tft.drawRect(0,0,319,476,TFT_WHITE);//screen seems to only display 476 wide, rest is hidden under black surround tft.drawRect(10,10,10,10,TFT_WHITE);//just to let me know top corner tft.setTextColor(TFT_WHITE, TFT_BLACK); tft.setCursor(40,40); tft.println("Some Text"); } void loop() { screenPress(); }