I connected my 4-wires-Touchscreen with an Arduino Mega2560. I used the guide from: https://www.instructables.com/Resistive-Touch-Screen-on-the-DP32/. But the coordinates I'm getting from the output of my touchscreen arent't exactly enough. While I'm going along the X-axis, the coordinates of the Y-axis are also changing. Only a little, but the difference is growing by distance.
So my main problem is, that I can't calibrate my 4-wires-Touchscreen correctly.
I got the values for a and b, from calculations of step 7 of the guide.
For any questions, here is my code:
#define Yin A0
#define Yout A1
#define Xin A2
#define Xout A3
#define a_1 0.02281
#define b_1 198.2
#define a_3 -0.01455
#define b_3 704.2
#define a_4 -0.01707
#define b_4 83.41
#define a_6 0.01996
#define b_6 829.0
#define C_x 22.81
#define C_y 30.41
int readX;
int readY;
float X;
float Y;
float correctX(int measuredX, int measuredY);
float correctY(int measuredX, int measuredY);
void setup()
{
pinMode(Xin, INPUT);
pinMode(Yin, INPUT);
pinMode(Xout, INPUT);
pinMode(Yout, INPUT);
Serial.begin(9600);
}
void loop()
{
{
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Read X
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Set Y to a gradient
pinMode(Yin, OUTPUT);
pinMode(Yout, OUTPUT);
digitalWrite(Yin, LOW);
digitalWrite(Yout, HIGH);
delay(5); // Pause to allow lines to power up
// Read and store X
readX = analogRead(Xin);
// Reset Y
digitalWrite(Yout, LOW);
delay(5); // Pause to allow lines to power down
pinMode(Yin, INPUT);
pinMode(Yout, INPUT);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Read Y
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Set X to a gradient
pinMode(Xin, OUTPUT);
pinMode(Xout, OUTPUT);
digitalWrite(Xin, LOW);
digitalWrite(Xout, HIGH);
delay(5); // Pause to allow lines to power up
// Read and store Y
readY = analogRead(Yin);
// Reset X
digitalWrite(Xout, LOW);
delay(5); // Pause to allow lines to power down
pinMode(Xin, INPUT);
pinMode(Xout, INPUT);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Correct X
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
X = correctX(readX, readY);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Correct Y
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Y = correctY(readX, readY);
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Output our values
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Serial.print(X);
Serial.print("\t");
Serial.println(Y);
delay(250); // Debounce
}
}
float correctX(int measuredX, int measuredY)
{
float correctedX;
float temp;
temp = (a_4 * measuredY) + b_4;
correctedX = measuredX - temp;
temp = (a_6 * measuredY) + b_6;
correctedX = correctedX / temp;
correctedX = correctedX * C_x;
return correctedX;
}
float correctY(int measuredX, int measuredY)
{
float correctedY;
float temp;
temp = (a_1 * measuredX) + b_1;
correctedY = measuredY - temp;
temp = (a_3 * measuredX) + b_3;
correctedY = correctedY / temp;
correctedY = correctedY * C_y;
return correctedY;
}
Would be grateful, if anyone could help me further.