Sunday, December 27, 2015

Arduino Nintendo DS Touch Screen

Today I hope to add some clarification to a popular project, based on a Nintendo DS Touch Screen, with breakout board from Sparkfun ($10).

The concept is simple. Print out a picture of your buttons, sliders, etc., slide it under the glass, and with a series of if statements, create zones of co-ordinates that fit the printed controls.





I originally found this project in the 1st Edition of Beginning Arduino by Mike McRoberts. I had some difficulties, reached out to Mike, and he pointed me to the second edition of the book which added two pullup resistors. So here is a photo of the touch screen wired up, and some explanation.

First, there is a silver border side,and a black border side. The silver side is the touch sensitive side, so the black side has to be face down. 

Second, Sparkfun silkscreened the wrong side of their breakout board, in my humble opinion, so you can't see the pin designations. That said, starting from left to right, they are X1, Y2, X2, Y1.  Solder the pins so that the connector side faces the breadboard and the logo faces up. This keeps the VERY FRAGILE cable connection from breaking. Also means you have to remove the breakout board to connect the screen.

Third, with the connections at the lower left, your 0,0 would be top left, your 0,900 would be top right, your 900,0 would be bottom left,and your 900,900 would be bottom right. Your numbers may vary somewhat.

Fourth, the pullup resistors (mentioned in the 2nd edition of the book). Add a 47k to 64k resistor from X2 to +5v, and another from Y1 to +5v. You would connect both to 3.3v if you are using a 3.3v Arduino.

Fifth, the Serial monitor expects 38400 in the example code, so adjust accordingly. If you see garbage, you may still be set to 9600.

I hope this clarifies an otherwise excellent project. I do recommend the book, as it shows you some very practical uses for this touch screen.

Here is a different implementation that uses 4 analog pins instead of 2 analog and 4 digital - http://bildr.org/2011/06/ds-touch-screen-arduino/

// Project 33

// Power connections
#define Left 8     // Left (X1) to digital pin 8
#define Bottom 9   // Bottom (Y2) to digital pin 9
#define Right 10   // Right (X2) to digital pin 10
#define Top 11     // Top (Y1) to digital pin 11

// Analog connections 
#define topInput 0   // Top (Y1) to analog pin 0
#define rightInput 1 // Right (X2) to analog pin 1 

int coordX = 0, coordY = 0;

void setup()
{
        Serial.begin(38400);
}

void loop()
{    
        if (touch())  // If screen touched, print co-ordinates
        {
                Serial.print(coordX);
                Serial.print("  ");
                Serial.println(coordY);
                delay(250); 
        }
}

// return TRUE if touched, and set coordinates to touchX and touchY
boolean touch()
{
        boolean touch = false;
                // get horizontal co-ordinates
        pinMode(Left, OUTPUT); 
        digitalWrite(Left, LOW); // Set Left to Gnd

        pinMode(Right, OUTPUT); // Set right to +5v
        digitalWrite(Right, HIGH);

        pinMode(Top, INPUT); // Top and Bottom to high impedence
        pinMode(Bottom, INPUT);

        delay(3); 
        coordX = analogRead(topInput);

        // get vertical co-ordinates
        pinMode(Bottom, OUTPUT); // set Bottom to Gnd
        digitalWrite(Bottom, LOW);

        pinMode(Top, OUTPUT); // set Top to +5v
        digitalWrite(Top, HIGH);

        pinMode(Right, INPUT); // left and right to high impedence
        pinMode(Left, INPUT);

        delay(3); 
        coordY = analogRead(rightInput);

        // if co-ordinates read are less than 1000 and greater than 0 then the screen has been touched
        if(coordX < 1000 && coordX > 0 && coordY < 1000 && coordY > 0) {touch = true;}

          return touch;
}



No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...