UTOUCH Users---READ THIS!!! Add delay after myTouch.dataAvailable()

For those of you who are using the www.henningkarlsen.com and experiencing strange behavior when trying to calibrate your screen, I learned that adding a delay(50); after myTouch.dataAvailable() fixed my problem. Without this, my uTouch coordinates were corrupted and caused the cursor to show up in strange places misleading me into thinking the coordinates were off. I also learned the calibration was reversing my screen coordinates causing strange things to occur...

Here is a simpler way to calibrate your screen. First download the attached code and library files: uTouch.cpp and uTouch.h. Replace the library files from henningkarlsen
(note: you previously copied the library folder to ...MyDocuments/Arduino/Libraries/, right?)

First off: Open the .pde code and make sure to:
A) Enter the correct display driver in myGLCD(SSD1289,38,39,40,41);
B) Enter the correct screen orientation for both myGLCD.InitLCD(LANDSCAPE); and myTouch.InitTouch(LANDSCAPE);

Then, follow the steps below for a simpler, straightforward way of calibrating the touchscreen.

The program has the following functions that can be selected by changing the #define selector at the top of the code:
Functions:

  1. Map out the display coordinates: Prints numbers across the screen from left to right and up to down.
    -Write down the extreme values (right (X) and down (Y)). I assume the left and up positions are zero.
    -Open the .cpp file and enter these values under disp_X_size and disp_Y_size. This sets the range of your screen.

  2. Map out the touch coordinates: Prints the number coming back from your touch controller (0-4096) at a fixed location on the screen.
    -Write down the extreme values (left, right,up, and down).
    -Enter them into the uTouch.cpp under touch_x_left, etc.. and disp_x_size, etc...
    -Note: If you have a reversed coordinate system, modify the math under *getX()or getY(). The new uTouch.cpp is simplified so the offset and scaling is straightforward. (Note reversed does not mean you can just add a __-1__!)

  3. Put them together! Prints X location at scaled X touch, Prints Y location at scaled Y touch.

  4. Have fun! Draw pixel at touch location.

I should mention that this approach was initiated by

adrianwing:
I had a similar problem with a Mega 2560 R3, Sainsmart 4.2", and the Elecfreaks v2.2 adapter. Having dug through the UTouch.cpp file, there is a section at about line 30:-

SimplerCalibration.ino (2.41 KB)

UTouch.cpp (4.83 KB)

UTouch.h (2.01 KB)

Well, you haven't posted your sketch so it's likely that the problem is actually there.

You only need a delay if your loop() is a really fast, tight loop, for example if that the data from UTouch is not being processed.

The problems described here are specific to the crappy SainSmart products which ARE NOT, nor will they ever be, supported by any of my libraries!

/Henning

Henning,
My thanks goes out to you for the very helpful libraries. I did not realize the SainSmart controllers were so crappy. I saw a bunch of brands with similar products and chose one based on the form factor. Perhaps the design has some cross talk interference? But now I know.

This post is not to replace your code, but to provide a simple troubleshooting approach for those who are trying to unravel why their screen will not calibrate. I don't know if all the posters who have this problem stem from SainSmart, but I can tell you, they are common.

The code I used that gave the error is the draw pixel program that come with the Utouch library. Certain odd things like changing a color before drawing a pixel would also cause strange corruption of the coordinates. Adding delay in other places did not work. However, adding the delay after the data available command worked, which is the same delay that is listed in the paint colors example. Is there a reason it is added there?

I have heard of these issues several times and every single time it has been with a SainSmart display. I have not had any reports of this on any of the supported display modules nor have I ever experienced it myself...

The delays in the QuickPaint example are there to "debounce" the "buttons".

/Henning

Hello Henning and all,

I think the problem is related to 10kohm series resistors in Saintmart shields.
I also noticed that some delay is needed for the touch function.
The resistor with some capacitance in the circuitry slows down the CS signal and there's not enough time that data is valid in the touch AD-converter.
I found out that even 1us delay is enough.

Those resistors are ok in this kind of experimental kit, cause it allows other usage of same pins.

I have tested several displays with the old ITead shields which use 10k resistors... No problems with those.

/Henning

Thanks for the responses... Wish I knew how bad these SainSmart boards were! My Mega just tanked with the error below, so I am returning it for an ElecFreaks or ITEAD touchscren. To my novice eyes, all three of the websites looked pretty hokey! But I feel much better knowing that the latter brands are tested. Again, no intention at knocking your wonderful libraries, Henning --- a shame that a few bad apples can frustrate the whole process.

avrdude: stk500v2_getsync(): can't communicate with device: resp=0x01
---Loop back test worked fine; new bootloader using Nick Gammon's code loaded fine; but still cannot upload simple blink sketch. Perhaps something to do with a faulty reset? If you have ideas I will start another thread, but don't want to divert this one.
-SainSmart Mega 2560 R3

Hello,
have you measured the waveform from CS signal with 10kohm resistor?
There's no issues related to SainSmart quality.

Henning,

Please don't get pissy about this. Your libraries are gold and make UTFT displays usable. The work you've put in is unbelievable, and something I couldn't hope to replicate. Much appreciated.

