2.4" LCD TFT 240x320 display SPI


I have some troubles with my 2.4" touch display (purchased from HERE) and wired and tested by diagram and code from THIS page.

Iam using breadboard to test it with Arduino Uno R3 and i have those issues:

1) sometimes the LCD is just white (but its very rare) 2) very often the LCD acts like its been touched, the x,y and z are changing very quickly and randomly... the z value is most of the time about 4089 but it drops even to 1000 or 300 and then back to 4090. The x and y are changing randomly also, sometimes there is 0 x 0 but rather more there are some higher numbers. When this x,y,z values are constantly changing it doesnt seems to registering my attempts for touches 3) in some very rare moments, when it actually works as wxpected (with no code change at all), iam able to touch it and get the valus but its a bit strange that any corner I try to touch with the stylus, thy x and y are never close to 0 (maybe I didnt understand how the addressing works but i would expect that somewhere would be the 0,0). The lowest value is somewhere about 350 and when i touch the same place more times, it can differ even more that +100 like from 350 to 450 or even 500 and I dont get it... I mean yes it propably isnt super accurate and i can press the stylus some 1 or 2mm nearby the last touch but still +100 is way off right?

220R and 470R are very low values. 2k2 and 4k7 would seem wiser.

You should remove the resistors from the SDO (MISO) line. This is probably why you get inconsistent results. The MISO signal is 3.3V. If you divide it with the resistors you will get a 2.2V signal which is not very reliable on a 5V Uno.


david_prentice: 220R and 470R are very low values. 2k2 and 4k7 would seem wiser.

You should remove the resistors from the SDO (MISO) line. This is probably why you get inconsistent results. The MISO signal is 3.3V. If you divide it with the resistors you will get a 2.2V signal which is not very reliable on a 5V Uno.


Thanks I will try... just out of curiosity, what the difference between that resistors? The guy in that manual used formula (5V*470 ohm) / (470 ohm + 220 ohm). So when I uset is with 4700 (4k7) and 2200 (2k2) instead, the result seems to be the same = 3,41V. Or the higher ohm values are different somehow else?

2k2, 4k7 give exactly the same voltage ratio as 220R, 470R or even 22R, 47R.

Think about the currents. When UNO_CS = 5V, LCD_CS = 3.4V. But the current flowing is 0.72mA when you use 2k2, 4k7 instead of the 7.2mA for 220R, 470R.

Since you have RST, DC, CS, SCK, MOSI the worst case would be 36mA if all UNO signals are 5V. Which is actually the idle state of SPI MODE3 that you would normally use with your display.

Yes, there is a side-effect of using "high-value" resistors in a potential divider. The effective "Source impedance" is 1k5 for 2k2,4k7. Or 15k for 22k, 47k.

1k5 is fine. Your screen should work well. With 15k source impedance any stray capacitance will be noticeable at fast SPI frequencies.

You do not need to know high powered Maths or Physics. Just learn Ohms Law and the rules for parallel resistors. Pencil and paper are good for drawing schematics with arrows for the current flow. Don't try to do it in your head.


Ok i tried to use 4k7 and 2k2 and copletly take away both resistors from SDO - so the one that was connected to same path leading to UNO pin 12 (2k2) and also the one that was after this one connected to ground (4k7) is that right?

The problem seems to be still there. So I tried to add one 4k7 resistor between pin 7 and T_CS (in the diagram its without any resistor at all) and the continous refresh with random coordinates x,y,z semms to stop now... at lest I hope its not one of the time its behave OK and it will not start to act like crazy again

EDIT: ok seems to be a moment when it gets crazy again but itss till so far way more better than it was.

But there is strill one huge problem - the x,y coordinates are off or broken because 3 draw six rectangles in two rows, there are 3 in one row, so 3 and 3 under them. I tried to get the position from the first one - from top left corner and bottom right corner. I got 2928/2225 vs 3784/784 but when i try to get tge coordinates now, i get way different walues like 4094/1704 vs 4094/4094 and then I got 4094/4094 almost on whole place around as many time as I touch.... and still no corner of display is 0/0 .....

Oops. I had not studied the schematic closely.

Yes, you need 2k2, 4k7 on the T_CS line. Yes, T_CLK, T_DIN should connect straight to SCK, SDI

Think about it. Output signals from the 5V Uno must use 2k2, 4k7 potential dividers. Input signal from T_DO or SDO is 3.3V. T_DO, SDO should go straight to Uno D11 pin.

Personally, I always use proper 3.3V Arduinos. (Actually Uno with switchable 3.3V/5V )

The resistors should work ok. I would either buy an 8-channel level-shifter chip or a 3.3V Arduino. Many people have your Red display. I have one. It works fine with 3.3V logic.


Ok I just find out that i need to calibrate the display by taping the rocners, find out the max and min valuss for X and Y and define it like:

#define TS_MINX 176
#define TS_MINY 218
#define TS_MAXX 3920
#define TS_MAXY 3900

TS_Point p=ts.getPoint();
 p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320);
 p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240);

Strange thing is, they have the max values for X like 960 in the manuals and it corresponds to one video guide, where they explained that actualy each pixel is from three elements (RGB) and therefore it would be a match because 320px * 3 is 960. I have no idea why I have the coordinates like 3900 and also why I can get in 20 touch to the same place vaalues like 176 - 450 tahts a huge difference. But I will test it with this calibration and see if it will be more accurate

