Go Down

Topic: 3.2 Sainsmart TFT touch issues (Read 10 times) previous topic - next topic

Peter_F

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: [Select]

#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
Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD


Peter_F

I'm sorry, i'm not sure what you mean by "interrupts"?
Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

Osgeld

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. 

Peter_F

#4
Sep 03, 2012, 05:47 am Last Edit: Sep 03, 2012, 05:50 am by Peter_F Reason: 1
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
Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

Osgeld

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

Peter_F

Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

floresta

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


What did you expect to see?

Don

Peter_F

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.
Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

floresta

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

Peter_F

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.
Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

floresta

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

P18F4550

#12
Sep 03, 2012, 11:27 pm Last Edit: Sep 03, 2012, 11:45 pm by P18F4550 Reason: 1
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: [Select]
 myGLCD.InitLCD();
 myTouch.InitTouch();


you need to change it to this
Code: [Select]
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: [Select]
#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());
    }
}


Peter_F

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
Arduino Mega 2560
Arduino Uno R3
Sainsmart 3.2" TFT LCD

pYro_65

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.

Go Up