Dear community,
I have a problem with the touchscreen. Maybe somebody will know how to fix it.
I have 2.8inch TFT SPI display (ILI9341 which work without problem). Problem is with touch panel (XPT2046) connected via SPI too. I attached connection (which I checked several times). I see correct value of push force, but X and Y coordinates are not real (most of time are 31 and sometimes can reach thousands). Why? Did anyone think of how to fix it?
Here is a test code:
#include "SPI.h"
#include "Adafruit_ILI9341.h"
#include "XPT2046_Touchscreen.h"
#define LCD_cs 10
#define LCD_dc 9
#define LCD_rst 8
#define DOTYK_cs 7
Adafruit_ILI9341 displej = Adafruit_ILI9341(LCD_cs, LCD_dc, LCD_rst);
XPT2046_Touchscreen dotyk(DOTYK_cs);
void setup() {
displej.begin();
dotyk.begin();
displej.setRotation(0);
displej.fillScreen(ILI9341_BLACK);
displej.setCursor(0, 0);
displej.setTextColor(ILI9341_WHITE);
displej.setTextSize(1);
displej.println("Dotykovy displej");
displej.setTextSize(3);
displej.println("2.4 TFT LCD");
displej.setTextSize(2);
displej.println("navody.");
displej.println("arduino-shop.cz");
}
void loop() {
if (dotyk.touched()) {
TS_Point bod = dotyk.getPoint();
displej.fillRect(115, 100, 100, 50, ILI9341_BLACK);
displej.drawRect(20, 200, 100, 100, ILI9341_RED);
displej.drawFastHLine(10, 90, 220, ILI9341_BLUE);
displej.drawFastVLine(110, 90, 100, ILI9341_GREEN);
displej.setCursor(0, 100);
displej.setTextColor(ILI9341_WHITE);
displej.setTextSize(2);
displej.print(" Tlak = ");
displej.print(bod.z);
displej.println(",");
displej.print("Sour. x = ");
displej.print(bod.x);
displej.println(",");
displej.print("Sour. y = ");
displej.print(bod.y);
displej.println();
if (bod.x > 580 & bod.x < 1660 & bod.y > 2100 & bod.y < 3500 ) {
displej.setCursor(35, 240);
displej.print("Stisk!");
} else {
displej.fillRect(35, 210, 80, 80, ILI9341_BLACK);
}
}
delay(1);
}
Thanks!
UK
