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);
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
. Replace the library files from henningkarlsen
(note: you previously copied the library folder to ...MyDocuments/Arduino/Libraries/
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);
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
. 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
, etc.. and disp_x_size
-Note: If you have a reversed coordinate system, modify the math under getX()
. 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
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:-