Objetivo
El objetivo de este manual es ofrecer la manera de testear la Pantalla Touch 2.4 Pulgadas con nuestro Uno R3.
Materiales necesarios:
- Pantalla Touch 2.4 Pulg. para Arduino
- Uno R3 + Cable USB para Arduino
- 22 Resistencias de 10K Ohm 1/4W - 5%
- 20 Jumpers Macho-Hembra 20cm
- 30 Jumpers Macho-Macho 20cm
Diagrama de conexión:
SENSOR KY-001 |
ARDUINO UNO R3 |
3.3V (+) | 3.3V (+) |
GND (-) | GND (-) |
TSCK | Pin 3 |
TCS | Pin 4 |
TMOSI | Pin 5 |
TMISO | Pin 6 |
TIRQ | Pin 7 |
TFT_RST | Pin 8 |
TFT_DC | Pin 9 |
TFT_CS | Pin 10 |
TFT_MOSI | Pin 11 |
TFT_MISO | Pin 12 |
TFT_CLK | Pin 13 |
1. - Instalando las librerias necesarias para el uso del Modulo
Antes de poder proceder a insertar el codigo en nuestro Arduino, debemos tener 4 librerias esenciales instaladas ya en nuestro IDE: Para ello, te dejare un enlace el cual les descargará las librerias ya mencionadas compactadas en un archivos ''.rar y .zip''. Una vez descargadas deben mover los archivos a la carpeta de Librerias en Archivos de programa o insertarlas desde el menú ''Programa'' (Incluir Librería > Añadir Libreria .ZIP).
Nota: Se debe calibrar los puntos de precisión a la pantalla para que la ubicación de los mismos sea la correcta, de lo contrario la ubicación de los trazos seran incorrectos.
Codigo utilizado:
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <URTouch.h>
// pin definition for the Uno LCD
#define TFT_DC 9
#define TFT_CS 10
#define TFT_MOSI 11
#define TFT_CLK 13
#define TFT_RST 8
#define TFT_MISO 12
// TFT Screen pixel resolution in landscape orientation, change these to suit your display
// Defined in landscape orientation !
#define HRES 320
#define VRES 240
//Pines URTouch
#define TSCK 3
#define TCS 4
#define TMOSI 5
#define TMISO 6
#define TIRQ 7
//Instanciamos la TFT
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
//Instancimos el Touch
URTouch ts(TSCK, TCS, TMOSI, TMISO, TIRQ);
//long X_Raw = 0, Y_Raw = 0;
void setup()
{
Serial.begin(38400);
Serial.println("ILI9341 Test!");
//Confguracion de la TFT
tft.begin();
tft.setRotation(1); //Must be 1 or else touchscreen gets lost
tft.fillScreen(ILI9341_YELLOW); //Fondo Amarillo
//Configuracion del Touch
ts.InitTouch(1);
ts.setPrecision(3);
tft.setTextColor(ILI9341_BLUE);
tft.setTextSize(3);
tft.setCursor(40,5);
tft.print("Testing Touch");
tft.setTextColor(ILI9341_BLUE);
tft.setTextSize(2);
tft.setCursor(20,220);
tft.print("www.electronicapty.com");
}
void loop()
{
//long X_Raw, Y_Raw;
drawlines();
}
void drawlines()
{
while(ts.dataAvailable())
{
ts.read();
int X_Raw = ts.getX()+80;
int Y_Raw = ts.getY()+40;
if((X_Raw!=-1) && (Y_Raw!=-1))
{
int radius = 4;
tft.fillCircle(X_Raw, Y_Raw, radius, ILI9341_RED);
}
}
}