2.8" TFT Touch Down Event

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
figgyb
 
Posts: 41
Joined: Wed Mar 17, 2010 5:19 pm

2.8" TFT shield - touch buffer issues

Post by figgyb »

I seem to always have bad data in my touch buffer, and suspect I am missing something. I noticed in the example sketch, the following
ts.writeRegister8(STMPE_INT_STA, 0xFF); // reset all ints
but there was no explanation as to what it does. What does it do? Is it related to the ts buffer?

Thanks!

User avatar
figgyb
 
Posts: 41
Joined: Wed Mar 17, 2010 5:19 pm

Re: 2.8" TFT shield - touch buffer issues

Post by figgyb »

Sample code. This is multiple presses in to the menu and always kicks back an old value :(

Code: Select all

//table showing cell mv readings with yellow button area on top
void startChartData(O2Sensor Cells[], PressureSensor P1)
{
  unsigned long prevTime = 0;
  
  //set first cell to plot
  uint8_t activeCell = 1;
  
  //refresh sensor data
  getCell_mV(Cells); 
  getPressure(P1);

  setupLCD_chartData(Cells, activeCell);
  printChartData(Cells, activeCell);

  while (1) {

    if(millis() - prevTime > 1000) {
      //refresh sensor data
      getCell_mV(Cells); 
      getPressure(P1);  
      
      //print current cell mv on table row 1
      tft.setTextColor(ILI9341_BLUE);
      tft.fillRect(90, 79, 70, 15, ILI9341_BLACK);
      tft.setCursor(100, 79); tft.print(Cells[activeCell-1].mV);
      
      //print pressure in yellow button area
      tft.setTextColor(ILI9341_RED);
      tft.fillRect(253, 21, 60, 15, ILI9341_YELLOW);
      tft.setCursor(253, 21); tft.print(convertkPa(P1.pressure, ATA), 3);

      
      prevTime = millis();
    }
    
    if (touch.touched()) {
      int x = 0;
      int y = 0;
      while (! touch.bufferEmpty()) {
        //cycle through all to select last coordinates for finger lift
        mapTouchscreen(x, y);
        Serial.print("map> "); Serial.print(x); Serial.print(", "); Serial.println(y);
      }
      
      if (x < 75 && y < 80) {
        // Mark selected
        Serial.println("Lock selected");
        Serial.print("used> "); Serial.print(x); Serial.print(", "); Serial.println(y);
        chartData_SavePoint(Cells, P1, activeCell);
      }
      else if (x > 85 && x < 155 && y < 80) {
        // Clear Selected
        Serial.println("Graph cells selected");
        Serial.print("used> "); Serial.print(x); Serial.print(", "); Serial.println(y);

        //clear cell pts
        //redraw screen
        //draw linear
      }
      else if (x > 165 && x < 235 && y < 80) {
        //swap cells selected
        Serial.println("swap cells selected");
        Serial.print("used> "); Serial.print(x); Serial.print(", "); Serial.println(y);
        activeCell++;
        if(activeCell > 3) activeCell = 1;
        printChartData(Cells, activeCell);
      }
      else break;
    }
  }
}

void mapTouchscreen(int &x, int &y)
{
  //TS_Point p = touch.getPoint();
  uint16_t y1=0;
  uint16_t x1=0;
  uint8_t z1=0;
  touch.readData(&x1, &y1, &z1);
  
  //p.x = map(p.x, TS_MINY, TS_MAXY, 0, tft.height());
  //p.y = map(p.y, TS_MINX, TS_MAXX, 0, tft.width());
  //y = tft.height() - p.x;
  //x = p.y;
  x1 = map(x1, TS_MINY, TS_MAXY, 0, tft.height());
  y1 = map(y1, TS_MINX, TS_MAXX, 0, tft.width());
  y = tft.height() - x1;
  x = y1;
  
  //Serial.print("ori> "); Serial.print(p.x); Serial.print(", "); Serial.println(p.y);
  Serial.print("map> "); Serial.print(x); Serial.print(", "); Serial.println(y);
}

User avatar
figgyb
 
Posts: 41
Joined: Wed Mar 17, 2010 5:19 pm

Re: 2.8" TFT shield - touch buffer issues

Post by figgyb »

Anyone?

User avatar
asteroid
 
Posts: 300
Joined: Tue Oct 22, 2013 9:10 pm

2.8" TFT Touch Down Event

Post by asteroid »

The following source code template was recently published on this forum as a way to trap 'touch down' events ( I added some code to it in order to create a runnable demo). However, I am unable to get it to work correctly. If the screen is touched in all four corners starting in the left lower and going clockwise (USB on right) this record may be generated:

X = 65527 Y = 65526
X = 231 Y = 285
==================
X = 229 Y = 290
X = 19 Y = 297
==================
X = 17 Y = 298
X = 17 Y = 21
==================
X = 16 Y = 20
X = 228 Y = 13

Note that each corner has to be touched twice in order to get the correct value (shown in red). Furthermore, the initial touch down event is incorrect. The 'current' touch down event is actually reporting the one immediately preceding it, and is always one behind. Any help would be appreciated. The source code follows:

Code: Select all

/*
  Demonstrates "touch down" event
  UNO + 2.8 TFT Touch Shield - v2
  USB in right lower corner
*/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_STMPE610.h>

// Default values for Adafruit shield v2.
#define STMPE_CS 8
#define TFT_DC 9
#define TFT_CS 10

Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

 #define TS_MINX 150
 #define TS_MINY 130
 #define TS_MAXX 3800
 #define TS_MAXY 4000
 
void setup() 
{
  Serial.begin(9600);
  tft.begin();
  ts.begin();  
}

void loop()
{  
  uint16_t x = 0;
  uint16_t y = 0;

  TS_Point p = ts.getPoint();
  // wait for a touch
  if (! ts.touched()) {
    return;
  }

  x = map( p.x, TS_MINX, TS_MAXX, 0, tft.width());
  y = map( p.y, TS_MINY, TS_MAXY, 0, tft.height());
  // print the "touch down" position
  Serial.print("X = "); Serial.print(x);
  Serial.print("\tY = "); Serial.println(y);  

  //hang around in a while loop until the touch is released
  while (ts.touched()) {
  }

}

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: 2.8" TFT Touch Down Event

Post by adafruit_support_rick »

Should work. But try it this way instead:

Code: Select all

void loop()
{  
  uint16_t x = 0;
  uint16_t y = 0;

  // wait for a touch
  if (! ts.touched()) {
    return;
  }
  TS_Point p = ts.getPoint();

  x = map( p.x, TS_MINX, TS_MAXX, 0, tft.width());
  y = map( p.y, TS_MINY, TS_MAXY, 0, tft.height());
  // print the "touch down" position
  Serial.print("X = "); Serial.print(x);
  Serial.print("\tY = "); Serial.println(y);  

  //hang around in a while loop until the touch is released
  while (ts.touched()) {
  }

}

User avatar
asteroid
 
Posts: 300
Joined: Tue Oct 22, 2013 9:10 pm

Re: 2.8" TFT Touch Down Event

Post by asteroid »

> Should work. But try it this way instead:

Unfortunately, the problem persists. Now a touch in all four corners (starting in left lower, USB on right) yields the following Serial Monitor data:

X = 65527 Y = 65526
X = 235 Y = 291
X = 237 Y = 291
X = 237 Y = 291

It no longer gives different data for each corner.

User avatar
asteroid
 
Posts: 300
Joined: Tue Oct 22, 2013 9:10 pm

Re: 2.8" TFT shield - touch buffer issues

Post by asteroid »

> always kicks back an old value

I'm also experiencing this problem and interested in finding a solution. However, it is difficult for me to follow the sample code that you posted. Would it be possible to write a simple runnable demo which illustrates the problem?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: 2.8" TFT Touch Down Event

Post by adafruit_support_rick »

Strange. There's obviously some sort of buffering going on. However, the following seems to work, and should get you going:

Code: Select all

/*
  Demonstrates "touch down" event
  UNO + 2.8 TFT Touch Shield - v2
  USB in right lower corner
*/

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_STMPE610.h>

// Default values for Adafruit shield v2.
#define STMPE_CS 8
#define TFT_DC 9
#define TFT_CS 10

Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

 #define TS_MINX 150
 #define TS_MINY 130
 #define TS_MAXX 3800
 #define TS_MAXY 4000
 
void setup() 
{
  Serial.begin(9600);
  tft.begin();
  ts.begin();  
}

void loop()
{  
  uint16_t x = 0;
  uint16_t y = 0;

  TS_Point p = ts.getPoint();

  // wait for a touch
  if (! ts.touched()) {
    return;
  }
  delay(100);
  p = ts.getPoint();
  
  x = map( p.x, TS_MINX, TS_MAXX, 0, tft.width());
  y = map( p.y, TS_MINY, TS_MAXY, 0, tft.height());
  // print the "touch down" position
  Serial.print("X = "); Serial.print(x);
  Serial.print("\tY = "); Serial.println(y);  

  //hang around in a while loop until the touch is released
  while (ts.touched()) {
  }

}

User avatar
asteroid
 
Posts: 300
Joined: Tue Oct 22, 2013 9:10 pm

Re: 2.8" TFT Touch Down Event

Post by asteroid »

Thank you, Rick. Now I get the correct data with a touch in each lcd corner:

X = 237 Y = 288
X = 16 Y = 288
X = 18 Y = 17
X = 237 Y = 13

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”