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

HARDWARE
esp32(not the full pinout one...)
3.5 inch tft screen sheild for arduino uno/mega

specs of screen
|LCD Type:|TFT|
|LCD Interface:|SPI|
|LCD Controller:|ILI9486|
|Touch Screen Type:|Resistive|
|Touch Screen Controller:|XPT2046|
|Colors:|RGB, 65K colors|
|Resolution:|480x320 (Pixel)|
|Aspect Ratio:|8:5|
|I/O Voltage:|3.3V/5V|

Libraries

i am using bodmer's library for showing display in the tft screen in 8bit parallel connection mode

i got the screen working somehow(lack of documentation for using this display with esp32)

then i started tests for touch but bodmer's lib doesnot support resistive touch on parallel connection so i went with the suggested library

(GitHub - s60sc/Adafruit_TouchScreen: Arduino library for 4-wire resistive touchscreens)

i was not able to find how to connect the wires for XP XM YP YM then i found out this library from fork history of the same library
and connected accordingly

|Touch Defines|Display|
|YP|CS|
|XM|RS|
|YM|D1|
|XP|D0|

here is the user defined data for bodmer's library...

*> *
> 02:44:25.654 -> TFT_eSPI ver = 2.5.23
> 02:44:25.654 -> Processor = ESP32
> 02:44:25.654 -> Frequency = 240MHz
> 02:44:25.654 -> Transactions = Yes
> 02:44:25.654 -> Interface = Parallel
> 02:44:25.654 -> Display driver = 9486
> 02:44:25.654 -> Display width = 320
> 02:44:25.654 -> Display height = 480
*> 02:44:25.654 -> *
> 02:44:25.654 -> TFT_CS = GPIO 33
> 02:44:25.654 -> TFT_DC = GPIO 18
> 02:44:25.654 -> TFT_RST = GPIO 32
> 02:44:25.654 -> TFT_WR = GPIO 19
> 02:44:25.701 -> TFT_RD = GPIO 23
*> 02:44:25.701 -> *
> 02:44:25.701 -> TFT_D0 = GPIO 13
> 02:44:25.701 -> TFT_D1 = GPIO 12
> 02:44:25.701 -> TFT_D2 = GPIO 14
> 02:44:25.701 -> TFT_D3 = GPIO 27
> 02:44:25.701 -> TFT_D4 = GPIO 26
> 02:44:25.701 -> TFT_D5 = GPIO 15
> 02:44:25.701 -> TFT_D6 = GPIO 2
> 02:44:25.701 -> TFT_D7 = GPIO 4
*> 02:44:25.701 -> *
> 02:44:25.701 -> Font GLCD loaded
> 02:44:25.701 -> Font 2 loaded
> 02:44:25.701 -> Font 4 loaded
> 02:44:25.701 -> Font 6 loaded
> 02:44:25.701 -> Font 7 loaded
> 02:44:25.701 -> Font 8 loaded
> 02:44:25.701 -> Smooth font enabled

everything is working fine except touch

first of all the pressure is negative
when 0 pressure is applied it return 0 or -1
when force is applied it returns values between -290 and -240

another problem is that X cordinate of the pressure applied never changes its always 4016 and Y cordinate changes as it should from 2800 to 4095

i dont understand this code snippet its in the example of the touch library...
const int coords[] = {4000, 500, 300, 2800};

1 Like

touch screen configuration

#define ESP32_WIFI_TOUCH // uncomment to use parallel MCU Friend LCD touchscreen with ESP32 UNO Wifi
#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  // Allow small amount of measurement noise

LCD_RS is connected to 18 and 35 both
LCD_WR is connected to 19 and 39 both(VN)

and is there any way to connect this display in SPI because further in this same esp i with to connect mrfc522

1 Like

So, any one of almost 100 kinds of ESP32... not very specific.

Why is that a problem? It gives you values you can test.

ESP WROOM32 WIFI + BLE

image

about the pressure values i am using them in negative but i would like to know is that so.. that it is in negative when it is supposed to be someother range of values

Is it "stopping the show" for you, or are you just curious? A real answer could depend on referencing documentation, you said you didn't have any.

its not a show stopper for now.. i can manage it..
but i just informed about that if it helps solve other problems and is interrelated

X cordinate of the pressure applied never changes its always 4016

to fix this problem

