Nintendo DS Touchscreen + Arduino slight problems

Your source for all things Atmel.

Moderator: phalanx

Post Reply
samwhitehall
Posts: 1
Joined: Wed Aug 19, 2009 3:14 pm

Nintendo DS Touchscreen + Arduino slight problems

Post by samwhitehall » Wed Aug 19, 2009 3:32 pm

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);
}

whoismaha
Posts: 23
Joined: Mon Aug 31, 2009 7:43 am

Post by whoismaha » Tue Nov 10, 2009 1:05 pm

Don't you have to set x1 and y2 as INPUTs before you read from them?

trialex
Posts: 279
Joined: Tue Jan 09, 2007 3:55 pm

Post by trialex » Tue Nov 10, 2009 2:43 pm

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.

whoismaha
Posts: 23
Joined: Mon Aug 31, 2009 7:43 am

Post by whoismaha » Thu Nov 12, 2009 6:18 am

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

dvnm
Posts: 1
Joined: Tue Jul 27, 2010 8:56 am

Re: Nintendo DS Touchscreen + Arduino slight problems

Post by dvnm » Tue Jul 27, 2010 8:59 am

You may want to delay(10) before doing another read, this will give the AD enough time to switch.

Post Reply