Can anyone tell me why the analog pins 6 and 7 on a nano don’t seem to work as per the rest of the pins?
I have a nano from OSEPP on a breadboard. To that breadboard I have a 4 wire DS touchscreen attached to a breakout from adafruit.
I then use the library from pratical arduino and run the example for simply reading the coordinates.
If I use any combination of A0-A5 everything works great. But if I throw in A6 or A7 it doesn’t work anymore.
This is the code that works…
#include <TouchScreen.h>
TouchScreen ts(3, 1, 0, 2);
void setup()
{
Serial.begin(38400);
}
void loop()
{
int coords[2];
ts.read(coords);
Serial.print(coords[0]);
Serial.print(",");
Serial.println(coords[1]);
delay (100);
}
This is the code that doesn’t work…
#include <TouchScreen.h>
TouchScreen ts(7, 5, 4, 6);
void setup()
{
Serial.begin(38400);
}
void loop()
{
int coords[2];
ts.read(coords);
Serial.print(coords[0]);
Serial.print(",");
Serial.println(coords[1]);
delay (100);
}
And in case you haven’t seen the library from Practical, here it is…
Cpp…
/**
* TouchScreen Library
*
* Copyright 2009 Jonathan Oxer <jon@oxer.com.au> / <www.practicalarduino.com>
*
* Reads X/Y coordinates from a 4-wire resistive touch-screen connected
* to four analog inputs on an Arduino.
*
* Analog input pins can also be used as general-purpose digital I/O
* pins. When referenced in that mode they are actually d14 through
* d18, ie:
* a0 = d14 = y1
* a1 = d15 = x2
* a2 = d16 = y2
* a3 = d17 = x1
* We therefore add 14 to the analog pin number to reference it as a
* digital pin.
*/
#include "Arduino.h"
#include "TouchScreen.h"
TouchScreen::TouchScreen(int pinX1, int pinX2, int pinY1, int pinY2)
{
_pinX1 = pinX1;
_pinX2 = pinX2;
_pinY1 = pinY1;
_pinY2 = pinY2;
}
/* ================ Public methods ================ */
/**
* Reads the X and Y coordinates from a touchscreen
*/
void TouchScreen::read(int *coordinates)
{
// Read the X coordinate
pinMode( _pinX2 + DIGITAL_OFFSET, INPUT ); // Analog pin 1
pinMode( _pinX1 + DIGITAL_OFFSET, INPUT ); // Analog pin 3
pinMode( _pinY1 + DIGITAL_OFFSET, OUTPUT ); // Analog pin 0
digitalWrite( _pinY1 + DIGITAL_OFFSET, LOW ); // Use analog pin 0 as a GND connection
pinMode( _pinY2 + DIGITAL_OFFSET, OUTPUT ); // Analog pin 2
digitalWrite( _pinY2 + DIGITAL_OFFSET, HIGH ); // Use analog pin 2 as a +5V connection
_xVal = analogRead( _pinX2 ); // Read the X value
// Read the Y coordinate
pinMode( _pinY1 + DIGITAL_OFFSET, INPUT ); // Analog pin 0
pinMode( _pinY2 + DIGITAL_OFFSET, INPUT ); // Analog pin 2
pinMode( _pinX2 + DIGITAL_OFFSET, OUTPUT ); // Analog pin 1
digitalWrite( _pinX2 + DIGITAL_OFFSET, LOW ); // Use analog pin 1 as a GND connection
pinMode( _pinX1 + DIGITAL_OFFSET, OUTPUT ); // Analog pin 3
digitalWrite( _pinX1 + DIGITAL_OFFSET, HIGH ); // Use analog pin 3 as a +5V connection
_yVal = analogRead( _pinY1 ); // Read the Y value
// Update the array we were pointed to by the calling function
coordinates[0] = _xVal;
coordinates[1] = _yVal;
}
h…
/**
* TouchScreen Library
*
* Copyright 2009 Jonathan Oxer <jon@oxer.com.au> / <www.practicalarduino.com>
*
* Reads X/Y coordinates from a 4-wire resistive touch-screen connected
* to four analog inputs on an Arduino.
*/
#ifndef TouchScreen_h
#define TouchScreen_h
#define DIGITAL_OFFSET 14 // Added to analog pin number to get digital number
#include "Arduino.h"
class TouchScreen
{
public:
TouchScreen(int pinX1, int pinX2, int pinY1, int pinY2);
void read(int *coordinates); // Read the touchscreen and return coordinates
private:
int _pinX1; // Analog pin connected to screen line X1
int _pinX2; // Analog pin connected to screen line X2
int _pinY1; // Analog pin connected to screen line Y1
int _pinY2; // Analog pin connected to screen line Y2
int _xVal; // Current X coordinate
int _yVal; // Current Y coordinate
};
#endif
If anyone can shine some light on this I would REALLY appreciate it as I have been banging my head against the table.