First off all, thanks for the reply. I ran the calibration and the paint sketch again and adjusted the values in my Sketch, that I get from the Serial Monitor. I´m still a few Pixels off but a bit closer than last time. I ordered a new display just to check if there is an fabrication failure. But now running into the next problem..
This is Sketch I wrote to test the accuracy of the touchscreen:
#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
// MCU Values
//const int XP=8,XM=A2,YP=A3,YM=9; //240x320 ID=0x9341
//const int TS_LEFT=918,TS_RT=98,TS_TOP=75,TS_BOT=901;
//PORTRAIT CALIBRATION 240 x 320
//x = map(p.x, LEFT=918, RT=98, 0, 240)
//y = map(p.y, TOP=75, BOT=901, 0, 320)
// USB-Port faces downwards
#define TS_MINX 918// TS_LEFT
#define TS_MINY 75// TS_TOP
#define TS_MAXX 98// TS_RT
#define TS_MAXY 901// TS_BOT
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
const int XP = 8;
const int XM = A2;
const int YP = A3;
const int YM = 9;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); // Resistance between D8 and A2
void setup() {
Serial.begin(9600);
Serial.print("Starting...");
tft.reset();
//tft.begin(tft.readID());
tft.begin(0x9341);
tft.setRotation(0);
}
void loop() {
TSPoint p = ts.getPoint(); //Get touch point
if (p.z > ts.pressureThreshhold) {
p.x = map(p.x, TS_MINX, TS_MAXX, 240, 0);// setRotation(0)
p.y = map(p.y, TS_MINY, TS_MAXY, 320, 0);// setRotation(0)
Serial.println("Koordinaten");
Serial.println(p.x);
Serial.println(p.y);
}
if (p.x > 0 && p.x < 240 && p.y > 0 && p.y < 320) {
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
tft.fillScreen(BLACK);
tft.fillRect(p.x, p.y, 2, 2, YELLOW); // draws 2 pixel rectangle
tft.setCursor(100, 70);
tft.setTextColor(WHITE, BLACK ); tft.setTextSize(4);
tft.print("Hello"); // just to see to the alignment / rotation
}
}
Display is in portrait mode(USB facing downwards) and anywhere the Screen gets touched it draws a yellow rectangle and prints out the XY coordinates. Works perfectly for me. Next I tried to rotate the Screen to the landscape mode with the same fuctions as above. So I wrote this:
#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define TS_MINX 918// TS_LEFT 75
#define TS_MINY 75// TS_TOP 98
#define TS_MAXX 98// TS_RT 901
#define TS_MAXY 901// TS_BOT 917
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
const int XP = 8;
const int XM = A2;
const int YP = A3;
const int YM = 9;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
void setup() {
Serial.begin(9600);
Serial.print("Starting...");
tft.reset();
//tft.begin(tft.readID());
tft.begin(0x9341);
tft.setRotation(1);
tft.fillScreen(BLACK);
}
void loop()
{
TSPoint p = ts.getPoint(); //Get touch point
if (p.z > ts.pressureThreshhold) {
p.x = map(p.y, TS_MINY, TS_MAXY, 320, 0);
p.y = map(p.x, TS_MAXX, TS_MINX, 0, 240);
Serial.println("Koordinaten");
Serial.println(p.x);
Serial.println(p.y);
}
if (p.x > 0 && p.x < 320 && p.y > 0 && p.y < 240){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
tft.fillScreen(BLACK);
tft.fillRect(p.x, p.y, 2, 2, YELLOW); // draws 2 pixel rectangle
tft.setCursor(100, 70);
tft.setTextColor(WHITE, BLACK ); tft.setTextSize(4);
tft.print("Hello"); // just to see to the alignment / rotation
}
}
The problem is that it dont prints the XY Values correct. If I comment out "p.x = map(p.y, TS_MINY, TS_MAXY, 320, 0);" and the "Serial.println(p.x);" lines I get the right Values and vica versa. But not both at the same time. The Value I map at first in the loop gives the right coordinats back and the second one jumps in a range of 20 to 30. For me the loop in both sketches look similar. Any idea what it could be?
** Serial Output mapping X Value at first
Koordinaten
X0
Y268 (Bottom left corner)
Koordinaten
X321
Y175 (Top right corner)
** Serial Output mapping Y Value at first
Koordinaten
347
0(Bottom left corner)
Koordinaten
256
242(Top right corner)