How to do I troubleshoot the touch part of the 2.8 ILI9341?

Status
Not open for further replies.

Daveed

Member
I installed the optimize library https://github.com/PaulStoffregen/XPT2046_Touchscreen.
and the DemoSause sketch runs great on the screen, but the touchscren is not working.
When I run the "onoffbutton" sketch, the graphics shows up but I get: "Unable to start touchscreen" on the Serial monitor, and not response to touch on the display.

I don't know if this mean anything but here is the result of "graphictest"

ILI9341 Test!
Display Power Mode: 0x80
MADCTL Mode: 0x0
Pixel Format: 0x0
Image Format: 0x80
Self Diagnostic: 0x0

I read the two threads on this board on the ILI9341 but I can't find the answer to my question:
How can I trouble shoot the touchscreen portion of the ILI9341?
Can somebody here please help?
 
Where did you get the ILI9341? Just wondering if you have the common unit - check your pics against the PJRC store maybe if not from there. Check your wiring to be right - and that the sketch specifies them like that by pin_#. It shares the common SPI pins and crossing them up at all won't be right. I don't recall seeing that error or what may have led to it - I haven't used that for almost 1.5 years.
 
I bought it from PJRC.com. I checked the wiring, it seems right. Do I need any type of pull up?
I notice than when I pull out pin 11 TDIN, the on/off graphic button on the screen goes back and forth.
Also shouldn't pin 12(DIM) be connected to T_DIM?. I uploaded a picture that explains what I mean
 

Attachments

  • pinOut.pdf
    39.4 KB · Views: 151
You aren't using the purple board to plug these together? I have several of these, also with Ethernet added (which means remapping the TFT CS and DC signals), running test code. The purple boards make using these really convenient.

SPI doesn't need pullups.

The display's data in has to come from Teensy data out, and vice versa. Like old serial comms: one device data out has to talk to the other data input.

These displays use the ADS7843/XPT2046 for resistive touch, which is also SPI, it just has a separate chip select for the touch and the display.
 
Last edited:
KurtE
Actually, that worked, I didn't have to change the pins or change anything, I worked just like that the first time.
Thanks so much!

So there is something about the "onoffbutton" example that is not working on this card.
 
Last edited:
You aren't using the purple board to plug these together?
I am not sure which one is the purple board, I'm using a breadboard and jumper cables to connect the teensy to the screen.

Just now I used the example that KurtE suggested above and it worked, perfectly. So I guess that means that the hardware is working and connected properly. However, the question now is trying to zero in what is different about KurtE code that it actually makes it work.

Thank you so much for answering all my questions. I'm just trying to learn enough to keep myself busy.

Cheers
 
Last edited:
Almost working.

I got the "OffOnButton" example working by borrowing from KurtE's example.

Code:
#include <SPI.h>
#include <Wire.h>
#include <ILI9341_t3.h>
//#include <Adafruit_STMPE610.h>
//added this library
#include <XPT2046_Touchscreen.h>

The problem now is that the touch area doesn't correspond with the graphic on the screen (it's probably something obvious that I'm missing)

The square button appears on the bottom right but the touch area is at the bottom left and on the code is annotated indicating that t is suppose to be top left. Obviously I have a few cables crossed. Can anybody help figure this out?
Please.



Code:
//This example implements a simple sliding On/Off button. The example
// demonstrates drawing and touch operations.
//
//Thanks to Adafruit forums member Asteroid for the original sketch!
//
#include <SPI.h>
#include <Wire.h>
#include <ILI9341_t3.h>
//#include <Adafruit_STMPE610.h>
//added this library
#include <XPT2046_Touchscreen.h>


// This is calibration data for the raw touch data to the screen coordinates
//#define TS_MINX 150
//#define TS_MINY 130
//#define TS_MAXX 3800
//#define TS_MAXY 4000

//cut and pasted / didn't notice any change
#define TS_MINX 337
#define TS_MINY 529
#define TS_MAXX 3729
#define TS_MAXY 3711


// cut and pasted
#define TFT_DC  9
#define TFT_CS 10
#define TFT_RST 7
#define TFT_SCK 13
#define TFT_MISO 12
#define TFT_MOSI 11

#define TOUCH_CS  8

XPT2046_Touchscreen ts(TOUCH_CS);
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCK, TFT_MISO);
//end cut and pasted


//original code
/*
#define STMPE_CS 8
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
#define TFT_CS 10
#define TFT_DC  9
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
*/
boolean RecordOn = false;

#define FRAME_X 210
#define FRAME_Y 180
#define FRAME_W 100
#define FRAME_H 50

