3.2 Sainsmart TFT touch issues

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.

#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

are they both using interrupts?

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

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.

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

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

Okay, i am using the UTFT Library for the screen Electronics - Henning Karlsen
and the ITDB02_Touch Library for the touch Sensor Electronics - Henning Karlsen

I've also attached a picture of the screen.

What did you expect to see?

Don

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.

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

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.

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.

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

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

  myGLCD.InitLCD();
  myTouch.InitTouch();

you need to change it to this

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?

#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());
    }
}

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

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.

What would be the best way to debounce the touch interface? Also, i cant seem to find the data sheet.

I am not sure if your issues are the same as mine where, but I bought a sainsmart 3.2" TFT LCD Screen about a month ago and had roughly the same issues, it ending up being that the touch screen was just installed upside down?

So to fix that I now have to subtract the y-axis value I want from 240 to get the correct response...
Kind of annoying, but it still works. I am really not thrilled with sainsmart to be honest, they have such a wide variety of products that all seem to work, I just don't understand why they can't provide information about how to use them with the products.

Hi nkd5025,

I've got the same kit ... I can't get my start with it. I did do http://henningkarlsen.com UTFT to prove the screen. It was a sine wave and all but sometimes quite noisy. With that great reference for the functions, so I'm not too worried about getting what I want to show up on the screen.

But as time passes, the display gets more and more scattered so when I try the Touch demos, I'm not able to really see anything.

I feel like I'm missing something simple to get going... any ideas on simple sketches that got you started?

Thanks,
Chris

I just fought with this display from Sainsmart for abit, found you need the latest librarys.
Electronics - Henning Karlsen for touch
Electronics - Henning Karlsen for display

works well.
Id say those 3.2 screens arnt the best for touch, but the display is great. For the price, I can live with the touch not working to great. I'm thinking if I keep all the buttons on the more accurate side, I should be good.

I used the codes supplied to check my screens and they work to a point. the second coding inverts my vertical touch however. how do I change that? do I change the pins around in the code?