Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Touch callibration problem LCD TFT 4.3" XPT2046

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
daro

Bascom Member



Joined: 15 Nov 2010
Posts: 25

blank.gif
PostPosted: Sat Mar 14, 2020 1:33 pm    Post subject: Touch callibration problem LCD TFT 4.3" XPT2046 Reply with quote

I have problem to set up and callibrate touch for 4,3" 480x272 display.
Touch using XPT2046 IC on module.

I read ADC points:
1. Coordinate X=30, Y=30
X1=3700 = Xs
Y1=3400

2. Coordinate X=450, Y=30
X2=300 = Xe
Y2=3400 = Ye

3. Coordinate X=240, Y=240
X3=2000
Y3=600 =Ys

Callibration:
Code:
   Xdiff = Xs - Xe
   X_fact = Xdiff / 480
   Xoff = 30 * X_fact
   X_offset = Xe - Xoff

   Ydiff = Ye - Ys
   Y_fact = Ydiff / 272
   Yoff = 30 * Y_fact
   Y_offset = Ys - Yoff

   Xo = X_offset
   Yo = Y_offset
   Xf = X_fact
   Yf = Y_fact


After Read:
Code:
   Tx = Tx - X_offset
   Res = Tx / X_fact
   Touchx = Int(res)

   Ty = Ty - Y_offset
   Res = Ty / Y_fact
   Touchy = Int(res)

   If Touchx > 480 Or Touchy > 272 Then
      Touchx = 0
      Touchy = 0
      If Touch_test = 1 Then Lcd_tt_text "Error" , 200 , 50 , Red
   Else
      If Touch_test = 1 Then
         Lcd_tt_text "Read touch" , 170 , 50 , Red
         Call Lcd_fill_circle(touchx , Touchy , 10 , Red)
         Call Lcd_circle(touchx , Touchy , 40 , Red)
      End If
   End If


After use code and callibration read X and Y position is incorrect. What is wrong in my code?
Read X and Y are in different, strange positions.

(BASCOM-AVR version : 2.0.8.2 )
Back to top
View user's profile
daro

Bascom Member



Joined: 15 Nov 2010
Posts: 25

blank.gif
PostPosted: Thu Mar 19, 2020 12:00 am    Post subject: Reply with quote

Problem resolved:

Callibration part:

Code:
   Xdiff = Xs - Xe
   X_fact = Xdiff / 419                                     'podzielić na odległość między Xs a Xe  minus 1pix
   Xoff = 30 * X_fact                                       'razy współrzędna punku Xs
   X_offset = Xe - Xoff

   Ydiff = Ye - Ys
   Y_fact = Ydiff / 209                                     'podzielić na odległość między Ys a Ye  minus 1pix
   Yoff = 30 * Y_fact                                       'razy współrzędna punku Ys
   Y_offset = Ys - Yoff

   Xo = X_offset
   Yo = Y_offset
   Xf = X_fact
   Yf = Y_fact


Read part:

Code:
   Tx = Tx - X_offset
   Res = Tx / X_fact
   Touchx = Int(res)

   Ty = Ty - Y_offset
   Res = Ty / Y_fact
   Touchy = Int(res)

   Touchx = 480 - Touchx
   Touchy = 272 - Touchy
Back to top
View user's profile
Kasch

Bascom Member



Joined: 18 Jun 2005
Posts: 48

PostPosted: Sun Sep 03, 2023 8:51 am    Post subject: Reply with quote

Hello, what display you are using? Thank you
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum