 # MATHEMATICAL SOLUTION OF TOUCH PANEL CALIBRATION

This post is also available in: Türkçe

## TOUCH PANEL CALIBRATION

• Touch panels are used by attaching them to the screens. However, the coordinates of the panel and the coordinates of the screen do not match. That’s why they have to be calibrated.
• Previously I had to calibrate through the function in the library I wrote for 4-wire resistive type panes. However, I learned the mathematical solution of the 2 point calibration method with the aim of learning the calibration mathematics of users of different types of touch panel.
• Do not forget to watch the video lesson.

### 2 POINT CALIBRATION METHOD

• There are many calibration methods. (2-4-6-12-16 point methods are available.)
• In general, large screens are calibrated using 2 denier values to provide angular calibration.
• Even though it is a 2 point method, touch 4 points. This is because X1 is X2 and Y1 is Y2.
• To do this, first of all, on the screen where the touch panel is installed, pixels are formed in certain places.
• The picture above is a template. Here 4 red dots are our calibration points.
• These points are created in the GLCD where the pixel rendering function corresponds to the above metrics. This is just to show where the user will touch.
• For a 240×128 GLCD, the coordinates that need to be created are points that need to be touched according to the template image above;
• 1.POINT   x=%20 ve y=%80 so x=240*20/100= 48   y=128*80/100=102   so (48,102)
• 2.POINT  x=%20 ve y=%20 so x=240*20/100=48     y=128*20/100=25     so (48,25)
• 3.POINT  x=%80 ve y=%20 so x=240*80/100=192   y=128*20/100=25     so (192,25)
• 4.POINT  x=%80 ve y=%80 so x=240*80/100=192   y=128*80/100=102  so (192,102)
•  We have calculated above in which coordinates the 4 calibration points on the 240×128 screen should be created on the screen. Pixels will be created at these points and the user will be asked to touch the place.
• When the user touches this point, the raw x and y values coming from the touch panel will be read. (see circuit diagram and other details for “resistive touch panel library”)
• For example (the raw values are the values used in the lesson, and the value that each panel gives may vary).
• The raw value read when the first POINT is touched is x = 230 and y = 730. That is, when the point on the GLCD is touched (48,102), the read value is (230,730).
• The raw value read when the second POINT is touched is x = 228 and y = 237. That is, the value read when the point (48,25) on the GLCD is touched (228,237) is.
• The raw value read when the third POINT is touched is x = 780 and y = 232. That is, when the point (192,25) is touched on the GLCD, the read value is (780,232).
• The raw value read when the fourth POINT is touched is x = 773 and y = 704. That is, when the point (192,102) on the GLCD is touched, the read value is (773,704).
• We record the points touched in the above manner and the raw data from these points (the data comes from the touch panel).
• For screen control, you can use the “SAP1024B_GRAFIK_LCD” library I wrote earlier. Four points are created on the screen above and the user is asked to touch. Thus, the received data is processed. We call it the “virtual spots” from here.
 Touched Points in GLCD Values read from Touch Panel XD YD X Y 1.POINT 48 102 230 730 2.POINT 48 25 228 237 3.POINT 192 25 780 232 4.POINT 192 102 773 704
• The values read when this point is touched are our raw values.
• After these values, the mathematical operation sequence came up.
• With this process we will arrive at the solution by calculating our deviation shares.
As can be understood from its name, the deviation share calculates the deviation between the GLCD and the touch panel. Correcting the values accordingly enables the GLCD to have the same point in the coordinate plane in the touch panel.
• Example = If you touch the point of the screen (100,100) this time you will read it (100,100) through the touch panel instead of the different value.

### MATHEMATICAL SOLUTION OF CALIBRATION

#### Calculation of Deviation Values

• Before going to the end with the last formula, I need to calculate 4 values which I call “deviation value“.
• We will calculate the deviation values by using the table above.
• Four deviation values will be calculated. These are “a” value, “b” value, “c” value and “d” value.
• Each value will be calculated as “(a1 + a2) / 2 = averaging”.
• For all deviation values, 4 formulas will be used as shown in the picture above.

#### Calculation of Deviation Values “a1 and b1“

 FORMULA1: YD1=(a1*Y1)+(b1*1) YD3=(a1*Y3)+(b1*1)
