ILI9341 Calibration

Hello, i connected ILI9341 to an arduino and ran example touch test

#include "Adafruit_ILI9341.h" 
#include "URTouch.h"          

#define TFT_DC 9              
#define TFT_CS 10            
#define TFT_RST 8
#define TFT_MISO 12         
#define TFT_MOSI 11           
#define TFT_SCK 13            

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCK, TFT_RST, TFT_MISO);

#define t_CLK 3              
#define t_CS 4                
#define t_DIN 5              
#define t_DO 6             
#define t_IRQ 7              

URTouch ts(t_CLK, t_CS, t_DIN, t_DO, t_IRQ);

void setup(){
  tft.begin();                     
  tft.setRotation(3);           
 
  ts.InitTouch();                   
  ts.setPrecision(PREC_EXTREME);
  tft.fillScreen(ILI9341_BLACK);

  tft.setTextColor(ILI9341_RED);  
  tft.setTextSize(2);               
  tft.setCursor(85,5);              
  tft.print("Mady by alex"); 

  
  tft.setTextColor(ILI9341_GREEN);  
  tft.setCursor(20,220);           
  tft.print("Are you even reading it");
}
 
void loop()
{
  int y, x;                        
 
  while(ts.dataAvailable())        
  {
    ts.read();                      
    x = ts.getX();                 
    y = ts.getY();                  
    if((x!=-1) && (y!=-1))          
    {
      x += 0;                      
      y += 0;                       
      int radius = 4;               
      tft.fillCircle(x, y, radius, ILI9341_BLUE);
    }
  }
}

but there was a lot problems with calibration, it mirrored everything and when i was moving stylus up to down it was showing as right to left, then i tried to use Utouch calibration to calibrate it but it didnt worked for me, any tips to fix it?

Have you considered that your touch screen library may not be aware that you've rotated the display orientation?

I just checked and yes library isnt aware that i rotated the display rotation

How to fix it tho?

Not being entirely happy with any of the touch screen libraries I found out there, I ended up writing my own. Two of them actually; one for analog and one for SPI. You may want to consider doing the same.

ohh ok

I have deleted your other cross-post @yutolol .

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Hi @yutolol ,

as mentioned above the touch screen is a (more or less) separate device on top of the display. It does not know about the pixel coordinate system ...

Here is a thread that explains what you have to do to handle the rotation issue:

https://forum.arduino.cc/t/tft-lcd-coordinate-mapping-is-flipped/1195348

Good luck!
ec2021

thx

This simple sketch shows how display and touch coordinates are related in principle (may depend on the brand and libs):

If you look carefully you will see that it is not only a change in x to y but also sometimes in the direction from zero to maximum and that width and height of the display switch.

But once the principle is understood it can be easily handled...

The sketch shows

  • top left with zero rotation
  • top right 90 degrees clockwise
  • bottom left 180 degrees
  • bottom right 270 degrees