Negative pressure, no response to touch on X/Y axis ILI9486 ESP32 [SOLVED]

finally got this working....

FOR ESP32

for many of you looking for solution to the same problem in one spot there you go..

for the connection follow this

#define TFT_CS   33 
#define TFT_DC   15  
#define TFT_RST  32  

#define TFT_WR    4 
#define TFT_RD    2

#define TFT_D0   12  
#define TFT_D1   13  
#define TFT_D2   26
#define TFT_D3   25
#define TFT_D4   18
#define TFT_D5   19
#define TFT_D6   27
#define TFT_D7   14

make sure you have the same in the User_Setup.h

for the touch library i am using Adafruit_TouchScreen-master

in TouchScreen.h you have to do the following modifications

#define ESP32_WIFI_TOUCH

make sure you uncomment this in this configuration else your X Y values will be constant

you need to connect pin 39 of esp32 to pin D4 and pin 35 to D15


#define ESP32_WIFI_TOUCH // make sure you uncomment this
#ifdef ESP32 
#define ADC_MAX 4095  // maximum value for ESP32 ADC (default 11db, 12 bits)
#define aXM 35  // analog input pin connected to LCD_RS 
#define aYP 39  // analog input pin connected to LCD_WR
#else
#define ADC_MAX 1023  // Arduino
#endif 
#define NOISE_LEVEL 4

you can use this test code untill you get correct values of X Y and Z

i never got the internal X Y mapper to work so i am doing a manual range check on the raw values i receive from getPoints()

#define TFT_eSPIlib  // comment out to use MCUFRIEND_kbv

#ifdef TFT_eSPIlib
#include <TFT_eSPI.h>
TFT_eSPI tft = TFT_eSPI();
#else
#include <MCUFRIEND_kbv.h> 
MCUFRIEND_kbv tft;
#endif

#include <TouchScreen.h>
#define MINPRESSURE -300
#define MAXPRESSURE -100 
// check what pressure you are getting on not touched and while it is being touched and set the values according to that
#define YELLOW  0xFFE0
#define BLACK 0x0000


const int coords[] = {907, 136, 942, 139}; // portrait - left, right, top, bottom

const int rotation = 0; //  in rotation order - portrait, landscape, etc


const int XP = 27, XM = 15, YP = 4, YM = 14; // default ESP32 Uno touchscreen pins 33 32
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

void setup() {
    Serial.begin(115200);
    analogSetWidth(12);
#ifdef TFT_eSPIlib
    Serial.println("TFT_eSPI library");
    tft.begin();
#else
    Serial.println("MCUFRIEND_kbv library");
    idDisplay();
#endif
    // screen orientation and background
    String orientation;
    switch (rotation) {
      case 0: 
        orientation = "Portrait";
      break;
      case 1: 
        orientation = "Landscape";
      break;
      case 2: 
        orientation = "Portrait Inverted";
      break;
      case 3: 
        orientation = "Landscape Inverted";
      break;
    }
    Serial.println(orientation);
    tft.setRotation(rotation);  
    tft.fillScreen(BLACK);
    tft.setCursor(0, 4, 4);
    tft.println(" yamete kudsai text");
    delay(2000);
    tft.setCursor(0, 5, 4);
    tft.println(" uguh kaam kr jaaa");
}

void loop() {
 // TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
    uint16_t pixel_x, pixel_y;    
    
   boolean pressed = Touch_getXY(&pixel_x, &pixel_y, true,ts);
   delay(10);
   }

boolean Touch_getXY(uint16_t *x, uint16_t *y, boolean showTouch,TouchScreen ts ) {
    TSPoint p = ts.getPoint();
    
    pinMode(XM, OUTPUT);
    pinMode(YP, OUTPUT);
    //digitalWrite(XP, HIGH);   //because TFT control pins
    //digitalWrite(YM, HIGH);
    Serial.print("X = "); Serial.print(p.x);
     Serial.print("\tY = "); Serial.print(p.y);
     Serial.print("\tPressure = "); Serial.println(p.z);
  
    bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
    if (pressed) {
      switch (rotation) {
        case 0: // portrait
          *x = map(p.x, coords[0], coords[1], 0, tft.width()); 
          *y = map(p.y, coords[2], coords[3], 0, tft.height());
        break;
        case 1: // landscape
          *x = map(p.y, coords[1], coords[0], 0, tft.width()); 
          *y = map(p.x, coords[2], coords[3], 0, tft.height());
        break;
        case 2: // portrait inverted
          *x = map(p.x, coords[1], coords[0], 0, tft.width()); 
          *y = map(p.y, coords[3], coords[2], 0, tft.height());
        break;
        case 3: // landscape inverted
          *x = map(p.y, coords[0], coords[1], 0, tft.width()); 
          *y = map(p.x, coords[3], coords[2], 0, tft.height());
        break;
      }      
      Serial.write(*x);
      Serial.write(*y);
      
      if (showTouch) {
        //tft.drawString("LMOA YAMETE KUDASAI",50,50);
        //tft.begin();
        tft.setCursor(0, 4, 4);
        tft.fillScreen(BLACK);
        tft.println(" White text");
        Serial.println("PRIONMTED");
        delay(200);
        tft.fillCircle(*x, *y, 2, YELLOW);
        }
    }
    return pressed;
}

by this point you will be able to get some values of X Y and Z
use those values to locate the touch and make your UI accordingly....

ps:- this is a work around cause i dont have time do this the correct way (by putting them in getx_y function getting a mapped value of touch......)

special thanks:-
@bodmer for creating the awesome library and all the old posts(before 2021)
@david_prentice for his old posts that helped me figure out things bit by bit

Trouble finding touch pins?
use a multimeter observe changes in resistance when touching between pins
or use a arduino uno hook it out try the mcufrieind library then get the correct pin set then replicate it in the esp32

some useful posts
if you are finding it difficult to find touch pins
correct hardware?
some other info

not ranting but.. what did i learn from the replies of this form? dunno about the actually problem but how to post a form correctly :slight_smile: