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:
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.
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__!)
Put them together! Prints X location at scaled X touch, Prints Y location at scaled Y touch.
Have fun! Draw pixel at touch location.
I should mention that this approach was initiated by
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)