Issue with calibration of display (ili9341 display and xpt 2046 touch controller)

Wow, that really strange. Three y values are quite the same. Maybe this TP is broken?

What are the very raw data if you press the corners?
You should print them here: https://github.com/littlevgl/lv_drivers/blob/master/indev/XPT2046.c#L87

if(irq == 0) {
        gpio_set_level(TP_SPI_CS, 0);
        tp_spi_xchg(CMD_X_READ);         /*Start x read*/

        buf = tp_spi_xchg(0);           /*Read x MSB*/
        x = buf << 8;
        buf = tp_spi_xchg(CMD_Y_READ);  /*Until x LSB converted y command can be sent*/
        x += buf;

        buf =  tp_spi_xchg(0);   /*Read y MSB*/
        y = buf << 8;

        buf =  tp_spi_xchg(0);   /*Read y LSB*/
        y += buf;
        gpio_set_level(TP_SPI_CS, 1);

        printf("x= %d Y=%d\n",x,y);

        /*Normalize Data*/
        x = x >> 3;
        y = y >> 3;
       // xpt2046_corr(&x, &y);
        xpt2046_avg(&x, &y);
        last_x = x;
        last_y = y;

Did what you asked for
Results -
First point (left top) -
x= 13568 Y=9216
x= 13568 Y=9216
Second point (right top) -
x= 4088 Y=9216
x= 4088 Y=9472
Third point (right bottom)-
x= 4088 Y=8184
x= 4088 Y=8184
x= 4088 Y=7936
x= 4088 Y=8184
Fourth point (left bottom) -
x= 13312 Y=4088
x= 13312 Y=4088

what I see on screen

If look at the X coordinates they are good. The two right and two left coordinates are quite the same.
However “right-bottom” is almost like the “top” coordinates.

Probably your touchpad is broken :frowning:

alright I will get new touchpad check it up(need sometime)

So i did get new screen and touch pad combo
and ran tpcal onto it

The same issue again. The right botom Y should be ~500. However, the 1023 value is very specific. Can is be a driver (reading) issue?

I am also having issues with the touch screen.
Have been following this thread as the issue is similar to mine.
The spi init function has the clock speed set at 10MHz, which seems to me to be much too fast.
I have change it to:
.clock_speed_hz=1 * 1000 * 1000, //Clock out at 80 MHz

And the result is much much more stable, almost perfect in fact but still not 100% usable.
I have to go out for a while now, but will carry on with it when I get back.

Thought it was worth mentioning :slight_smile:

File is tp_spi.c btw.

1 Like

So, after slowing the SPI down and a recal, it is now perfect. :slight_smile:

1 Like

After testing few different setting mentioned by @kisvegabor and @Duinui
I came to the conclusion that it does work when you do these settings

#define XPT2046_AVG 4
#define XPT2046_X_MIN       0
#define XPT2046_Y_MIN       0
#define XPT2046_X_MAX       4095
#define XPT2046_Y_MAX       4095
#define XPT2046_X_INV       0
#define XPT2046_Y_INV       0

clocked down to 80hz

Now does work on code which is standalone (not using the demo apps)
u get the touch co-ordinates properly but I am not sure what what was bug what causing the issue in first place.
Still I test more on this and update you guys as I go from here.
Thanks to @kisvegabor @Duinui & @embeddedt
Ps- will post the result of the esp32 + littlevgl project as example once I am done

@kitarp
It was pretty much black and white for me, when the SPI was slowed down, it worked.
Looking at the Datasheet I have for the 2046, Tacq is 1.5uS so really there should be a small delay between issuing the command to READ-X/READ-Y before actually reading it.
I also have fairly long Dupont connectors, which doesn’t help.

Hey @Duinui
its also worth mentioning that I did the same test over and over got new display and tested it out but it was not working. But when I added this to the file xpt2046.c

 printf("x= %d Y=%d\n",x,y);
   /*Normalize Data*/
        x = x >> 3;
        y = y >> 3;
        xpt2046_corr(&x, &y);
        xpt2046_avg(&x, &y);
        last_x = x;
        last_y = y;
 printf("x= %d Y=%d\n",x,y);

This statement changed the results maybe I don’t know but still I am mentioning it

Also I made it work on 100hz in the setting and now it has same results. No issues whatsoever.
Maybe I need play around with sliders and such to check it there is drift in the touch or something else.

Very likely. Adding a printf statement is effectively adding the delay that @Duinui mentioned.

It would be a better idea to use an actual delay function and determine the necessary wait time.

2 Likes

@embeddedt & @Duinui
Okay so I added delay in the same line and also tested so far good going there are no issue what so ever.
added and tested slider and it does work

1 Like

Hi, I’ve got stranger things too. I always get 320x240 px on every position.
My wiring is default for esp32, ili9341 and xpt2046, as described in the examples.
I also have tested the slow down, but not working.
Is my TP bad?

@versteckt
This may sound obvious, but are you ABSOLUTELY sure your wiring matches the pin definitions in tp_spi.h and xpt2046.h.
What you describe sounds very much like the SPI for the TP is not working at all.

Hi, I think so too. I’ve tested now the display via an arduino nano and touch is working.

Here’s my Wiring and configuration:
Wiring:

VCC			3V3
GND			GND
CS			5
RESET		18
DC			19
SDI(MOSI)	13
SCK			14
LED			3V3
SDO(MISO)	35
T_CLK		26
T_CS		33
T_DIN		35
T_DO (OUT)	32
T_IRQ		25

Configuration:

DISP_SPI_MOSI	13
DISP_SPI_CLK	14
DISP_SPI_CS	5

ILI9341_DC	19
ILI9341_RST	18
ILI9341_BCKL	23

TP_SPI_MOSI	32
TP_SPI_MISO	35
TP_SPI_CLK	26
TP_SPI_CS	33

XPT2046_IRQ 25

Pin configuration is correct. So what is the issue?
did u use the latest code from git repo?

I downloaded the code only two days ago, so it should be pretty up to date.
No matter where I click, it always comes as x 320 and as y always 240.
I tested it with the tpcal application.

@versteckt
You have the TP MOSI and MISO switched.

1 Like