Pages: [1]   Go Down
Author Topic: Nintendo DS Touchscreen Problems  (Read 868 times)
0 Members and 1 Guest are viewing this topic.
Huntsville, Alabama USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Why use a voltmeter when you can just touch it?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey all,

I'm having a problem with the Nintendo DS Touchscreen I bought.

Here is how I have it wired.  I bought the DS breakout board, so the Nintendo DS Pin number listed below is the breakout board pin number:

Arduino Mega Pin:                    Nintendo DS Pin:
      Analog 2                                     X2
      Analog 3                                     Y1
      Analog 4                                     X1
      Analog 5                                     Y2

Here is the sketch:

Code:
#define Lo 2
#define Bo 3
#define Ro 4
#define To 5

#define Ti 3
#define Ri 4

#define LED 13

int touchX = 0;
int touchY = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(LED, OUTPUT);
}

void loop ()
{
  if (touched())
  {
    Serial.print ("X = ");
    Serial.print (touchX);
    Serial.print (" Y = ");
    Serial.println (touchY);
    digitalWrite (LED, HIGH);
    delay (50);
    digitalWrite (LED, LOW);
  }
}

boolean touched()
{
  boolean touch = false;
  // HORIZONTAL ROUTINE!  SET L TO GND AND R TO 5V
  
  // Set L to GND:
  pinMode(Lo, OUTPUT);
  digitalWrite(Lo, LOW);
  
  // Set R to 5V:
  pinMode(Ro, OUTPUT);
  digitalWrite(Ro, HIGH);
  
  // Read the Bottom and Make the Top floating.  To set the top floating, make it an input
  pinMode(To, INPUT);
  pinMode(Bo, INPUT);
  delay(10);
  touchX = analogRead(Ti);
  
  // VERTICAL ROUTINE!  SET T TO GND AND B TO 5v
  
  //Set Bottom to 5V:
  pinMode(Bo, OUTPUT);
  pinMode(Bo, HIGH);
  
  //Set Top to GND:
  pinMode(To, OUTPUT);
  pinMode(To, LOW);
  
  //Read the Right Side and leave the Left Side floating.  To set the Left floatng, make it an input
  pinMode(Lo, INPUT);
  pinMode(Ro, INPUT);
  delay(10);
  touchY = analogRead(Ri);
  
  if(touchX < 1000 && touchY < 1000)
  {
    touch = true;
  }
  return touch;
}

The problem I'm having is the Serial Monitor just puts out X and Y coordinates constantly, even when the touchscreen is not being touched.  Indeed, it continues to put out numbers even when I have the touchscreen unplugged from the Mega.  I'm really confused here. :-/
« Last Edit: February 18, 2010, 09:00:37 pm by WheelerMDW » Logged

Huntsville, Alabama USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Why use a voltmeter when you can just touch it?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, I copied the code from a website, and I found a couple of potential problems with the code, so I rewrote it to this:

Code:
int Lo = 3;
int Bo = 4;
int Ro = 5;
int To = 2;

int Bi = 4;
int Ri = 5;

int ledPin = 13;

int touchX = 0;
int touchY = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}

void loop ()
{
  if (touched())
  {
    Serial.print ("X = ");
    Serial.print (touchX);
    Serial.print (" Y = ");
    Serial.println (touchY);
    digitalWrite (ledPin, HIGH);
    delay (50);
    digitalWrite (ledPin, LOW);
  }
}

boolean touched()
{
  boolean touch = false;
  // HORIZONTAL ROUTINE!  SET L TO GND AND R TO 5V
  
  // Set L to GND:
  pinMode(Lo, OUTPUT);
  digitalWrite(Lo, LOW);
  
  // Set R to 5V:
  pinMode(Ro, OUTPUT);
  digitalWrite(Ro, HIGH);
  
  // Read the Bottom and Make the Top floating.  To set the top floating, make it an input
  pinMode(To, INPUT);
  pinMode(Bo, INPUT);
  delay(10);
  touchX = analogRead(Bi);
  
  // VERTICAL ROUTINE!  SET T TO GND AND B TO 5v
  
  //Set Bottom to GND:
  pinMode(Bo, OUTPUT);
  pinMode(Bo, LOW);
  
  //Set Top to 5V:
  pinMode(To, OUTPUT);
  pinMode(To, HIGH);
  
  //Read the Right Side and leave the Left Side floating.  To set the Left floatng, make it an input
  pinMode(Lo, INPUT);
  pinMode(Ro, INPUT);
  delay(10);
  touchY = analogRead(Ri);
  
  if(touchX < 1000 && touchY < 1000)
  {
    touch = true;
  }
  return touch;
}

