Comments (23)
Yes, that's right. I guess, it is called "linear interpolation/extrapolation". I leave my code here in case of someone will have same problem.
int32_t int_ext(int32_t x1, int32_t y1, int32_t x2, int32_t y2, int32_t x)
{
return y2 - (x2-x) / ((x2 - x1) / (y2 - y1));
}
And, calibration and after aquiring raw data:
x = int_ext(cal_data.point[0].x, CIRCLE_OFFSET + CIRCLE_SIZE / 2, cal_data.point[1].x, LCD_HOR_RES - CIRCLE_OFFSET + CIRCLE_SIZE / 2, x);
y = int_ext(cal_data.point[1].y, CIRCLE_OFFSET + CIRCLE_SIZE / 2, cal_data.point[2].y, LCD_VER_RES - CIRCLE_OFFSET + CIRCLE_SIZE / 2, y);
from lv_port_esp32.
, I am trying to integrate it into the example, but formulas seem to be wrong. I get negative values using them.
What are the coordinates you measured and the resolution of your display?
Which of them is x1_saved and x2_saved?
x1_saved
is the left coordinatex2_saved
is the right coordinatey1_saved
is the top coordinatey2_saved
is the bottom coordinate
from lv_port_esp32.
Hello kisvegabor and thanks for the best embedded graphical library in the world!
I have a 3.2" 320x240 ILI9341 LCD with XPT2046 Touch screen in landscape mode.
I get values from about 340 to about 3900 on X axis and from 200 to 3850 on Y axis. These are raw values from a touchscreen.
The calibration routine from LittlevGL tpcal.c file collects raw coordinates of 4 points in the corners of the screen, but I cannot figure out what to do with these data. How to apply them to the raw touch screen coordinates in order to calculate true coordinates in pixels.
from lv_port_esp32.
So in your case:
x1_saved = 340
x2_saved = 3900
- lets say
x_act = 1000
(should be about at ~25% in x)
x_cal = ((1000 - 340) * 320) / (3900-340)
x_cal = (660 * 340) / 3560
x_cal = 22400 / 3560
x_cal = 63
So the pressed cooridinate is x = 63, (Really ~25% of 320)
from lv_port_esp32.
I am having a hard time calibrating the display , The example of calibration is not working as Make fails
I tried few things but I didn't get the touch calibrated
I am running default configs with the ili9341 display and xpt 2046 touch controller res = 320x240
Didnt make any changes at all in the example sketch
from lv_port_esp32.
What error message do you get exactly?
from lv_port_esp32.
So the demo does work, I placed a small button in the right in the middle (0,0) of the display (320x240). when I touch on the button there is no output but if i touch the display slightly away from the button on left side it doe register. So it is issue of calibration but i have no idea how to calibrate the touch.
#define XPT2046_AVG 4
#define XPT2046_X_MIN 1000
#define XPT2046_Y_MIN 1000
#define XPT2046_X_MAX 3200
#define XPT2046_Y_MAX 2000
#define XPT2046_X_INV 1
#define XPT2046_Y_INV 1
this is what I have in xpt2046.h
Also, I modified xpt2046.c to see the raw input from the xpt
if(data->state == LV_INDEV_STATE_PR) printf("X= %5d, Y=%5d \r\n",data->point.x, data->point.y);
from lv_port_esp32.
#define XPT2046_X_MIN 1000
#define XPT2046_Y_MIN 1000
#define XPT2046_X_MAX 3200
#define XPT2046_Y_MAX 2000
Are these the raw data you have measured for the corners?
from lv_port_esp32.
X1 = 200 , X2 = 320
Y1 = 240, Y2 = 240
these are raw value I am getting from the function that i measured
co-ordinate in center of display (raw value) is (X=170,Y=10 to 12)
#define XPT2046_X_MIN 1000 #define XPT2046_Y_MIN 1000 #define XPT2046_X_MAX 3200 #define XPT2046_Y_MAX 2000
this is defined by default in xpt2046.h
from lv_port_esp32.
By raw value, I meant the raw value in XPT2046
. E.g. the x and y values here. These are still not scaled but really the raw data from the touch controller.
from lv_port_esp32.
So the raw value i got from
xpt2046_corr(&x,&y);
top left = (200,204)
top right =(320,196)
bottom left = (224,240)
bottom right = (320,240)
from lv_port_esp32.
I meant BEFORE xpt2046_corr
where the calibration values ae still not applied.
from lv_port_esp32.
top left = (1952,1216)
top right =(511,1184)
bottom left = (1696,503)
bottom right = (511,511)
from lv_port_esp32.
Then you should:
#define XPT2046_X_MIN 511
#define XPT2046_Y_MIN 505
#define XPT2046_X_MAX 1800 //Somewherre between 1696 and 1952
#define XPT2046_Y_MAX 1200
from lv_port_esp32.
xpt2046_corr(&x,&y);
Okay so got some output, atleast it register input on display, But there is some offset.
#define XPT2046_X_MIN 511
#define XPT2046_Y_MIN 505
#define XPT2046_X_MAX 1800
#define XPT2046_Y_MAX 1500 // 1200 didnt work
How should I go ahead ?
ps - thank you so much for your valuable time !
from lv_port_esp32.
It's strange. I've checked xpt2046_corr
and seems correct. Can you print the intermediate values during the calculation?
from lv_port_esp32.
Yeah I can print just tell me what values you want to know, I tried multiple things but no output.
static void xpt2046_corr(int16_t * x, int16_t * y)
{
#if XPT2046_XY_SWAP != 0
int16_t swap_tmp;
swap_tmp = *x;
*x = *y;
*y = swap_tmp;
#endif
if((*x) > XPT2046_X_MIN)(*x) -= XPT2046_X_MIN;
else(*x) = 0;
if((*y) > XPT2046_Y_MIN)(*y) -= XPT2046_Y_MIN;
else(*y) = 0;
(*x) = (uint32_t)((uint32_t)(*x) * LV_HOR_RES) /
(XPT2046_X_MAX - XPT2046_X_MIN);
printf("cor_X= %5d",*x); //do you want these values? x
(*y) = (uint32_t)((uint32_t)(*y) * LV_VER_RES) /
(XPT2046_Y_MAX - XPT2046_Y_MIN);
printf("cor_Y= %5d",*y); //y
#if XPT2046_X_INV != 0
(*x) = LV_HOR_RES - (*x);
#endif
#if XPT2046_Y_INV != 0
(*y) = LV_VER_RES - (*y);
#endif
}
from lv_port_esp32.
I tried multiple things but no output.
Probably it's because you forgot the \n
at the end.
Let's try this:
static void xpt2046_corr(int16_t * x, int16_t * y)
{
printf("raw_X= %5d\n",*x);
#if XPT2046_XY_SWAP != 0
int16_t swap_tmp;
swap_tmp = *x;
*x = *y;
*y = swap_tmp;
#endif
printf("swap_X= %5d\n",*x);
if((*x) > XPT2046_X_MIN)(*x) -= XPT2046_X_MIN;
else(*x) = 0;
printf("min_sub_X= %5d\n",*x);
if((*y) > XPT2046_Y_MIN)(*y) -= XPT2046_Y_MIN;
else(*y) = 0;
(*x) = (uint32_t)((uint32_t)(*x) * LV_HOR_RES) /
(XPT2046_X_MAX - XPT2046_X_MIN);
printf("mult_X= %5d\n",*x);
(*y) = (uint32_t)((uint32_t)(*y) * LV_VER_RES) /
(XPT2046_Y_MAX - XPT2046_Y_MIN);
#if XPT2046_X_INV != 0
(*x) = LV_HOR_RES - (*x);
#endif
printf("inv_X= %5d\n",*x);
#if XPT2046_Y_INV != 0
(*y) = LV_VER_RES - (*y);
#endif
printf("\n");
}
from lv_port_esp32.
Alright , I will test the values and comeback.
I did add \n later (after my reply here) got same values as before. Still I will retest once I get back to my lab.
from lv_port_esp32.
So I tried the following code and got these readings
static void xpt2046_corr(int16_t * x, int16_t * y)
{
#if XPT2046_XY_SWAP != 0
int16_t swap_tmp;
swap_tmp = *x;
*x = *y;
*y = swap_tmp;
#endif
if((*x) > XPT2046_X_MIN)(*x) -= XPT2046_X_MIN;
else(*x) = 0;
if((*y) > XPT2046_Y_MIN)(*y) -= XPT2046_Y_MIN;
else(*y) = 0;
(*x) = (uint32_t)((uint32_t)(*x) * LV_HOR_RES) /
(XPT2046_X_MAX - XPT2046_X_MIN);
printf("corrX= %d",*x);
(*y) = (uint32_t)((uint32_t)(*y) * LV_VER_RES) /
(XPT2046_Y_MAX - XPT2046_Y_MIN);
printf("corrY= %5d\n",*y);
#if XPT2046_X_INV != 0
(*x) = LV_HOR_RES - (*x);
#endif
#if XPT2046_Y_INV != 0
(*y) = LV_VER_RES - (*y);
#endif
}
from lv_port_esp32.
The magnitude of the numbers seems correct. From this, I can't tell more because I don't know where you touched the screen. What are the values if you touch the center of the screen?
from lv_port_esp32.
Its not like exact centre but it is around that area.
the values I got from the touch
from lv_port_esp32.
I suggest continuing it on the Forum. You can reach more people there who hopefully already had a similar issue.
Please post your last results in Get started category.
from lv_port_esp32.
Related Issues (20)
- Cannot build project with LVGL as component HOT 1
- SPI display drivers do not play nice with other spi devices
- esp32-s3 invalid dma channel HOT 1
- Portrait mode of demos doesn't display correctly
- The link to the forum when you write a PR/issue is incorrect HOT 1
- build with esp-idf-4.4.3 fails HOT 1
- failed to run idf.py menuconfig HOT 2
- updated LVGL+squareline studio+ ESP32 HOT 2
- Demo on older esp-wrover-kit board ( not v4.1) HOT 2
- Display not showing the correct windows while running this example HOT 2
- Sunton ESP32-8048S070 board HOT 8
- How can I add my own components to the project
- Unable to compile on esp-idf version 5.0 HOT 4
- undefined reference to `lv_obj_set_scroll_propagation'
- Cant turn off LV_USE_FLEX
- Horizontal scrolling HOT 4
- fatal error: Arduino_H7_Video.h: No such file or directory
- ESP32C3 - non-LVGL task (temp reading) causes TFT display to go blank and stay blank on second run of task HOT 1
- ssd1306 driver
- ssd1306
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lv_port_esp32.