#define REDBUTTON_X FRAME_X
#define REDBUTTON_Y FRAME_Y
#define REDBUTTON_W (FRAME_W/2)
#define REDBUTTON_H FRAME_H

#define GREENBUTTON_X (REDBUTTON_X + REDBUTTON_W)
#define GREENBUTTON_Y FRAME_Y
#define GREENBUTTON_W (FRAME_W/2)
#define GREENBUTTON_H FRAME_H

void drawFrame()
{
  tft.drawRect(FRAME_X, FRAME_Y, FRAME_W, FRAME_H, ILI9341_BLACK);
}

void redBtn()
{ 
  tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_RED);
  tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_BLUE);
  drawFrame();
  tft.setCursor(GREENBUTTON_X + 6 , GREENBUTTON_Y + (GREENBUTTON_H/2));
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
  tft.println("ON");
  RecordOn = false;
}

void greenBtn()
{
  tft.fillRect(GREENBUTTON_X, GREENBUTTON_Y, GREENBUTTON_W, GREENBUTTON_H, ILI9341_GREEN);
  tft.fillRect(REDBUTTON_X, REDBUTTON_Y, REDBUTTON_W, REDBUTTON_H, ILI9341_BLUE);
  drawFrame();
  tft.setCursor(REDBUTTON_X + 6 , REDBUTTON_Y + (REDBUTTON_H/2));
  tft.setTextColor(ILI9341_WHITE);
  tft.setTextSize(2);
  tft.println("OFF");
  RecordOn = true;
}

void setup(void)
{
  Serial.begin(9600);
  tft.begin();
  if (!ts.begin()) { 
    Serial.println("Unable to start touchscreen.");
  } 
  else { 
    Serial.println("Touchscreen started."); 
  }

  tft.fillScreen(ILI9341_BLUE);
  // origin = left,top landscape (USB left upper)
  tft.setRotation(1); 
  redBtn();
}

void loop()
{
  // See if there's any  touch data for us
  if (!ts.bufferEmpty())
  {   
    // Retrieve a point  
    TS_Point p = ts.getPoint(); 
    // Scale using the calibration #'s
    // and rotate coordinate system
    p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
    p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());
    int y = tft.height() - p.x;
    int x = p.y;

    if (RecordOn)
    {
      if((x > REDBUTTON_X) && (x < (REDBUTTON_X + REDBUTTON_W))) {
        if ((y > REDBUTTON_Y) && (y <= (REDBUTTON_Y + REDBUTTON_H))) {
          Serial.println("Red btn hit"); 
          redBtn();
        }
      }
    }
    else //Record is off (RecordOn == false)
    {
      if((x > GREENBUTTON_X) && (x < (GREENBUTTON_X + GREENBUTTON_W))) {
        if ((y > GREENBUTTON_Y) && (y <= (GREENBUTTON_Y + GREENBUTTON_H))) {
          Serial.println("Green btn hit"); 
          greenBtn();
        }
      }
    }

    Serial.println(RecordOn);
  }  
}
 
Yes the touch screen and the display have two different sets of coordinates, so in the example code which I did on one of my displays, there is code
in the loop function that looks like:

Code:
void loop()
{
  // See if there's any  touch data for us
  if (ts.bufferEmpty()) {
    return;
  }

  // You can also wait for a touch
  /*
  if (! ts.touched()) {
    return;
  }
*/

  // Retrieve a point
  TS_Point p = ts.getPoint();

  // p is in ILI9341_t3 setOrientation 1 settings. so we need to map x and y differently.
/*
  Serial.print("X = "); Serial.print(p.x);
  Serial.print("\tY = "); Serial.print(p.y);
  Serial.print("\tPressure = "); Serial.print(p.z);
*/

  // Scale from ~0->4000 to tft.width using the calibration #'s
#ifdef SCREEN_ORIENTATION_1
  p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
  p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
#else
  
  uint16_t px = map(p.y, TS_MAXY, TS_MINY, 0, tft.width());
  p.y = map(p.x, TS_MINX, TS_MAXX, 0, tft.height());
  p.x = px;
#endif
/*  
    Serial.print(" ("); Serial.print(p.x);
    Serial.print(", "); Serial.print(p.y);
    Serial.println(")");
*/
You will notice two two sections of print that are commented out. This is simply getting the raw input data and printing it and then using the map function to try to map this into screen coordinates.

The more accurate you can get the MIN/MAX values the more accurate the conversion will be. Also the conversion depends on what screen orientation you set the screen into. Portrait mode will be different than landscape mode...

There have been a few other postings on doing this conversion. I believe @defragster has one as well...
 
Status
Not open for further replies.
Back
Top