2.8'' TFT Touchscreen not working

Hello,

I have a 2.8’’ TFT display with touchscreen and using the ili9341. I cannot manage to use the touch capability of the screen. The display works fine and shows all the information and shapes required (all the pins are connected to 3.3V).

I wrote a very simple code to show me the result of the function dataAvailable() of the library URtouch, which returns a 1 if a touch is detected and 0 if not. Using the serial monitor, I am able to print the result of the dataAvailable() function and it is equal to 1 all the time, even though I might not be touching it.

The display I am using is https://www.amazon.de/gp/product/B07L4RVP5L/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1.

Here is the code:

#include <URTouch.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>

//Pines TFT
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8

//Pines Touch
#define t_SCK 3
#define t_CS 4
#define t_MOSI 5
#define t_MISO 6
#define t_IRQ 7

//TFT instantiation
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

//Touch instantiation
URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ);

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

//TFT configuration
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLUE);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(3);
tft.setCursor(80,5);
tft.print("Touch test ");

//Touch configuration
ts.InitTouch();
ts.setPrecision(PREC_MEDIUM);
}

void loop()
{
Serial.println(ts.dataAvailable());

if(ts.dataAvailable())
{
ts.read();
x = ts.getX();
y = ts.getY();
Serial.print("X = “);
Serial.print(x);
Serial.print(”\t Y = ");
Serial.println(y);
if((x!=-1) && (y!=-1))
{
int radius = 3;
tft.fillCircle(x, y, radius, ILI9341_BLACK);
}
}
}

Not only the result of the function ts.dataAvailable() is always 1, but the values of x and y are -1. I think these are separate issues, but in any case the touch screen is not properly communicating if it is being touched or not.

Any ideas about how I could solve this?

Thank you in advance

Look at the photo of the pcb in your Amazon link. U2 is not mounted. So there is no Touch.

Buy the version with U2. They are not expensive.

If you want to use the Adafruit code, you should buy the Adafruit touchscreen.

-jim lee

Thank you for your answers.

I finally bought a display with the U2 chip mounted and the touchscreen now is responding. However, the function dataAvailable() still reads always 1. Shouldn't it read 0 unless I touch the screen?

Kind regards,
Pablo

Personally, I always put all SPI devices on the hardware SPI bus. e.g. with XPT2046_TouchScreen.h library

I believe that TFTLCDCyg uses SPI for TFT and bit-bashes XPT2046 with URTouch
He will probably reply later.

Bear in mind that URTouch.h has no conception of hardware SPI. You must never mix SW SPI and HW SPI on the same pins.

Also note that URTouch does unusual things with the tIRQ pin.
You need to ask Mr Karlsen why.

David.

I would concur with favouring the use of the XPT2046_TouchScreen.h library.

It runs on the SPI bus, so only needs one extra IO pin to work, CS. Some touch libraries use bit bash bop and need a least 3 more IO pins.

XPT2046_TouchScreen.h was conceived to use the same sketch format as Adafruits touch library so programs such as the Adafruit touchpaint example are easy to modify.