Pages: [1] 2   Go Down
Author Topic: 3.2 Sainsmart TFT touch issues  (Read 8327 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay so i have managed to get get the screen to work and that is fine. However i cannot get the touch to work at all. I have all the libraries installed and even the example from the ITDB02_touch library compiles and loads fine. I am using an Arduino Mega 2560. However the example for touch screen calibration works but some of the graphics get screwed up. What could I be doing wrong? Any help would be greatly appreciated.

Here is some of my code.

Code:
#include <UTFT.h>
#include <ITDB02_Touch.h>

//Declare font types
extern uint8_t BigFont[];

//Gets the screen and touch sensor ready
UTFT myGLCD(ITDB32S,38,39,40,41);
ITDB02_Touch  myTouch(6,5,4,3,2);

//Declare functions
void read_ts();

//Define my variables
float x = 0, y = 0;
int run = 0;

int temp;
bool error = true;
bool changed = true;

void setup()
{
  //Setup the Screen
  myGLCD.InitLCD();
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);
  myGLCD.clrScr();
}

void loop()
{
  //reads x and y values of touch sensor
  read_ts();
  //prints these values to the screen
  myGLCD.printNumF(x,3,50,150);
  myGLCD.printNumF(y,3,50,175);
  myGLCD.setFont(BigFont);
  myGLCD.setColor(255, 0, 255);
  myGLCD.print("It got this far.", CENTER, 200);
  myGLCD.printNumF(run,2,50,75);
  //prints how many times it has run onto the screen
  run++;
}

void read_ts()
{
  x = myTouch.getX();
  y = myTouch.getY();
}

I've also attached a picture of the screen.

Peter


* 2012-09-01_00-21-25_284.jpg (1429.89 KB, 3264x1840 - viewed 302 times.)
Logged

Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

SE USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

are they both using interrupts?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm sorry, i'm not sure what you mean by "interrupts"?
Logged

Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

SE USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

interrupts are a fundamental part of computer processors, they say that if something occurs stop everything, run this part of the code, and then return back to what you were doing

imagine that your working on a report in the office and the phone rings from the bosses extension, that's an interrupt.

AVR microcontrollers can accept many different interrupts from different locations, internal timers, or external influence. the bad thing is AVR micro's are pretty stupid and cant really tell what caused the interrupt, it just knows that something happened, so if you have 2 items using interrupts, it kindly runs them both.

For example the TV out library uses timer interrupts so it can make the video timing signals, add the PS/2 keyboard library which uses external interrupts to note when the keyboard has data to send and the screen gets all goofy.   
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey thanks for the reply Osgeld.
So are you saying that the touch sensor acts as an interrupt which stops the code? I understand what you are saying, but how would i fix this? Do I have to tell the AVR what to do if it receives an interrupt or tell it to continue running the code even if it receives an interrupt signal?

Peter
« Last Edit: September 02, 2012, 10:50:29 pm by Peter_F » Logged

Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

SE USA
Offline Offline
Faraday Member
**
Karma: 40
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that I dont know, attach the libraries you are using for the screen and touch
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, i am using the UTFT Library for the screen http://www.henningkarlsen.com/electronics/library.php?id=51
and the ITDB02_Touch Library for the touch Sensor http://www.henningkarlsen.com/electronics/library.php?id=35
Logged

Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 25
Posts: 4107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I've also attached a picture of the screen.

What did you expect to see?

Don
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well quite frankly, that was what i expected to see. the 298 Number is a loop counter so i know its running. 27000 is the x coordinate and the 32656 is the y coordinate for the touch sensor. However, these numbers appear the same every time it runs, even  before the screen is touched.
Logged

Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 25
Posts: 4107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How often do you think you should read the touchscreen?

Do you think it is necessary to rewrite the x and y coordinate data if it doesn't change?

What's this:  run++; ?


Don
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well the run++ was just to keep track of the number of times the loop ran. I can probably get rid of that. Also I see what you mean that i should only readthe touch screen if the data changes, I know how to do that, but I cannot get accurate touch data at all, so that is my first priority.
Logged

Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 25
Posts: 4107
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Also I see what you mean that i should only readthe touch screen if the data changes,
Well you have to read the touch screen first in order to determine if the data changes - but you shouldn't have to redisplay the data if it hasn't changed.

Quote
I know how to do that, but I cannot get accurate touch data at all, ...
What are the timing constraints concerning how often you can access the touch data?  Are you observing those constraints?

Don
Logged

0
Offline Offline
Sr. Member
****
Karma: 5
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For the calibration sketch to work you neet to init the screen and touch in portrait orientation

as per your code this defaults to landscape mode
Code:
 myGLCD.InitLCD();
  myTouch.InitTouch();

you need to change it to this
Code:
myGLCD.InitLCD(PORTRAIT);
myTouch.InitTouch(PORTRAIT);

once the calibration is done you can go back to landscape if you want

Start simple, have you tried the quickdraw example?
Code:
#include <UTFT.h>
#include <ITDB02_Touch.h>

UTFT myGLCD(ITDB32S,38,39,40,41);
ITDB02_Touch  myTouch(6,5,4,3,2);

void setup()
{
  myGLCD.InitLCD(PORTRAIT);
  myGLCD.clrScr();

  myTouch.InitTouch(PORTRAIT);
  myTouch.setPrecision(PREC_MEDIUM);
}

void loop()
{
    while (myTouch.dataAvailable() == true)
    {
      myTouch.read();
      myGLCD.drawPixel (myTouch.getX(), myTouch.getY());
    }
}
« Last Edit: September 03, 2012, 04:45:48 pm by P18F4550 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay thanks to all your efforts, the touch sensor is now working and i can read the X and Y values However even after calibration, the readings are not consistent varying by as much as 30 pixels. I am using extreme precision and was using the tip of a pencil  and it still wasn't that accurate. Any ideas?

Peter
Logged

Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 52
Posts: 1770
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Check out the data sheet for the touch interface, it may have a trouble shooting section or tips on how to get best performance. Maybe the touch interface needs debouncing. I have a touch TFT I want to use so it'll be good to see if you can get nice and accurate readings.
Logged


Pages: [1] 2   Go Up
Jump to: