XPT2046_Touchscreen - Library - Question around wiring up with Teensy 3.6

Status
Not open for further replies.

Erich

Member
Hi,
I bought a TFT TJCTM24024-SPI which uses a XPT2046 to manage the touchscreen.
luckely I found the Library for it at
https://github.com/PaulStoffregen/X...b/master/examples/ILI9341Test/ILI9341Test.ino
because of my small breadboard I tried to make mostly short wires and used some pins of my T36 near to the TFT to keep it with short wires.

I used Ping 29 for TIRQ_PIN and 28 for CS.
How to wire up T_D0, T_DIN and T_CLK??? I my case I did not wire them to anything.

Only using CS or CS and T_IRQ it does not detect any Touch-Event and shows only
X = 8191
Y = 8191
.. because of showing something, the display-hardware and the upload of code works fine.

ARDUINO 1.8.9

Here is the example which I changed in the Pinout for the TFT and the Touch.

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

// Touch-Pins
#define CS_PIN  28
#define TIRQ_PIN  29

// TFT-Pins
#define TFT_DC      20
#define TFT_CS      21
#define TFT_RST    255  // 255 = unused, connect to 3.3V
#define TFT_MOSI     7
#define TFT_SCLK    14
#define TFT_MISO    12

XPT2046_Touchscreen ts( CS_PIN, TIRQ_PIN );

// For the Adafruit shield, these are the default
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);



void setup() {
  Serial.begin(115000);
  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);
}
 
How to wire up T_D0, T_DIN and T_CLK??? I my case I did not wire them to anything.
Connect:
T_D0 to MISO pin 12
T_DIN to MOSI PIN 7 ... NOTE: this is alternate MOSI pin --- SPI.setMOSI(7); or use pin 11, It is by default mapped to (pin11)
T_CLK to SCK pin 14 ... NOTE: this is alternate SCK pin --- SPI.setSCK(14); or use pin 13, It is by default mapped to (pin13)
NOTE: Just so you know the Teensy audio library changes the pin setups.
 
Thank You, this was the right answer... now it works fine!
I changed the PINs in my test:

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

// #define CS_PIN 28
// #define TIRQ_PIN 29
// #include "Adafruit_GFX.h"
// #include "Adafruit_ILI9341.h"

#define TOUCH_IRQ 2
#define TOUCH_CS 8

#define TFT_DC 20
#define TFT_CS 21
#define TFT_RST 255 // 255 = unused, connect to 3.3V
#define TFT_MOSI 7
#define TFT_SCLK 14
#define TFT_MISO 12

XPT2046_Touchscreen ts( TOUCH_CS, TOUCH_IRQ );

// T_D0 to MISO pin 12
// T_DIN to MOSI PIN 11 ... NOTE: this is alternate MOSI pin --- SPI.setMOSI(7); or use pin 11, It is by default mapped to (pin11)
// T_CLK to SCK pPIN 14 ... NOTE: this is alternate SCK pin --- SPI.setSCK(14); or use pin 13, It is by default mapped to (pin13)
// NOTE: Just so you know the Teensy audio library changes the pin setups.

// For the Adafruit shield, these are the default.
// For optimized ILI9341_t3 library

ILI9341_t3 tft = ILI9341_t3( TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);


void setup() {
Serial.begin(115000 );
//Wait a bit for power to settle
delay(100);

tft.begin();
tft.setRotation(3);
tft.fillScreen(ILI9341_BLACK);

ts.begin();
ts.setRotation(3);

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.setTextSize(5);
tft.setFont(Arial_60);
tft.setCursor(60, 80);
tft.print("Touch");
}
tft.fillRect(100, 150, 140, 60, ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
// tft.setTextSize(5);
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.setTextSize(5);
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