ILI9341 with XPT2046_Touchscreen

Status
Not open for further replies.

jshooks

Well-known member
I received three new ILI9341 Displays from PJRC. The screen displays the same graphics buttons as the older ILI9341 units. However, the touch screen appears to have X/Y indexing that is a mirror image of the original using the same touch code. In other words touch buttons displayed on lower right are activated in a different location on the screen. Has the indexing been changed on the newer panels? Has anyone experienced this same issue?
 
Possible the assembly or setup changed.

Try a call to :: setRotation(uint8_t n) { rotation = n % 4; }

Find the rotation that syncs with display rotation.
 
Or simply you need to do a new calibration for the display touch and change the mappings.

As for the question of if PJRC received a new batch of these which are different... Not sure.
 
defragster
Possible the assembly or setup changed.
I also had this issue before :eek:

From the Arduino Software (IDE) toolbar menu: File > Examples > XPT2046_Touchscreen > ILI9341Test
in setup()
tft.setRotation(1); // Screen rotation 1~4
ts.setRotation(1); // Touch rotation 1~4

Code:
#include <ILI9341_t3.h>
#include <font_Arial.h> // from ILI9341_t3
#include <XPT2046_Touchscreen.h>
#include <SPI.h>

#define CS_PIN  8
#define TFT_DC  9
#define TFT_CS 10
// MOSI=11, MISO=12, SCK=13

XPT2046_Touchscreen ts(CS_PIN);
#define TIRQ_PIN  2
//XPT2046_Touchscreen ts(CS_PIN);  // Param 2 - NULL - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, 255);  // Param 2 - 255 - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN);  // Param 2 - Touch IRQ Pin - interrupt enabled polling

ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);

void setup() {
  Serial.begin(38400);
  tft.begin();
  tft.setRotation(1);
  tft.fillScreen(ILI9341_BLACK);
  ts.begin();
  ts.setRotation(1);
  while (!Serial && (millis() <= 1000));
}

boolean wastouched = true;

void loop() {
  boolean istouched = ts.touched();
  if (istouched) {
    TS_Point p = ts.getPoint();
    if (!wastouched) {
      tft.fillScreen(ILI9341_BLACK);
      tft.setTextColor(ILI9341_YELLOW);
      tft.setFont(Arial_60);
      tft.setCursor(60, 80);
      tft.print("Touch");
    }
    tft.fillRect(100, 150, 140, 60, ILI9341_BLACK);
    tft.setTextColor(ILI9341_GREEN);
    tft.setFont(Arial_24);
    tft.setCursor(100, 150);
    tft.print("X = ");
    tft.print(p.x);
    tft.setCursor(100, 180);
    tft.print("Y = ");
    tft.print(p.y);
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.println(p.y);
  } else {
    if (wastouched) {
      tft.fillScreen(ILI9341_BLACK);
      tft.setTextColor(ILI9341_RED);
      tft.setFont(Arial_48);
      tft.setCursor(120, 50);
      tft.print("No");
      tft.setCursor(80, 120);
      tft.print("Touch");
    }
    Serial.println("no touch");
  }
  wastouched = istouched;
  delay(100);
}
 
Status
Not open for further replies.
Back
Top