Utouch wrong coordinates, ILI9341 2.8 LCD

this is my small test program:

void setup()

void loop()
  while (true)
    if (myTouch.dataAvailable())

Now the screen is in portrait position meaning that x should be 240 and y 320 max. Below are the logs of each corner

LEFT-UP 235,15 (lets skip the fact that it should be 240,0, as ther can be ± 15pixels difference)
RIGHT-UP 230, 330

The problem in PORTRAIT mode are:

  • x is longer than y it is reverted
  • touching LEFT-UP corner prints RIGHT-UP coordinates
  • touching RIGHT-UP corner prints RIGHT-BOTTOM coordinates
  • touching LEFT-BOTTOM corner prints LEFT-UP coordinates
  • touching RIGHT-BOTTOM corner prints LEFT-BOTTOM coordinates

in LANDSCAPE mode it is even worse

  • also x is longer than y (xmax = 380, ymax = 240
  • points are about half screen away, looks like screen ends 1,5cm above the real end and bottom 1,5 cm of the screen gives the same coordinates as 1,5 above

Moreover it doesnt work every restart - sometimes turning power of doesnt help, after some restarts / uploading from Arduino IDE 1.5.5 r2 it works but then it prints wrong coordonates.

Try this calibration set in UtouchCD.h file

// Touch ILI9341 ---->Rotación 3/LANDSCAPE
#define CAL_X 0x0399812BUL
#define CAL_Y 0x0047CE18UL
#define CAL_S 0x000EF13FUL

Serial Monitor-output & TFT-output

#include <UTFT.h>
#include <UTouch.h>

//24SPI, 28SPI
UTFT myGLCD(ILI9341_S5P,MOSI,SCK,10,8,9); 

 //touch panel (TCLK, TCS, TDIN, TDOUT, IRQ), XPT2046
UTouch  myTouch( 6, 5, 4, 3, 2);

extern uint8_t BigFont[];
int x, y;

void setup() 
  myGLCD.setBackColor(0, 0, 0);
  myGLCD.setColor(0, 255, 0);


void loop()
  while (true)
    if (myTouch.dataAvailable())

 // TFT-output
      myGLCD.print("x=       ", 50, 100);
      myGLCD.printNumI(x, 85, 100);
      myGLCD.print("y=       ", 185, 100);  
      myGLCD.printNumI(y, 220, 100);
// Serial-output            
      Serial.print("x= ");
      Serial.print("   y= ");            
      Serial.println("   ");    


Way better but still somethin is wrong, I dont use UTFT library but see it on serial log:

Now I am handling LCD like u in landscape position..

(there are +-5 pixels differences but I skip them) LEFT-UP 0,0 RIGHT-UP 320, 0 LEFT-BOTTOM 0,220 RIGHT-BOTTOM 320,240 WORKS IN LANDSCAPE !!!

But my program is running on Adafruit_ILI9341 and the it is PORTRAIT menu items, top of the screeen should be where thos 4 pins and "J4" is written.

So in PORTRAIT mode I have this problem:


EDIT: no errors in PORTRAIT ALSO, must have not uploaded it before

THANKS VERY MUCH How did u do that?

Also, try this library: http://marekburiak.github.io/ILI9341_due/ (It´s "insane" with Arduino MEGA and more with Arduino Due jejeje)

ILI9341 due lib

Some test https://www.youtube.com/watch?v=E4qZTWaSeq8


I´m used voltage dividers, made it with 1K and 2K resistors in this lines: TFT_CS, TFT_D/C, TFT_RESET, TFT_MOSI, TFT_SCK. All soldered on proto-shield for arduino UNO, and some pins and proto-wires recycled. It´s some... ugly thing..., but it´s efficient



i got problems with utouch and getting the right coardinates too, so i am working on getting spi work for that chip. Why spend a lot of pins and waste time on bit banging?
This is how far i hawe come:

void setup(){

pinMode (cs, OUTPUT);
pinMode ( irq, INPUT);

digitalWrite(cs, LOW);
SPI.transfer (0x92);
digitalWrite(cs, HIGH);


void loop(){

if (digitalRead (irq) == LOW) {
digitalWrite (cs, LOW);
int tty = 0;
int ttx = 0;

ttx = SPI.transfer(0x00) << 5;
ttx = ttx | SPI.transfer(0x90) >> 3;
tty = SPI.transfer(0x00) << 5;
tty = tty | SPI.transfer(0x00) >> 3;

digitalWrite (cs, HIGH);

Just measure max and min in each axel and divide it by the pixales and you shold get an fast and acurate touch…

on 8 mhz i need "SPI.setClockDivider(SPI_CLOCK_DIV4);" to get it work, if you running a 16 mhz chip you vill need to add SPI.setClockDivider(SPI_CLOCK_DIV8);. ili9341 should handel a spi clock divider of two. So add clock divider by 8 in beginning of touch commands and clock divider by 2 before tft commands.

For me this works quite good on my screen:

x = (ttx-440)/13; y = (tty-280)/11;

for exemple: if the lowest reading in x is 440. then remove 440 from ttx. the highest is 3560, remove 440 from that and divide it into the pixels and you get 13.

This simple touch library for the 2046 touch screen driver may be of interest and is usable with any graphics library.

The example in the library reports raw and transformed x,y touch coords via the Serial port at 38400 baud, it does not plot/draw anything on the screen as that needs a graphics library and not everyone uses the same library set.

By setting the screen resolution to a low value say 3,4 the display will be divided into a grid of 12 touch zones. It is also possible to define the touch rectangle to be anywhere and any size on the screen so for example the valid touch zones can be over a 4 x 4 key pad matrix, and reading back Zone() will report which zone was touched, this avoids tedious checking of coordinate ranges. More examples will follow.

This is a library that is being developed further so it is quite simple and does not include touch filtering at the moment. The aim is to store calibration values in the Arduino’s EEPROM so that the libraries do not have to be tweaked with calibration values for each different display you have.

Control signals are bit bashed but reading x and y values only takes just over 1 millisecond.

Touch_ASv2.zip (6.57 KB)


I have the same board as you. My screen works, though I used a CD4050 to reduce the pin voltage.

PLEASE please tell me how you connected your touch part - T_CLK, T_CS, t_DIN, T_DO, T_IRQ.

I just can get touch working and don't know if it's software or connections as I can't rule out either.

Kind regards