In this post i am going to provide a brief description on how to interface , Calibrate and use Resistive touch panels .I will try to stay away from maths as much as possible but you need a little math to get the job done.First of all let me show you how the touch screens work .Well there are so many touchscreen controllers in the market . In most of the tutorial you will find about how to interface the touchscreen controller to MCU not about how to interface the touchscreen to MCU. Here are some pictures of a touch screen with its LCD.
unless you have a LCD it's impossible to calibrate. Basically if you tear apart a resistive touch screen you get the following image, yes there are 1000s of resistors vertically and horizontally.We are not going to mesh with 1000 so ,, just shown 1 .Remember vertical resistors do not touch the horizontal ones there is a little gap in between them.
when you touch it 1 of those 100s of resistors gets connected to the other.following diagram shows it clearly.
That's why a current flows in between them forming a potentiometer like configuration .
That's why a current flows in between them forming a potentiometer like configuration .
CALIBRATION :
Doesn't it look pretty much like a potentiometer.O-5v and one sense pin thats where you read the voltage.Doing so will you to detect the point on one axis.Then you need to reconfigure it for another axis .
here is how. you need to do the following.
5v=leave it.
leave it=0v
0v=sense
sense=5v
this way you get two voltages not the coordinates of pixel .from here on a little maths to get the coordinates.
The following algorithm is the easiest one to understand .This easiness comes by compromising the the accuracy.so please don't claim for that now.
I assume you have a LCD of at least 320 x 240 pixels.
STEP 1: Clear LCD with any color.//let it be black
STEP 2: Set pixel(100,100,green);
This means the pixel colour will be green at pixel no 100 x and 100 y.
STEP 3: int x1=Read(xaxis);int y1=read(yaxis); //Now you have two values in x1 and y1(these values are for 100,100).
STEP 4:set pixel (200,200,green);
STEP 5:int x2=Read(xaxis);int y2=read(yaxis);//Now x2 and y2 have values for (200,200)pixel.
STEP 6: Perpixel width calculation .
int perpixelwidthx=(x2-x1)/100 ;
int perpixelwidthy=(y2-y1)/100;
Now it's almost done.In order to get the coordinates here is what you need to do.
when user touched--:
Get the X value.check if its greater that value of x1.if yes then how much greater=x-x1;let it be 3
then x pixel coordinate =100+3*(perpixelwidthx); //This will give you the exact pixel coodinate of x axis.
Repeat same thing for y axis.
NOTE: no 3 is an assumption.
100+3*(perpixelwidthx); will be 100-3*( perpixelwidthx) if read value is smaller than x1.
here is how. you need to do the following.
5v=leave it.
leave it=0v
0v=sense
sense=5v
this way you get two voltages not the coordinates of pixel .from here on a little maths to get the coordinates.
The following algorithm is the easiest one to understand .This easiness comes by compromising the the accuracy.so please don't claim for that now.
I assume you have a LCD of at least 320 x 240 pixels.
STEP 1: Clear LCD with any color.//let it be black
STEP 2: Set pixel(100,100,green);
This means the pixel colour will be green at pixel no 100 x and 100 y.
STEP 3: int x1=Read(xaxis);int y1=read(yaxis); //Now you have two values in x1 and y1(these values are for 100,100).
STEP 4:set pixel (200,200,green);
STEP 5:int x2=Read(xaxis);int y2=read(yaxis);//Now x2 and y2 have values for (200,200)pixel.
STEP 6: Perpixel width calculation .
int perpixelwidthx=(x2-x1)/100 ;
int perpixelwidthy=(y2-y1)/100;
Now it's almost done.In order to get the coordinates here is what you need to do.
when user touched--:
Get the X value.check if its greater that value of x1.if yes then how much greater=x-x1;let it be 3
then x pixel coordinate =100+3*(perpixelwidthx); //This will give you the exact pixel coodinate of x axis.
Repeat same thing for y axis.
NOTE: no 3 is an assumption.
100+3*(perpixelwidthx); will be 100-3*( perpixelwidthx) if read value is smaller than x1.