• Let’s put into place by reading the values from the table above.
102=(a1*730)+b1
25=(a1*232)+b1
———————–
102=  (730a1) + b1
–25(232a1– b1
———————–
77=498a1
———————–
a1=(77/498) = 0,154
• Let us find the value of b1 based on the value of a1.
25=(0,154*232)+b1
———————–
25=(35,728)+b1
———————–
b1=(2537,728)= -10,728

#### Calculation of Deviation Values “a2 and b2“

 FORMULA2: YD2=(a2*Y2)+(b2*1) YD4=(a2*Y4)+(b2*1)
• Let’s put into place by reading the values from the table above.
25=(a2*237)+b2
102=(a2*704)+b2
———————–
25= (237a2)  b2
102=  (704a2b2
———————–
77=467a2
———————–
a2=(77/467) = 0,164
• Let us find the value of b2 over this value as we find the value of a2.
25=(0,164*237)+b2
———————–
25=(38,868)+b2
———————–
b2=(2538,868)= -13,868

#### Calculation of Deviation Values “c1 and d1“

 FORMULA3: XD1=(c1*X1)+(d1*1) XD3=(c1*X3)+(d1*1)
• Let’s put into place by reading the values from the table above.
48=(c1*230)+d1
192=(c1*780)+d1
———————–
48= (230c1)  d1
192=  (780c1+ d1
———————–
144=550c1
———————–
c1=(144/550) = 0,261
• Let’s find the value of d1 based on this value as we find the value of c1.
48=(0,261*230)+d1
———————–
48=(60,03)+d1
———————–
d1=(4860,03)= -12,03

#### Calculation of Deviation Values “c2 and d2“

 FORMULA4: XD2=(c2*X2)+(d2*1) XD4=(c2*X4)+(d2*1)
• Let’s put into place by reading the values from the table above.
48=(c2*228)+d2
192=(c2*773)+d2
———————–
48= (228c2)  d2
192=  (773c2+ d2
———————–
144=545c2
———————–
c2=(144/545) = 0,264
• Since we find the value of c2, let’s find the value of d2 over this value.
48=(0,264*228)+d2
———————–
48=(60,192)+d2
———————–
d2=(4860,192)= -12,192

#### Deviation Values Result Table

 1 2 Average a 0,154 0,164 0,159 b -10,728 -13,868 -12,298 c 0,261 0,264 0,262 d -12,03 -12,192 -12,111
• The results from the above tablature will be used in the final form.
• The averaging method is (a1 + a2) / 2.

#### Calibration by Using Result Formula

 RESULT FORMULA YD=a*Y(b) XD=c*X(d)
• After all values have been calculated, calibration can now be done.
• The “Result Formula” above is the last point in the software. With this formula, the software calibrates. See how it works with examples.
• As an example I will use the values given in the table above.
• For example, I read 730 on the Y axis. But the point I clicked is actually 102 dir. (see the table at the beginning)
Let’s place them in the form;
YD=(0,159*730)-12,298=103,772
• I saw that the point I touched when I made transactions based on the deviations I have found should be 103. Actually, the point I actually touched is 102. Such deviations can be caused by touching places and fractions. However, it should not be taken into consideration. Because the software is processed with the value of the float, a large part of the fractions are accounted for, and such mistakes are eliminated.
• If we had to do an X-axis calculation:
• For example, when I touch the X axis, I read 230, but the point I clicked is actually 48. (see the table at the beginning)
Put your place in the form;
XD=(0,262*230)-12,111=48,149
• I have seen that the point to be touched in the calculations made according to the deviation values I have found should be 48. The point I already touched was the 48 axes on the X axis, that is, the calibration was done correctly.

## RESULT

• Calibration of the touch panels is done by calculations as described above. Random number determination is unscientific and not true.
• Regardless of the screen size, the above method takes you to the right conclusion because it deals with the percentiles.
• When calibrating, the raw “X” and “Y” values of each point touch are substituted in the “Conclusion Formula” and the result is taken.

Be sure to watch the video lesson below for action and other details.

## Mathematical Solution of Touch Panel Calibration Video Lesson 