Forum - MCS Electronics

Author Message
daro

Joined: 15 Nov 2010
Posts: 18

Posted: Sat Mar 14, 2020 1:33 pm    Post subject: Touch callibration problem LCD TFT 4.3" XPT2046

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

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

 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 )
daro

Joined: 15 Nov 2010
Posts: 18

Posted: Thu Mar 19, 2020 12:00 am    Post subject:

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

 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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1

 Jump to: Select a forum BASCOM AVR/8051----------------BASCOM-AVRBASCOM-8051BASCOM-ARDUINOShare your working BASCOM-8051 code hereShare your working BASCOM-AVR code hereBASCOM BETA-SLA BASCOM Related----------------EASY TCP/IPAVR-DOSAR7212KokkeKat FAT-free SD card libBASCOM Project Blog Other Stuff----------------VariousPCB'sRoboticsNew WebSiteAnnouncementsAVR Archive----------------BASCOM-AVR ArchiveBASCOM-8051 ArchiveBASCOM-AVR Unsupported versionsEasy TCP/IP ArchiveBASCOM-EDB
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