And I changed the pinout accordingly:

Mega Pin:                    Breakout Pin:
========================
Analog 2                            Y1
Analog 3                            X2
Analog 4                            Y2
Analog 5                            X1

Still behaves the same.  Here are some experimental results:

1. I decreased the threshold of touchX and touchY to various values, and the Serial Monitor will only display values below that threshold, but it still displays numbers without touching the screen and even when the touchscreen is disconnected from the Mega.

2. When I increase the delay functions, the Serial Monitor still outputs values as described above, but at a slower pace.

3. I decreased the threshold of touchX and touchY to 50, and the Serial Monitor does not output anything, even when I am touching the touchscreen with any amount of force, including more force than I feel comfortable with.  I moved to various locations around the TS with no results.

Finally, a little piece of background info about the breakout board.  When I received it, I inspected it and found that X2 and Y2 were shorted together with a bad solder job.  I have learned over the years to inspect solder work before installing anything.  As a result, I desoldered the pins and removed the short-circuit.  I am confident that they are no longer short-circuited at te SMT solder point, but I did not take the connector apart and check it out.

Incidentally, Pins 25 and 26 on the FTDI chip of my Mega have a similar solder bridge across them, but they are common to GND anyway... smiley-wink
Logged

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did this ages ago....

I used this code:
http://mnicolato.altervista.org/arduino/ardtouch.htm

The 'top' and 'right' also have to be connected to analog inputs with the others being connected to digital outputs for power...

Mowcius
Logged

Huntsville, Alabama USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Why use a voltmeter when you can just touch it?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I thought the analog pins could also be used as digital pins?

Anyway...I'll try out your wiring tonight.

Mega Pin:      Breakout Board Pin:        TS Pin:      Description:
========================================
Analog2                    X1                          1           Top of TS
Digital3                     X2                          3           Bottom of TS
Digital4                     Y2                          2           Left side of TS
Analog5                    Y1                          4           Right side of TS
Logged

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes they can but you need them connected to two different pins.

From the site I linked. The top and right connections have to be connected to both analog and digital. You need 6 pins in total.
Quote
        Wiring                                           Logic
Touchpad       Arduino       Phase 1:              Phase 2:
                        X axis reading         Y axis reading

Left               Dig 2       mode OUTPUT      mode INPUT
                          value: LOW       (high impedance)

Top               An 3       Read X axis value (not used)
                        (last operation)*       
              Dig 5       mode INPUT          mode OUTPUT
                        (high impedance)   value: HIGH

Right         An 4      (not used)                   Read Y axis value
                                                            (last operation)*
              Dig 4        mode OUTPUT          mode INPUT
                         value: HIGH           (High impedance)

Bottom       Dig 3        mode INPUT         mode OUTPUT
                         (high impedance) value: LOW

[edit]That didn't copy well. Look at the site I linked for a better version.[/edit]

Mowcius
« Last Edit: February 19, 2010, 02:20:30 pm by mowcius » Logged

Huntsville, Alabama USA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 66
Why use a voltmeter when you can just touch it?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh!  I'm tracking you now.

I looked at that site you referenced when I started this (in fact, I used the code from there and modified it a little), but unfortunately the translation made it pretty difficult to really understand what the guy was doing, but now that I understand that there will actually be six wires used, I think some of the blanks are beginning to be filled in.

I'll take a look at it again, and post another pin arrangement and will experiment with it tonight.

Thanks a lot, Mowcius.
Logged

Buffalo, NY
Offline Offline
Newbie
*
Karma: 0
Posts: 12
"The reason for time is so that everything doesn't happen at once"-Albert Einstein
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using a uOLED display with a 4-wire touch screen I added to it, you don't have to use the extra digital pins, you can use the analog pins as digital out instead.
Port         Pin     Function
PF 0      54       A0
PF 1      55       A1
PF 2      56       A2
PF 3      57       A3
PF 4      58       A4
PF 5      59       A5
PF 6      60       A6
PF 7      61       A7
PK 0      62       A8
PK 1      63       A9
PK 2      64       A10
PK 3      65       A11
PK 4      66       A12
PK 5      67       A13
PK 6      68       A14
PK 7      69       A15
Logged

Pages: [1]   Go Up
Jump to: