how do I calibrate TouchScreen.h

after doing the calibration I got this values

TouchScreen.h GFX Calibration
Not possible to diagnose Touch pins on ARM or ESP32
ID = 0x6814

cx=895 cy=855 cz=596 LEFT, TOP, Pressure
cx=517 cy=854 cz=445 LEFT, MIDH, Pressure
cx=136 cy=858 cz=250 LEFT, BOT, Pressure
cx=892 cy=538 cz=597 MIDW, TOP, Pressure
cx=137 cy=538 cz=330 MIDW, BOT, Pressure
cx=893 cy=222 cz=627 RT, TOP, Pressure
cx=514 cy=226 cz=551 RT, MIDH, Pressure
cx=138 cy=224 cz=450 RT, BOT, Pressure
MCUFRIEND_kbv ID=0x6814 320 x 480

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;
PORTRAIT CALIBRATION 320 x 480
x = map(p.x, LEFT=876, RT=202, 0, 320)
y = map(p.y, TOP=909, BOT=120, 0, 480)
Touch Pin Wiring XP=6 XM=A2 YP=A1 YM=7
LANDSCAPE CALIBRATION 480 x 320
x = map(p.y, LEFT=909, RT=120, 0, 480)
y = map(p.x, TOP=202, BOT=876, 0, 320)

what do I do with this, enter somehow inside the TouchScreen.h library or inside the main program body ?

I want to use LANDSCAPE

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.

1 Like

I note that you appear to have run your sketch on an ARM. An ARM can't diagnose your X, Y pins. It will simply use the "common" pin wiring.

I suggest that you determine your X, Y wiring on a Uno / Mega. In fact, you might just as well run the Calibration on the AVR target. The results can be used on any target.

Or use a DMM if you don't have an AVR.

David.

Hi

Actually I managed to get it working with this, I spent whole weekend playing

const int XP=7,XM=A1,YP=A2,YM=6;
const int TS_LEFT=160,TS_RT=835,TS_TOP=113,TS_BOT=917;

I had to change the PINS and make some adjustments

I just got new touch TFT 9486, it works on Nucleo, it has blue board, the same pin layout as D = 0x6814

but again pins have to arranged to make the touch working. It uses A2 and A3,

It is quite simple. Diagnose X and Y pins with a DMM. The resistance will be ~ 300R for X and ~ 500R for Y. Use the correct X, Y pins in your App.

Otherwise, plug the shield into a Uno and run the calibration. Copy-paste the info to your App.

Your Blue ILI9486 has got different calibration info to your Red RM68140 board.

It is clear that you have found this difficult. If you can suggest a better way to do things it will help others.

It also looks as if your Red board is the same as the Red board that you sent me. Your problems were all down to using the wrong X, Y pins.

David.

when I try to do the calibration, the top - left cross hair does not work on ILI9486, I got 2, both the same problem.

Identify the correct X, Y pins.

Run TouchShield_kbv example with the correct X, Y pins.
Observe how the TouchScreen returns ADC values for anywhere on the screen.
Observe the values near the top left of the screen.

Run the TouchScreen_Calibr_native example. Click as near to the top left cross-hair as you can.
Copy-Paste the Serial Terminal to your message.

Make sure that any Apps that you write do not have buttons too close to the top left corner.

David.

something funny is going on with the calibration program, I am still working to figure it out (could it be the TFT itself)
the top left cross hair will not respond, but when I click on the second down on the left, it thinks that I click on the top and it completes the calibration.

but I managed to get good calibration adjusting the values manually and the program Touch_shield_new works fine with this setting.

//ID=0x6814

const int XP=7,XM=A1,YP=A2,YM=6;
const int TS_LEFT=160,TS_RT=835,TS_TOP=113,TS_BOT=917;

//ID=0x9486

const int XP=8,XM=A2,YP=A3,YM=9;
const int TS_LEFT=180,TS_RT=805,TS_TOP=935,TS_BOT=130;

Go on. The Calibration routine records 8 cross-hairs. It will accept the "first" press as being top-left.

That is why I asked you to run the TouchShield example. It will show you every "touch". If the top-left corner is dead, you could say "it responds at 10mm, 10mm from the top-left" or wherever.

You would press this point instead of the actual top-left cross-hair.
And most importantly, you would copy-paste the result to your message.

Ah-ha. I see that it shares A3 for LCD_CS and YP. That is not wise. But hey-ho, I don't manufacture these Shields.

const int XP=8,XM=A2,YP=A3,YM=9; 
const int TS_LEFT=180,TS_RT=805,TS_TOP=935,TS_BOT=130;

I would like to see the Serial Output from Calibration sketch. Even if you press a "fake" top-left cross-hair.

David.

here it goes; the top left cross hair does not respond but I press twice the middle on the left (PORTRAIT) it thinks it is the top and then the middle.

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 : (A2, D8) = 22
Testing : (A3, D9) = 32
Diagnosing as:-
XM,XP: (A2, D8) = 22
YP,YM: (A3, D9) = 32
ID = 0x9486

cx=150 cy=525 cz=417 LEFT, TOP, Pressure
cx=146 cy=527 cz=414 LEFT, MIDH, Pressure
cx=143 cy=115 cz=597 LEFT, BOT, Pressure
cx=517 cy=942 cz=285 MIDW, TOP, Pressure
cx=521 cy=113 cz=606 MIDW, BOT, Pressure
cx=881 cy=940 cz=425 RT, TOP, Pressure
cx=886 cy=528 cz=536 RT, MIDH, Pressure
cx=894 cy=113 cz=679 RT, BOT, Pressure
MCUFRIEND_kbv ID=0x9486 320 x 480

const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x9486
const int TS_LEFT=121,TS_RT=911,TS_TOP=816,TS_BOT=98;
PORTRAIT CALIBRATION 320 x 480
x = map(p.x, LEFT=121, RT=911, 0, 320)
y = map(p.y, TOP=816, BOT=98, 0, 480)
Touch Pin Wiring XP=8 XM=A2 YP=A3 YM=9
LANDSCAPE CALIBRATION 480 x 320
x = map(p.y, LEFT=816, RT=98, 0, 480)
y = map(p.x, TOP=911, BOT=121, 0, 320)

Looking at your cx, cy values. LEFT=146, RT=887, TOP=942, BOT=114
These figures will be adjusted to allow for the cross-hairs not being at the far edges of the panel.

Which would give 121, 911, 958, 114 i.e. the TOP needed to be changed.

Paste in those values to the TouchShield program. The dot should follow your stylus perfectly.
You should see which region of the panel is "dead".

You can run TouchShield in Landscape mode if you want. It should be a simple define at the top of the sketch.

David.