I ran the TouchScreen_Calibr_native example on the screen you sent me.
TouchScreen.h GFX Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction
Testing : (A1, D7) = 23
Testing : (A2, D6) = 35
Diagnosing as:-
XM,XP: (A1, D7) = 23
YP,YM: (A2, D6) = 35
ID = 0x6814
cx=168 cy=103 cz=608 LEFT, TOP, Pressure
cx=169 cy=510 cz=432 LEFT, MIDH, Pressure
cx=165 cy=905 cz=215 LEFT, BOT, Pressure
cx=513 cy=105 cz=589 MIDW, TOP, Pressure
cx=521 cy=908 cz=294 MIDW, BOT, Pressure
cx=862 cy=107 cz=683 RT, TOP, Pressure
cx=866 cy=513 cz=541 RT, MIDH, Pressure
cx=871 cy=901 cz=418 RT, BOT, Pressure
MCUFRIEND_kbv ID=0x6814 320 x 480
const int XP=7,XM=A1,YP=A2,YM=6; //320x480 ID=0x6814
const int TS_LEFT=143,TS_RT=889,TS_TOP=87,TS_BOT=921;
PORTRAIT CALIBRATION 320 x 480
x = map(p.x, LEFT=143, RT=889, 0, 320)
y = map(p.y, TOP=87, BOT=921, 0, 480)
Touch Pin Wiring XP=7 XM=A1 YP=A2 YM=6
LANDSCAPE CALIBRATION 480 x 320
x = map(p.y, LEFT=87, RT=921, 0, 480)
y = map(p.x, TOP=889, BOT=143, 0, 320)
I would copy-paste the Portrait Calibration values into any example sketch
const int XP=7,XM=A1,YP=A2,YM=6; //320x480 ID=0x6814
const int TS_LEFT=143,TS_RT=889,TS_TOP=87,TS_BOT=921;
And the example should be calibrated perfectly for the actual display that is on my desk.
Your values were:
const int XP=6,XM=A2,YP=A1,YM=7; //320x480 ID=0x6814
const int TS_LEFT=876,TS_RT=202,TS_TOP=909,TS_BOT=120;
This shows that your Touch Panel XP, XM are on different pins to my panel.
Not only different pins but they are backwards too !!
Personally, I think that it is wise to always use the Portrait Calibration i.e. the const statements.
If my application is using Landscape, Portrait_Rev, ... I need to adjust the map() statements to respond to the orientation.
However, most people, most of the time write apps for one orientation and never change.
So I show you the map() arguments that you would use in LANDSCAPE. You could write your app :
TouchScreen_kbv ts(6, A1, A2, 7, 300); //your X, Y pins
...
tft.setRotation(1); //LANDSCAPE
...
x = map(p.y, 909, 120, 0, 480); //your calibration
y = map(p.x, 202, 876, 0, 320);
...
Traditionally, I just displayed the calibration values on the TFT screen. Which meant that you had to copy them to paper. And re-type them into your app.
Then I thought it would be helpful to show exactly what is happening on the Serial Terminal.
As you click on each cross-hair, you can see exactly what x,y,z values are returned from TouchScreen
It also means you can copy-paste from the Serial Terminal to your app. (or in your Forum question)
I appreciate feedback from users. Would this be better?
...
MCUFRIEND_kbv ID=0x6814 320 x 480
PORTRAIT CALIBRATION 320 x 480
x = map(p.x, LEFT=143, RT=889, 0, 320)
y = map(p.y, TOP=87, BOT=921, 0, 480)
Touch Pin Wiring XP=7 XM=A1 YP=A2 YM=6
LANDSCAPE CALIBRATION 480 x 320
x = map(p.y, LEFT=87, RT=921, 0, 480)
y = map(p.x, TOP=889, BOT=143, 0, 320)
//COPY_PASTE THESE TWO LINES TO YOUR SKETCH:
const int XP=7,XM=A1,YP=A2,YM=6; //320x480 ID=0x6814
const int TS_LEFT=143,TS_RT=889,TS_TOP=87,TS_BOT=921;
Traditionally, TouchScreen.h returns x,y,z as raw ADC values. You have to map() to your screen.
It would be possible to create a super class that receives the calibration values and orientation in a constructor. Then it could return proper pixel_x, pixel_y coordinates.
The calibration values could be in a "user_calibration.h" file. Fine for a SINGLE screen. A nightmare if you have several different screens.
David.