LCD Touch screen issues UNO R3 2.8

Hi, this is my first post on the forums so I hope I put all the information I need to so I can hopefully resolve this issue.

I bought my first LCD touch screen from Amazon and it came with no manual, instruction or libraries. I had to search around for about a day to find libraries that would work with this screen. After about a day of just putting shapes, words and data on the screen I decided to try and get the touch screen working. The library I found does work with it, however, the touchscreen and display rely on the same pins for it to work. I can either have the touchscreen working with a white display or graphics with no touch. I’ve been trying for a while to get both to work but I just can’t figure out what I’m doing wrong.

LCD I bought

#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#include <stdint.h>
#include "TouchScreen.h"

//TouchScreen definitions
#define YP A2
#define XM A3
#define YM 8
#define XP 9

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

//Graphics Definitions

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

//Color Definitions
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

void setup(void) {
  Serial.begin(9600);

   #ifdef DEBUG
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));
  Serial.print("TFT size is ");
  Serial.print(tft.width());
  Serial.print("x");
  Serial.println(tft.height());
#endif // DEBUG
  tft.reset();

  uint16_t identifier = tft.readID();

if(identifier == 0x9325) {
#ifdef DEBUG
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {

    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {

    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {

    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {

    Serial.println(F("Found HX8357D LCD driver"));
#endif // DEBUG
    } else {
    #ifdef DEBUG
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.print(F("I try use ILI9341 LCD driver "));
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    #endif // DEBUG
    identifier = 0x9341;
  }

  tft.begin(identifier); //Begin TFT with correct chip
}

void loop() {
  touchTest();
}

void touchTest() {
  tft.fillScreen(BLACK);
  delay(1000);
  tft.fillScreen(WHITE); //Display changes up to this point
  delay(1000);
  TSPoint p = ts.getPoint(); //Thinking this is the issue since both graphics and touch are on same pins.

  if (p.z > ts.pressureThreshhold) {
    test();
  }
}

unsigned long test(void) {
  Serial.println("Test"); //Displays this text in the serial monitor.
  tft.fillScreen(GREEN); //Does not change the screen color.
}

Most of the current mcufriend style boards have the TouchScreen on YP=A1, XM=A2, YM=7, XP=6.

However some are Landscape and some are Portrait. So your paint directions may be wrong.

Add this to the top of your sketch. Then you can see some information on the Serial Terminal. e.g. which Controller you have.

#define DEBUG

David.

I have done this (finally) and here is what it has printed:

TFT LCD test
TFT size is 240x320
Found ILI9341 LCD driver

Surely it has printed the X,Y of each Touch.

If these look silly, something has gone wrong.

David.

I have made it print the x/y locations when I'm touching the screen but the lowest point for each is around 150 to 200.

TFT LCD test
TFT size is 240x320
Found ILI9341 LCD driver
X = 954	Y = 910	Pressure = 245
X = 950	Y = 202	Pressure = 269
X = 211	Y = 207	Pressure = 488
X = 213	Y = 914	Pressure = 414

Those are the four corners of the screen.

Sorry to bump this again but I was wondering if anyone had any ideas?

So, what is the problem?
You are using the Adafruit libraries.

You edit the Adafruit tftpaint sketch to match your X, Y values. From memory, I think they are called MINX, MAXX, ....

David.

Here is my current code:

#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#include <stdint.h>
#include "TouchScreen.h"

//Graphics Definitions

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

//TouchScreen definitions
#define YP A2
#define XM A3
#define YM 8
#define XP 9

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

//Color Definitions
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

#define DEBUG

void setup(void) {
  tft.reset();
  
  Serial.begin(9600);

  uint16_t identifier = tft.readID();
  tft.begin(identifier);
  
  touch();
  
  }



void loop() {
}

void touch() {
   while(1){
    TSPoint p = ts.getPoint();

    if (p.z > ts.pressureThreshhold) {
      Serial.println("!");
      tft.fillScreen(GREEN);
    }
    delay(100);
  }
}

When I press on the screen, the color does not change. The issue is when I start using the touch screen, nothing will happen with the graphics anymore.

[edit] To be specific, after “TSPoint p = ts.getPoint();” is when the graphics will no longer update.

I finally have figured out the issue.

Working code:

#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#include <stdint.h>
#include "TouchScreen.h"

//Graphics Definitions

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

//TouchScreen definitions
#define YP A2
#define XM A3
#define YM 8
#define XP 9

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 0);

//Color Definitions
#define  BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

#define DEBUG

void setup(void) {
  tft.reset();
  
  Serial.begin(9600);

  uint16_t identifier = tft.readID();
  tft.begin(identifier);
}


void loop() {
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  //pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //pinMode(YM, OUTPUT);

    if (p.z - 20 > ts.pressureThreshhold) {
      tft.fillScreen(GREEN);
      Serial.println("!");
    }
    delay(100);
}

Hopefully this will help someone out in the future.

Seriously, it is always wise to say which display you are using e.g. a link to Ebay item. (e.g. like in message #1)
And where you got your libraries from. e.g. a link to the library downloads.

Most Adafruit libraries have been hacked with little indication of what has been altered, or what the hacker started with.

As far as I can remember, the official Adafruit tftpaint has an explicit note that you should restore XM and YP to outputs after every access to the TouchScreen if the Touch pins are shared with the TFT pins.

This is exactly what your “fix” has done. But you have not added ANY explanation.
Nor any explanation for your choice of XM, YP pins in the first place.

David.