Help Arduino Mega 2560 + 3.2" TFT LCD

tgsuperspec: The UTouch lIbrary in my view uses a slightly odd method ..

  1. I used a logic analyser to review the Texas Instrument chip used for the screen, this showed the best option seemed to be to attach the IRQ to a pin on arduino as an ege triggered interrupt. rather than use the polll techniues and read while low.

  2. The spec on the chip also highlighted that although its 12 bit resolution to ensure next value availability you should clear the buffer register by clocking 16 bits through, from memory the UTouch library only does 12

  3. You tend to get a ghosting interrupt generated at removal of touch which if your polling will cause extra invalid readings.

4 I run a moving average on data during a touch event.

Calibration is difficult on smaller displays if you google cailibrartion algorithms for TFT touch, the matrix solution always comes out best but

/// a.. On 3,2 its a bit overkill // b. The maths is difficult to program

The UTouch Library solution is fair, but holding the pointer still whilst sampling for a series of locations I find difficult, my customers founmd impossible.

Rewrote the calibration to cycle defined points round screen to acieve am average Y for TOP, BOTTOM and average x for LEFT, RIGHT with that and some simple maths can scale any touch sample read to be position on screen

Currently can specify down to 8 x 8 Icon on screen and with stylas touch detecy position. With finger touch use 16 x 16 Icon

Happy coding

8) 8)

HazardsMind: You can subtract 320 from the getX() value you have now.

I tried, But not thing changed

I don't know how to fix You can send me a example code that can fix that error, tks all.

Post your code, and please use code tags.

I test with this code

#include <UTFT.h>
#include <UTouch.h>
extern uint8_t BigFont;

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

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

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

void loop()
{
long x, y;
myGLCD.setFont(BigFont);

while (myTouch.dataAvailable() == true)
{
myTouch.read();
x = myTouch.getX();
y = myTouch.getY();
if ((x!=-1) and (y!=-1))
{
myGLCD.clrScr();
myGLCD.print(“o”, 310-x , y-6 , 0);
myGLCD.printNumI(310-x, CENTER, 0); //X axis
myGLCD.printNumI(y-6, CENTER, 16); //Y axis
}
}
}

I invert the X Axis and add/subtract some unit.
In the left of screen, all great.
In the right of screen, X axis not right

see it, you will know

Private videos are hard to watch.

Have you tried the calibration sketch that comes with the UTouch library?

HazardsMind: Private videos are hard to watch.

Have you tried the calibration sketch that comes with the UTouch library?

Now, you can see

I was under the impression you had a 240x320 screen, But you have a 240x400 screen. So instead of subtracting 320, you need to subtract 400.

HazardsMind: I was under the impression you had a 240x320 screen, But you have a 240x400 screen. So instead of subtracting 320, you need to subtract 400.

That mean ...

myGLCD.printNumI(x-400, CENTER, 0); //X axis

I Test with

myGLCD.printNumI(x-400, CENTER, 0); //X axis

and

myGLCD.printNumI(400-x, CENTER, 0); //X axis

not better.

Where did you download your library from, can you provide a link. The values that are shown on screen fit where you touched the screen, but the display is off. I think the screen is set to 240x400, but the touchpad is set to 240x320. This would explain why when you touch the edge of the screen, you see 319, but the dot only goes 4/5 the way.

You need to calibrate your display / touch ratio and fix the CAL_X and CAL_Y values in the UTouchCD.h file.

HazardsMind: Where did you download your library from, can you provide a link. The values that are shown on screen fit where you touched the screen, but the display is off. I think the screen is set to 240x400, but the touchpad is set to 240x320. This would explain why when you touch the edge of the screen, you see 319, but the dot only goes 4/5 the way.

You need to calibrate your display / touch ratio and fix the CAL_X and CAL_Y values in the UTouchCD.h file.

I download my library from http://www.henningkarlsen.com/electronics/library.php?id=52

I will try the way you teach me.

Few mins ago, I test with this code, very good :3

while (myTouch.dataAvailable() == true) { myTouch.read();

test = 310-x; x = myTouch.getX(); y = myTouch.getY(); if ((x!=-1) and (y!=-1)) { myGLCD.clrScr(); myGLCD.print("o", 310-x+test/5.5,y-6,0); myGLCD.printNumI(310-x+test/5.5, CENTER, 0); //X axis myGLCD.printNumI(y-6, CENTER, 16); //Y axis } }

Very very thank you for your help.

You shouldn't have to divide anything by 5.5, if the screen / touch ratio is correct, the code will already do it for you.

HazardsMind:
You shouldn’t have to divide anything by 5.5, if the screen / touch ratio is correct, the code will already do it for you.

I found it

// UTouchCD.h
// ----------
//
// Since there are slight deviations in all touch screens you should run a
// calibration on your display module. Run the UTouch_Calibration sketch
// that came with this library and follow the on-screen instructions to
// update this file.
//
// Remember that is you have multiple display modules they will probably
// require different calibration data so you should run the calibration
// every time you switch to another module.
// You can, of course, store calibration data for all your modules here
// and comment out the ones you dont need at the moment.
//

// These calibration settings works with my ITDB02-3.2S.
// They MIGHT work on your display module, but you should run the
// calibration sketch anyway.
#define CAL_X 0x00378F66UL
#define CAL_Y 0x03C34155UL
#define CAL_S 0x000EF13FUL

But i don’t know the CAL_X CAL_Y correct

If you run the calibration sketch, it will give you values at the end, to replace the CAL_X/Y and S, thus fixing your problem.

HazardsMind: If you run the calibration sketch, it will give you values at the end, to replace the CAL_X/Y and S, thus fixing your problem.

I can't, I bought it from taobao.com :disappointed_relieved:

Your using the UTFT and UTouch libraries, you should be able to run the calibration sketch. Attached is the calibration sketch, You may need to change a few lines to get it to work, like you pin numbers and model.

UTouch_Calibration.ino (9.71 KB)