The Touch Shield is an electronic component designed to add touch-sensitive input to projects. It typically features a capacitive touch sensor, which can detect finger presence and location on a surface. This shield is often used with microcontroller platforms like the Arduino UNO to create interactive devices, such as touch interfaces, control panels, or even simple games.
Common applications include:
Pin Number | Description | Notes |
---|---|---|
1 | VCC | Connect to 3.3V or 5V |
2 | GND | Connect to ground |
3 | SCL (I2C) / SCK (SPI) | Serial clock line |
4 | SDA (I2C) / MOSI (SPI) | Serial data line |
5 | RESET | Reset pin, active low |
6 | INT | Interrupt pin |
7 | MISO (SPI only) | Master In Slave Out (SPI mode) |
8 | CS (SPI only) | Chip Select (SPI mode) |
#include <TouchScreen.h> // Include the touch screen library
// Touch screen pins
#define YP A3 // must be an analog pin
#define XM A2 // must be an analog pin
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
// Touch screen calibration values
#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940
// Create a touch screen object
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
void setup() {
Serial.begin(9600);
}
void loop() {
// Check for a touch
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
if (p.z > ts.pressureThreshhold) {
// Scale from touch coordinates to screen coordinates
p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.println();
}
}
TS_MINX
, TS_MINY
, TS_MAXX
, and TS_MAXY
as needed.Q: Can I use the touch shield with a 3.3V system? A: Yes, but ensure that the touch shield is compatible with 3.3V logic levels.
Q: How do I clean the touch surface? A: Use a soft, slightly damp cloth. Avoid harsh chemicals and do not apply excessive force.
Q: What should I do if the touch shield is unresponsive? A: Reset the microcontroller and the touch shield. If the issue persists, check for any visible damage to the shield or its connections.