To obtain further help, please follow the forum guidelines and post a complete schematic. Please read:

1 Like

You need to know, not guess the connections

i was not able to find how to connect the wires for XP XM YP YM

from the above forked repo i got to know the connections and i have connected accordingly

|YP->CS| 33
|XM->RS| 18
|YM->D1| 13
|XP->D0| 12

with these connections as stated earlier
Y coordinate works fine
X stays almost constant(between 4016 and 4020)
pressure working fine just in negative

#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 -299
#define YELLOW  0xFFE0
#define BLACK 0x0000


const int coords[] = {4000, 500, 300, 2800}; // portrait - left, right, top, bottom

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

const int XP = 12, XM = 18, YP = 33, YM = 13; 
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

void setup() {
    Serial.begin(115200);
#ifdef TFT_eSPIlib
    Serial.println("TFT_eSPI library");
    tft.begin();
#else
    Serial.println("MCUFRIEND_kbv library");
    idDisplay();
#endif

    String orientation;
    switch (rotation) {
      case 1: 
        orientation = "Landscape";
      break;

    }
    Serial.println(orientation);
    tft.setRotation(rotation);  
    tft.fillScreen(BLACK);
    tft.setCursor(0, 4, 4);
    tft.println(" yamete kudsai text");
}

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);      //restore shared pins
    pinMode(YP, OUTPUT);
    pinMode(XP, OUTPUT);      //restore shared pins
    pinMode(YM, 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 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;
      }      
      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;
}

@bodmer if you could give this problem a look..

Why are you simply re-posting your original post? Everyone who is interested, has seen it the first time. Unless I'm mistaken, you didn't post any new information. If you have questions for a particular forum member, you should send them a PM.

no i dont have question for a particular form member
sorry i misinterpret your last post and re confirmed the connections..

Well, who is @bodmer then?

I'm still waiting for a wiring diagram...

here is the wiring diagram..

in whiteboard

UPDATE:-

these changes are not based on any written information i am just trying out different pin configurations that might give me correct data of resistive touch

my configuration:-
const int XP = 12, XM = 18, YP = 32, YM = 33; //XP -> D1 XM->RS YP-> RST YM->CS

my observation

  • pressure is 0 and -1 and ranges from 230 to 250 same as before

  • X coordinate is still the same as before at 4010-4030 range

  • Y coordinate gives some interesting results

it seems as if it is reacting to both the X axis and Y axis and somewhat proportionally

posting this if it helps find the problem of constant X value

1 Like

related post according to this i hooked up an arduino uploaded the code and i was able to get some results


the touch worked perfectly from the given data i was able to conclude that

YP in arduino is connected to 15 which for arduino is A1 and it is connected to WR
XM in arduino is connected to 16 which for arduino is A2 and it is connected to RS
YM in arduino connected to 7 which is connected to lcs's D7
XP in arduino connected to 6 which is connected to lcs's D6

so i updated my code for esp according and changed the following line

const int XP = 2, XM = 18, YP = 19, YM = 4;

yet i am getting the same results

Check your data types, when a positive integer overflows it can become negative.

Although it may sound passive-aggressive, it is in fact what I would do - study and troubleshoot your code.

Troubleshoot by placing serial debug prints of your variables so you can see what they are.

Compare your program with the working one that you have, to see what the differences are.

1 Like

Check your data types, when a positive integer overflows it can become negative.

its int type defined in the library's .cpp code

as for placing serial debug printings the results of X,Y,Z are the same thing
infact both the setup with arduino one and the esp one uses the same touch library i checked the code and the calculation they do in the library is also bare minimum and its almost raw analog output anyways ... since they use same library i dont think the error is withing library...? or it could be?

my hunch is that its about the connection only...

yup i like to learn and fix things the same way but its not helping this time
i dont know how do i compare those 2 programs the difference visible to me is only that it has different connections and different board.. one code uses mcufriend_kbv library and the other uses TFT_eSPI library by bodmer but that should not affect the working cause both library only shows display on screen and not the touch input related

after somechanges in connection i am getting even weird values of pressure.. i am not really sure what it is based of
when i use a sharp object(high pressure due to less surface area) it is in positive and when i use my fingers (large surface area) it is in negative maybe it needs to be calibrated anyways they are not linear and their behavior is not predictable let alone mapping them in a linear way.

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: