ILI9341 Touchscreen stuck on 0,0.

sleitman

Member
Hello,

I have made a new PCB board for a project that I am working on that uses both the Audio shield and the touchscreen sold by PJRC.

In this newest version, I have used a 4.0 instead of a 4.1 while keeping the same pin routing as with the 4.0. The code for that routing can be found below.

The screen works great but the touch is set on maximum pressure at one of the corners (top left if you are orienting the screen as seen in the font examples on this page. (https://www.pjrc.com/store/display_ili9341_touch.html). This corner remains the "touched" corner regardless of screen and touchscreen orientation. It is always that corner. I have tried swapping out screens and 2 screens get the same result.


I have tried Examples->XPT2046->TouchTest or ILI9341Test and gotten the same result.

I have examined my board over and over and checked the pin routing. If anyone has any suggestions about were I should look for errors, I would be very grateful. I read a similar issue having to do with Chip Select choices but as far as I can tell, I can use any pin for chip select with these two libraries ( <ILI9341_t3.h> and <XPT2046_Touchscreen.h>)


Thank you in advance for any clues you might be able to offer.

Sasha


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

//added libraries
#include <SerialFlash.h>
#include <Audio.h>
#include <SD.h>

//Screen
#define TFT_DC 3
#define TFT_CS 0
#define TFT_RST 255 // 255 = unused, connect to 3.3V
#define TFT_MOSI 11
#define TFT_SCLK 13
#define TFT_MISO 12

//Touch
#define CS_PIN 9
XPT2046_Touchscreen ts(CS_PIN);
 
Note the touch controller will always have the same coordinates for a physical location on the screen regardless of how you set the orientation of the display.

You need to have software map the touch location to pixel or like, by software.

I have poor example of this in example sketch in my version of display library

https://github.com/KurtE/ILI9341_t3...ouchpaint_xpt2046/touchpaint_xpt2046.ino#L175
It only handles 2 orientations. I think @defragster has a better example?
 
Thanks, Kurt. I think that in the example code for the XPT2046_Touchscreen.h library, there is an orientation for both the touch and the screen. The values of where it is being "touched" change correspondingly for me.

I will run your code but I think what I was getting at was that the place where it was touched "seems" to be either the first or last touch point. I don't know if that is useful information but it is just one of the few data points I can find while trying to figure this out.
 
Hello,

I have made a new PCB board for a project that I am working on that uses both the Audio shield and the touchscreen sold by PJRC.

In this newest version, I have used a 4.0 instead of a 4.1 while keeping the same pin routing as with the 4.0. The code for that routing can be found below.

The screen works great but the touch is set on maximum pressure at one of the corners (top left if you are orienting the screen as seen in the font examples on this page. (https://www.pjrc.com/store/display_ili9341_touch.html). This corner remains the "touched" corner regardless of screen and touchscreen orientation. It is always that corner. I have tried swapping out screens and 2 screens get the same result.


I have tried Examples->XPT2046->TouchTest or ILI9341Test and gotten the same result.

I have examined my board over and over and checked the pin routing. If anyone has any suggestions about were I should look for errors, I would be very grateful. I read a similar issue having to do with Chip Select choices but as far as I can tell, I can use any pin for chip select with these two libraries ( <ILI9341_t3.h> and <XPT2046_Touchscreen.h>)


Thank you in advance for any clues you might be able to offer.

Sasha


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

//added libraries
#include <SerialFlash.h>
#include <Audio.h>
#include <SD.h>

//Screen
#define TFT_DC 3
#define TFT_CS 0
#define TFT_RST 255 // 255 = unused, connect to 3.3V
#define TFT_MOSI 11
#define TFT_SCLK 13
#define TFT_MISO 12

//Touch
#define CS_PIN 9
XPT2046_Touchscreen ts(CS_PIN);

Take a look at the following <URL> (gives pinout info for the case when using both the Audio Adapter & the PJRC ILI9341 touchscreen display), particularly the column labeled "Teensy 3.x and 4.4 Standard", which shows that pin 9 is normally used as D/C. If your setup includes the easy ability to change the wiring connections, you might try the pins listed there & see what kind of luck you have using those recommendations.

Hope that helps !!

Mark J Culross
KD5RXT
 
Hi Mark,

My PCB definitely does not include the ability to change the pins but these pin allocations were working great in my last pcb with the 4.0.

Is there a reason that D/C would need to be on pin 3 for 4.0?

I have always found the table on the link you shared confusing because it includes pins for 3.x with audio shield but the 4.x without audio shield. That was why I ended up using the pin set up below.

This is my pin set up.

PinsForPJRC.jpg
 
As indicated earlier, the referenced table gives the specific pins to be used (and which work) with both the Audio Shield & the PJRC ILI9341 touchscreen display. Your pinout list has pin assignments that conflict with the info in the table !!

Since you say that the table is confusing, <here's> another post with an interpretation on how to read the table properly.

And, as stated in my earlier post, D/C is on pin 9, not on pin 3 . . . not sure why you ask "Is there a reason that D/C would need to be on pin 3 for 4.0?"

Sounds like you need to put your PCB aside for a bit & connect everything (strictly per the table) on a prototyping setup & get the simple examples working, then go forward from there.

Hope that helps . . .

Mark J Culross
KD5RXT
 
Here are the #include directives & a few pin definitions (including my specific pin list) for an intermediate version of my TeensyMIDIPolySynth project which used both the Audio Adapter & the PJRC ILI9341 touchscreen display. Note that I was specifically using the ILI9341_t3n library (providing the advantage of a frame buffer).

Code:
#include <ILI9341_t3n.h>
#include <XPT2046_Touchscreen.h>
#include <USBHost_t36.h>
#include <MIDI.h>
#include <EEPROM.h>
#include <Audio.h>


// when used w/ Audio Adapter, must use an alternate CS pin for the display
const int TFT_CHIP_SELECT = 14;
const int TFT_DATA_COMMAND = 9;
ILI9341_t3n tft = ILI9341_t3n(TFT_CHIP_SELECT, TFT_DATA_COMMAND);

// create TFT framebuffer
DMAMEM uint16_t framebuf[320 * 240];

// when used w/ Audio Adapter, must use an alternate CS pin for the touchscreen
#define TS_CS_PIN  5

XPT2046_Touchscreen ts(TS_CS_PIN, 255);

//
// The following pins are used in this project:
//
// PIN  D1  = (not used)
// PIN  D2  = (not used)
// PIN  D3  = (not used)
// PIN  D4  = (not used)
// PIN  D5  = TouchScreen chip select (alternate when used w/ audio adapter)
// PIN  D6  = Audio adapter memory chip select
// PIN  D7  = Audio adapter data in
// PIN  D8  = Audio adapter data out
// PIN  D9  = TFT/TS data/command select
// PIN D10  = Audio adapter SD card chip select
// PIN D11  = SPI MOSI (data in)
// PIN D12  = SPI MISO (data out)
// PIN D13  = SPI serial clock + on-board LED
// PIN  A0  = (D14) TFT chip select (alternate when used w/ audio adapter)
// PIN  A1  = Volume pot on audio adapter
// PIN  A2  = (not used)
// PIN  A3  = (not used)
// PIN  A4  = (D18) Audio adapter SDA (I2C control data)
// PIN  A5  = (D19) Audio adapter SCL (I2C control clock)

// onboard LED on pin 13
#define LED_PIN 13
 
I have the same issue.

My setup is described here https://forum.pjrc.com/threads/71367-T4-1-ILI9431_t3-(2-4-quot-display)-inverted-colors , it's the same as in PJRC page: https://www.pjrc.com/store/display_ili9341_touch.html

I am testing with Teensy 4.1 (Arduino IDE 1.8.19 + TD 1.57) using "Examples->XPT_2046_Touchscreen->ILI9431test"

Sample sketch code:

Code:
/*
 * Wiring with T4.1:
 * 
 * Screen Teensy
 * Vcc    Vin (up to 5.5V is OK)
 * GND    GND
 * CS     10
 * RESET  3V3
 * D/C    9
 * MOSI   11
 * SCK    13 (yes, we cannot use onboard LED anymore)
 * LED    3V3 (also works with Vin)
 * MISO   12
 * T_CLK  13 (shared with SCK)
 * T_CS   8
 * T_DIN  11 (shared with MOSI)
 * T_DO   12 (shared with MISO) 
 * T_IRQ  2
 */


#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
#define TIRQ_PIN 2
// MOSI=11, MISO=12, SCK=13

XPT2046_Touchscreen ts(CS_PIN);
//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.invertDisplay(false);
  tft.setRotation(1);
  tft.fillScreen(ILI9341_BLACK);
  ts.begin();
  ts.setRotation(1);
  while (!Serial && (millis() <= 5000));
}

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 
  { // not touched
    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(250);
}

Printed coordinates are always

X = 0
Y = 0

both on screen and on the Serial Monitor

Any hint?
Thanks!

Fernando
 
If you are using an Audio board, you will see that pin 8 is used by the Audio board.

Screenshot.png
 
I have the same issue.

My setup is described here https://forum.pjrc.com/threads/71367-T4-1-ILI9431_t3-(2-4-quot-display)-inverted-colors , it's the same as in PJRC page: https://www.pjrc.com/store/display_ili9341_touch.html

I am testing with Teensy 4.1 (Arduino IDE 1.8.19 + TD 1.57) using "Examples->XPT_2046_Touchscreen->ILI9431test"

Sample sketch code:

Code:
/*
 * Wiring with T4.1:
 * 
 * Screen Teensy
 * Vcc    Vin (up to 5.5V is OK)
 * GND    GND
 * CS     10
 * RESET  3V3
 * D/C    9
 * MOSI   11
 * SCK    13 (yes, we cannot use onboard LED anymore)
 * LED    3V3 (also works with Vin)
 * MISO   12
 * T_CLK  13 (shared with SCK)
 * T_CS   8
 * T_DIN  11 (shared with MOSI)
 * T_DO   12 (shared with MISO) 
 * T_IRQ  2
 */

Any hint?
Thanks!

Fernando

Try pin 5 for (touchscreen) CS_PIN & alternately pin 14 (A0) for (TFT) CS (leaving the Audio Adapter SD CS free - not that you'll likely ever use that !!). For the touchscreen, you could use the explicit "XPT2046_Touchscreen ts(CS_PIN, 255);" form of the declaration as a reminder that interrupts are not used.

Give that a try & let us know how it goes . . .

Mark J Culross
KD5RXT
 
Try pin 5 for (touchscreen) CS_PIN & alternately pin 14 (A0) for (TFT) CS (leaving the Audio Adapter SD CS free - not that you'll likely ever use that !!). For the touchscreen, you could use the explicit "XPT2046_Touchscreen ts(CS_PIN, 255);" form of the declaration as a reminder that interrupts are not used.

Give that a try & let us know how it goes . . .

I moved the touch_cs pin to 5 and changed the code, as per your suggestion, to:

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

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

// XPT2046_Touchscreen ts(CS_PIN);
//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.invertDisplay(false);
  tft.setRotation(1);
  tft.fillScreen(ILI9341_BLACK);
  ts.begin();
  ts.setRotation(1);
  while (!Serial && (millis() <= 5000));
}

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 
  { // not touched
    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(250);
}

Nothing changed: it does not even register the touch ("touched" never printed to Serial Monitor). :(
Screen works OK but no touch.

Edit: also tried moving TFT_CS from 10 to 14, still no touch.
Any possibility XPT_2046 touch driver is broken in TD 1.57?
Did anyone successfully used 9341 + 2046 with T4.1 at all using latest TeensyDuino?
 
Last edited:
Any possibility XPT_2046 touch driver is broken in TD 1.57?
Did anyone successfully used 9341 + 2046 with T4.1 at all using latest TeensyDuino?

I have a setup that uses all those pieces along with the audio adapter and there is no issue with the touch working. I am using TD 1.57 and latest ver 1.4.0 of the library

For what it's worth, here are the connections I am using on the display. I am not using the T_IRQ pin.
Prototyping System for Teensy 4.1 LCD Display Schematic.png
 
Update: I purchased a new 2.8" display (the non-working one was 2.4") and this one works perfectly, touch included.

So I have a faulty 2.4" display, or maybe one that, despite being advertised as having a XPT_2046 touch driver, is equipped with a different chip instead (can't read the writings).
 
...or maybe one that, despite being advertised as having a XPT_2046 touch driver, is equipped with a different chip instead (can't read the writings).

The STMPE610 is another popular touch controller (before I moved over the the PJRC touchscreen, I previously used the Adafruit 2.8" capacitive touchscreen which employs the STMPE610 as the touch controller). Maybe you could try the Adafruit STMPE610 library & see if that might somehow work with your touchscreen display before giving up on it completely.

Mark J Culross
KD5RXT
 
Back
Top