The XPT2046_Touchscreen.h library returns 12-bit values i.e. 0-4095 Unintelligent Resistive panels use Touchscreen.h library which returns 10-bit values i.e. 0-1023

Which is why you see typical TS_LEFT, TS_RT values for Touchscreen.h

const int TS_LEFT=907,TS_RT=136,TS_TOP=942,TS_BOT=139;

The equivalents for XPT2046 library would have values like 3900 instead of 900.

Even if you do not calibrate, you can draw a pixel at (p.x, p.y) Move the stylus horizontally. Does the "spot" move horizontally or vertically? if direction is wrong, swap X, Y Does the spot move backwards? if direction is wrong, swap LEFT, RT

Simple really. Just think about it.


Thanks now I undersrand why te numbers was so high… I know i could still draw some shape but it was a bit problematic with the if x>= && x<=… now when it is calibrated ist way easier I just put the same coordiantes and it works like a charm :))))

Ok I take it back... it worked just fine yesterday. Today I uploaded shorter code just to test some text print and count for center aligment, that worked also fine. Then I decided to connect the ethernet shiled on the UNO and wire the LCD exactly the same way on the ethernet shield and it started to go crazy again even faster then before. So I pull out the ethernet shiled and wire it back just to UNO and its still crazy....

I dont know why it sudddenly behaves like that when it worked just fine. Iam so lost now...

I doubt if you have enough pins on a UNO for Ethernet and TFT.

Check what pins are used by each component.


Iam not using anything ont he ethernet shield so far... i only connect it on the UNO and connect the LCD. But anyway even if this would be some case of using some pins that use the shield it doesnt explain why the problem continue on the UNO (without the ethernet shiled). I just rewire it to the UNO and upload the same program taht worked before... and its not working now

Here is the link to the video...even the backlight is flickering and the pressure (Tlak) and x,y are changing like crazy.... https://youtu.be/_UE0fip-8l0

EDIT: Iam so soryy... it was my mistake... I dont know how and when but I manage disconnect the 7 pin cable from the arduino going to LCD (it was connected to nowhere). So it finely works again and I think you have right about the ethernet shield as well. I noticed its the SD card issue - when I pull out the microSD the problem with touch xyz refreshing stops.

Sorry. I thought that I was replying to a different Touch Screen.

I would be amazed if anything good comes out of your rats nest of wires. If you put appropriate 2k2, 4k7 dividers on every output signal it should work ok.

Of course we have no idea what your sketch is doing. It is always wise to run all the library examples.

If you have a problem, quote which library and which example.

When the examples run ok, I will be happy to try the code in your link. I don't understand Czech but I do understand the Adafruit library.

Hey-ho. I ran your code on a Red ILI9341 screen. My X, Y were swapped. I suspect that your Touch panel will be like mine.

I see little point in displaying the RAW values. It is more useful to map to the Pixel coordinates.



this is my main testing code, it should just return xyz on touch and it works on UNO (on the shield the refreshing is caused if I pug in microSD card). The only issue now on the UNO itself is that time to time it seems the coordinates recalibrate themself… one moment they are OK and then suddenly same place taht should return x=50 or x=150 is returning x = -14 and its returnind this same value (x = -14) anywhere in X axes from left to aprox. half of the display itself, so in one half of the display is just x = -14… but when i upload the program again once or twice the coordinates are OK again… till they recalibrate again at some point.

#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>

#include "SPI.h"
#include "Adafruit_ILI9340.h"
#include "XPT2046_Touchscreen.h"

#define LCD_cs 10
#define LCD_dc 6
#define LCD_rst 8
#define DOTYK_cs 7

#define COLOR1     0x280B

#define TS_MINX 176
#define TS_MINY 218
#define TS_MAXX 3920
#define TS_MAXY 3900

Adafruit_ILI9340 displej = Adafruit_ILI9340(LCD_cs, LCD_dc, LCD_rst);
XPT2046_Touchscreen dotyk(DOTYK_cs);

void setup() {



void loop() {

  if (dotyk.touched()) {

    TS_Point bod = dotyk.getPoint();

    bod.x = map(bod.x, TS_MAXX, TS_MINX, 0, 320);
    bod.y = map(bod.y, TS_MAXY, TS_MINY, 240, 0);

    displej.fillRect(0, 0, 220, 27, COLOR1);
    displej.setCursor(0, 5);
    displej.print("   Tlak = ");
    displej.print(" x/y = ");
    displej.print(" / ");


    bod.x = 0;
    bod.y = 0;
    bod.z = 0;




I think I manage to solve the “refreshing xyz” problem by simply activating and deactivating the “services” by only one at the time - for example I will have only the touch screen active and etehrnet with SD card will be deactivated (digitalWrite(SHIELD_ETHERNET, HIGH); digitalWrite(SHIELD_SDCARD, HIGH);)… after I touch it, I will deactivate the touch capability (by if(SHIELD_ETHERNET == LOW) then i will not run the .getPoint();) and after I get some response I need I will deactivate the Ethernet… that will suppresses any unwanted comunication through SPI from more devices.

But I still dont know why the X and Y are sometimes OK and sometimes recalibrated. My frined who worked in company which makes gaming machines told me, they have simmilar problems with calibrations when the LCD displey are not grouded to the metal constructions (so when they just test them on the table). But I guess the connection to Arduino GND should be enough or the ardunino itself need to be somehow grounded to piece of metal ad well???