Touch screen - inconsistent output


Was hoping to get some help regarding a strange issue I'm having with two touch screens I ordered. These are the screens,

I ordered a DS connector from sparkfun, created my own breakout board. I've been utilizing this tutorial and the full explanation from the book Practical Arduino: Cool Projects for Open Source Hardware Chapter 8: touch control panel (safari ftw). I've tried the code in the book, the code from kalshagar's site, and ladys touchscreen.h library.

This was originally wired up to a project I am working on that is currently a boarduino. I've tested the code from each of the above references on my original arduino atmega328 and the megas I ordered and burned thinking maybe I did something wrong fuse wise etc...

What is happening is the output readings from both touchscreens on either my boarduino setup or the original arduino aren't true cartesian coordinates. This is sitting on top of a KS0108 GLCD with 8 buttons on it. If I use my stylus and draw horizontally across the screen both x,y change as I move! :fearful: =( and not like... a little just from natural hand movement. Would post exact output but currently at work. I know for a fact moving horizontally a little over and inch resulted in about a 20-25 in deviation on x and y, almost as though I was actually drawing diagonally. It changes drastically under a full sweep of x or y.

I've adjusted the code from each example thinking it was possibly the touch screens them selves. I've followed this documentation as well for a better understanding and thought maybe the screen needed to read from a specific bar so I tried reading from 1 instead of 3 and 0 instead of 2 (zero indexing the pins to match them on the mega) both end in the same result.

I'm using analog inputs 0-4, I've made sure I reference them as A0-A4 in the code, I'm making sure my digitalWrites correspond to the pin numbers as well since they are different (I ref the pin number directly, e.g. 14 for A0)

Any help would be greatly appreciated, oh I also tried it with and without the pulldowns, same result. I can post all code examples etc when I get home unless someone has seen this strange output before.. or maybe its just me :-)

No Touch

X = 984	Y = 78
X = 984	Y = 79
X = 985	Y = 80
X = 982	Y = 80
X = 982	Y = 80

Output when I make a horizontal line on the top edge of button 1

X = 981	Y = 79
X = 980	Y = 130
X = 984	Y = 80
X = 981	Y = 146
X = 980	Y = 150
X = 980	Y = 150
X = 980	Y = 147
X = 979	Y = 147
X = 976	Y = 144
X = 976	Y = 142
X = 974	Y = 139
X = 969	Y = 135
X = 966	Y = 133
X = 967	Y = 132
X = 965	Y = 130
X = 963	Y = 130
X = 982	Y = 80
X = 983	Y = 80

Horizontal line across top edge of button8

X = 985	Y = 80
X = 982	Y = 80
X = 985	Y = 80
X = 956	Y = 89
X = 951	Y = 92
X = 952	Y = 92
X = 949	Y = 90
X = 948	Y = 91
X = 945	Y = 91
X = 943	Y = 91
X = 940	Y = 91
X = 935	Y = 91
X = 929	Y = 90
X = 925	Y = 91
X = 919	Y = 89
X = 914	Y = 90
X = 911	Y = 89
X = 910	Y = 90
X = 910	Y = 90

Code I used for this test… straight up from the touchscreen.h example. This was done using the arduino board and original 328

// Touch screen library with X Y and Z (pressure) readings as well
// as oversampling to avoid 'bouncing'
// This demo code returns raw readings, public domain

#include <stdint.h>
#include "TouchScreen.h"

#define YP A0  // must be an analog pin, use "An" notation!
#define XM A1  // must be an analog pin, use "An" notation!
#define YM A2   // can be a digital pin
#define XP A3   // can be a digital pin

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

void setup(void) {

void loop(void) {
  // a point object holds x y and z coordinates
  Point p = ts.getPoint();
  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!
  //if (p.z > ts.pressureThreshhold) {
     Serial.print("X = "); Serial.print(p.x);
     Serial.print("\tY = "); Serial.print(p.y); Serial.print("\n");


That output looks consistent to me -- although not a whole lot of bits of precision.

You should start out by getting X Y readings for each of the four corners. Well, you only need two corners, really, but it'd be good to make sure that the X values are consistent from top to bottom and that the Y values are consistent from side to side. From there you're going to want to feed it into the map() function so you can translate it into pixel coordinates.

If you can provide those corner coordinate values and the pixel dimensions of your screen I could help out with using map().

The coords are so off when I do that that they actually overlap. It's what originally stumped me. I'll run through them again and post them when i get home. I'll also post the original mappings that I had penciled out on paper too. I remember button2's bottom right y coord being higher than button1s... but not the upper left coords. The result was my extra debug code resulting in the same coords being output but it was seeing buttons 1 and 2 pressed at the same time if you touched either on their far right side.

What’s the resistance across one of the resistance layers and what value pull-up/down resistors are you using?

490 ohms across one, 260 across the other =( on both screens...

I've tried with and without 10k pulldowns... didn't read anywhere about using pullups with a touchscreen... any thoughts?

The pull ups are so the input isn't floating when the screen is idle - they need to be much higher in value than the screen resistances, which they are.

Without them there's no way to know if the screen's being pressed or not.

Update on this. I haven't had time to play with this in a while. I decided to order two DS touchscreens from sparkfun. XY coords are consistent across the board. The touchscreens I ordered from dealextreme were junk, both of them.

How are the Pullups connected : - from X1 to 10K to +5V ? - from Y1 to 1M to +5V ?

I get distorted readings even with 1M My Panel has Resistances below 1K.