Page 1 of 1

Nintendo DS Touchscreen + Arduino slight problems

Posted: Wed Aug 19, 2009 3:32 pm
by samwhitehall
Hi, I bought one of your DS touchscreens, and have been programming just a simple reader which will take x and y co-ordinates for the point touched using the Arduino.

The screen is connected through a breakout board to four ADC pins on the Arduino (Due) 0-4 and the code I've written is shown below.

When I try and gather either the x-coord or the y-coord separately (ie: comment out the other function call and Serial.print lines) then I get a pretty good range of values (roughly 80 < x < 940 and 90 < y < 930).

However, when I call both functions and display both via the serial, as in the code below, the ranges are drastically smaller (47 ≤ x ≤ 53 and 937 ≤ y 968). I'd like to understand why there is such a radical difference, and if there's anything that can be done to improve it.

Thanks in advance,
Sam
Code: Select all
int x1 = 3;  // analogue pins for touchscreen controllers
int x2 = 1;
int y1 = 0;
int y2 = 2;

int xPosition = 0;
int yPosition = 0;

void setup() {
  Serial.begin(9600);  //start serial communication
}

void loop() {
   getXposition();  //get x-coordinate
   getYposition();  //get y-coordinate
   
   Serial.println(xPosition);  //display x-coordinate
   Serial.println(yPosition);  //display y-coordinate
}

void getXposition() {
  pinMode(14 + x1, OUTPUT);
  pinMode(14 + x2, OUTPUT);
  delay(1);
  
  digitalWrite(14 + x1, HIGH);
  digitalWrite(14 + x2, LOW);
  delay(1);
  
  xPosition = analogRead(y2);
}

void getYposition() {
  pinMode(14 + y1, OUTPUT);
  pinMode(14 + y2, OUTPUT);
  delay(1);
  
  digitalWrite(14 + y1, HIGH);
  digitalWrite(14 + y2, LOW);
  delay(1);
  
  yPosition = analogRead(x1);
}

Posted: Tue Nov 10, 2009 1:05 pm
by whoismaha
Don't you have to set x1 and y2 as INPUTs before you read from them?

Posted: Tue Nov 10, 2009 2:43 pm
by trialex
Don't you have to set x1 and y2 as INPUTs before you read from them?
Technically no, the code behind analogRead() automatically does the pinMode(pin, INPUT); for you.

Maybe try increasing the delay() inside the reading functions, or add a delay between the calls tot he reading functions in the loop() section.

Posted: Thu Nov 12, 2009 6:18 am
by whoismaha
It still doesn't look right to me. If only one function is used.. it is working fine, right? So it's the combination of the two. Which means something isn't being turned off before the other is run.

When you are reading X(via y2) y1 is still outputting HIGH when it should be "disconnected". You could either make it an input or output it low.

That's what i gathered from: http://www.sparkfun.com/datasheets/LCD/ ... 20WORK.pdf

Re: Nintendo DS Touchscreen + Arduino slight problems

Posted: Tue Jul 27, 2010 8:59 am
by dvnm
You may want to delay(10) before doing another read, this will give the AD enough time to switch.