ILI9488 & XPT2046 Issue

JimSoft

Member
I'm trying to connect a cheap 4" TFT from AliExpress which has an ILI9488 display and an XPT2046 touchscreen with a Teensy 4.1 (this has two additional PSRAM chips fitted but I doubt this is relevant).
I have the LCD connected to SPI0 and touch to SPI1 with pinouts detailed at the start of the code below.
The bizarre issue is when the tft.fillScreen(ILI9488_BLACK) line is uncommented I get spurious touch responses, this doesn't happen when the other colours (red, green or blue) code lines are used instead!

Code:
#include <ILI9488_t3.h>
#include <XPT2046_Touchscreen.h>

#define TFT_RST        8
#define TFT_DC         9
#define TFT_CS         10
#define TFT_MOSI     11
#define TFT_MISO     12
#define TFT_CLK        13
ILI9488_t3 tft = ILI9488_t3(10, TFT_DC, TFT_RST, TFT_MOSI, TFT_CLK, TFT_MISO);

#define TS_CS           0
#define TS_MISO      1
#define TS_MOSI      26
#define TS_CLK         27
XPT2046_Touchscreen ts(TS_CS);

void setup() {
  Serial.begin(921600);
  tft.begin();
  tft.fillScreen(ILI9488_BLACK);
  //tft.fillScreen(ILI9488_RED);
  //tft.fillScreen(ILI9488_GREEN);
  //tft.fillScreen(ILI9488_BLUE);
  ts.begin(SPI1);
  while (!Serial && (millis() <= 1000));
}

void loop() {
  if (ts.touched()) {
    TS_Point p = ts.getPoint();
    Serial.print("Pressure = ");
    Serial.print(p.z);
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.print(p.y);
    delay(30);
    Serial.println();
  }
}

Output with no touches and black screen is as follows:

10:13:49.794 -> ::begin 0 11 12 13
10:13:49.794 -> MOSI:11 MISO:12 SCK:13
10:13:49.794 -> ILI9488_t3::begin - End
10:13:50.287 -> Pressure = 422, x = 1577, y = 2251
10:13:50.334 -> Pressure = 434, x = 1576, y = 2253
10:13:50.402 -> Pressure = 436, x = 1573, y = 2244
10:13:50.647 -> Pressure = 338, x = 1576, y = 2254
10:13:50.785 -> Pressure = 357, x = 1575, y = 2251
10:13:50.852 -> Pressure = 438, x = 1575, y = 2251
10:13:50.985 -> Pressure = 363, x = 1577, y = 2251
10:13:51.019 -> Pressure = 323, x = 1578, y = 2251
10:13:51.086 -> Pressure = 335, x = 1575, y = 2252
10:13:51.186 -> Pressure = 301, x = 1574, y = 2244
10:13:51.285 -> Pressure = 392, x = 1577, y = 2253
10:13:51.319 -> Pressure = 346, x = 1576, y = 2243

Thanks for any help.
 
Some additional information,

Setting the fillScreen colour to Black, Navy, Darkgreen and Maroon all cause the same issue, using any other colour the touchscreen works fine!
Using fillRect to draw a background also has the same effect on the touchscreen behaviour.

Using library ILI9488_t3 at version 1.0
Using library SPI at version 1.0
Using library XPT2046_Touchscreen at version 1.4

I split the SPI ports, LCD on SPI0 and touch on SPI1 as above to try and isolate the issue without any success.
 
With cases like this, it often helps to post additional information.
Things like:

What version of Arduino/Teensy code you are using.

Some of the compiler stuff at the end, like using library X and not Y...
My output for it shows:
Code:
"C:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-tools\\0.60.3/stdout_redirect" "C:\\Users\\kurte\\AppData\\Local\\Temp\\arduino\\sketches\\FA3E58E7FC5A12C6FBDD83525B618266/sketch_oct9b.ino.lst" "C:\\Users\\kurte\\AppData\\Local\\Arduino15\\packages\\teensy\\tools\\teensy-compile\\11.3.1/arm/bin/arm-none-eabi-objdump" -d -S -C "C:\\Users\\kurte\\AppData\\Local\\Temp\\arduino\\sketches\\FA3E58E7FC5A12C6FBDD83525B618266/sketch_oct9b.ino.elf"
Multiple libraries were found for "ILI9488_t3.h"
  Used: D:\github\ILI9488_t3
  Not used: C:\Users\kurte\AppData\Local\Arduino15\packages\teensy\hardware\avr\0.60.3\libraries\ILI9488_t3
Multiple libraries were found for "XPT2046_Touchscreen.h"
  Used: C:\Users\kurte\Documents\Arduino\libraries\XPT2046_Touchscreen
  Not used: C:\Users\kurte\AppData\Local\Arduino15\packages\teensy\hardware\avr\0.60.3\libraries\XPT2046_Touchscreen
Using library ILI9488_t3 at version 1.0 in folder: D:\github\ILI9488_t3

Pictures of your setup. Maybe there is a wire on the wrong pin, or the IO pins are not soldered or look like they may be loose. and/or
shorted. There is other hardware like Audio or ...

Code wise things to try:

Maybe verify that the Touch started properly...
Code:
while (!Serial && (millis() <= 1000))
        ;
    if !( ts.begin(SPI1)) {
        Serial.println("Touch screen failed");
    }
Added the test for return value, plus moved the wait for Serial port ahead of it so it is likely to be able to print this out if it failed.

Maybe pre initiative all of the CS pins to high before you start the display and/or touch.
Code:
void setup() {
    Serial.begin(921600);
    pinMode(ts_CS, OUTPUT);
    digitalWrite(TS_CS, HIGH);
    pinMode(TFT_CS, OUTPUT);
    digitalWrite(TFT_CS, HIGH);

    tft.begin();
...
This helps if some of these devices don't have Pull up resistors on their CS pin, and potentially floating...
 
Back
Top