Unfortunately, many of us are cost driven, so we buy the crappy Sainsmart displays. My work around is not me having a shot at you, it's giving (I hope) the poor among us a chance to use our crappy displays and your libraries to get an actual result.

I found that using Publisher, exporting as a .png, then using Paint to resize and your utilities can give whole font families and custom buttons that display perfectly. I'm progressively creating all the monospaced fonts I can in *.c format and will package them in a zip when I'm done.

If you're offended, I apologise. That was not my intention. I'm just trying to make UTFT displays usable to as many Arduino users as possible.

Regards,
Adrian

Just received my ElecFreaks 3.2" TFT touch screen and shield for the mega. Works like a charm. No problems with screen calibration, flickering, etc.. Now this is how a shield should work! Best money I've spent on an Arduino project thus far.

I have a 'crappy' Sainsmart and was having problems with the touch screen. I was using the Utouch library. The button test example did not correlate the touch position with the screen display. Press 8 and 1 would light up, etc. Tried to calibrate and no difference. I then used an old library 'ITDB02 Touch Mod' and it now works fine. I found the library deep in the Sainsmart website. It would have been nice for Sainsmart to provide a downloadable library which worked!

mickl01:
I then used an old library 'ITDB02 Touch Mod' and it now works fine. I found the library deep in the Sainsmart website. It would have been nice for Sainsmart to provide a downloadable library which worked!

Please note that SainSmart does not have any rights to distribute that library. ITDB02_Touch is copyrighted by me and I have never given SainSmart any rights to use it commercially.

/Henning

I FIXED IT on my Sainsmart board.

Me too has found the joy in arduino and bought a cheap sainsmart Mega 2560 from Asia, with shield and Touch-TFT.
The touch did not work at all, not possible to calibrate. I studied the data waves with oscilloscope and found that the signals from touch IC XPT2046, in to the mega was ugly due to the 10K resistor. The resistor should not be needed as the touch IC signal is 3,3V but it has over and undershoot pikes, so it probably needs some filtering. When I used the oscilloscope probe without damping resistor in probe it suddenly worked. The oscilloscope adds a load of 1M ohm. So I started experimenting. After replacing the 10K resistor at D_OUT with 50K and connecting 10K between touch IC side of the 50K and to ground, it works and after calibration everything is perfekt.
Strange though, as this still makes the data signal look bad with curved flanks. I wonder if the problem is in the TFT, sheild or in the mega board (all from sainsmart), but clearly the data signal needs some attention, it has nothing to do with the software.

Thanks Henning for the librarys.
/ Weman

Weman:
..After replacing the 10K resistor at D_OUT with 50K and connecting 10K between touch IC side of the 50K and to ground, it works and after calibration everything is perfekt..

Thank you Weman, i fixed my crappy SainSmart board according your procedure.

I also want to thank Weman,
my SaintSmart board works perfect after changing the resistors!
Joa

Your right Doc_norway, these screens are indeed CRAPPY. I just spent 2 days ginning around with a 7 inch sainsmart unit and finally after calibrating it manually using erk1313's advice, I finally have a "acceptably" operating unit. There is a 50 pixel wide dead zone down the right side of the screen from half way down running to the bottom, where no touch is even detected, so I calibrated it "out" and wrote my button software so theres no need to touch there. Jeez if only I knew how crap these products are. I wont hold back and say do not buy any products from "profit vanity" from ebay, they love their saindumb products and at an expensive price too!
( I also bought a 5 inch one, similar story)
both are working now tho.
Be more bloody carefull what I buy from now on.
Thanks to everyone who has spent hours with these things, couldn't have fixed them without you.

John.

Hello everyone!

I just received my Due, CTE shield and 7 inch display from Sainsmart and this was not an issue that noticed to check before ordering.

Do any of you guys that have changed the resistor have a picture of resistors in question.
I'd really appreciate some sort of example, since I'm really unconfident with SMD soldering

In my display the 10K resistor (R3) close to the XPT2046 is connected between 3.3vdc and pin11/PENIRQ,
not to pin12/Dout

Thank You in advance
Tapio

You actually mean Sainsmart rip-off of a CTE shield!! You would not be having these problems if you bought CTE products.

Regards,

Graham

Hi all

Complete noob here - suffering the same issues of calibration using ATmega, TFT touchscreen and an ITD studios 5" screen. Trying to work through the calibration issues before - from the simplified calibration setup up I get the following coordinates (where x1, y1 is top left, x2, y1 is top right, x1, y2 is bottom left and x2, y2 bottom right):

x1, y1 428,3888
x2, y1 432, 136
x1, y2 3744, 3936
x2, y2 3736, 131

So I assume that my x and y are reversed and that my x coordinates are running back to front. So....how exactly do I modify the .cpp file again (going from below)... I know this should be simple but my brain hurts...

erk1313:
2) Map out the touch coordinates: Prints the number coming back from your touch controller (0-4096) at a fixed location on the screen.
-Write down the extreme values (left, right,up, and down).
-Enter them into the uTouch.cpp under touch_x_left, etc.. and disp_x_size, etc...
-Note: If you have a reversed coordinate system, modify the math under *getX()or getY(). The new uTouch.cpp is simplified so the offset and scaling is straightforward. (Note reversed does not mean you can just add a __-1__!)