Hi,
My problem is that I can’t get TOUCH FUNCTION running - returning coordinates of place I touch.
my hardware:
Arduino Mega 2560
TFT 3.5" ILI9486 8bit with Touch Screen
Quite sure that I’m using wrong library based on which I glued my code together (based on examples I found on internet like :https://howtomechatronics.com/tutorials/arduino/arduino-tft-lcd-touch-screen-tutorial/).
calibration test :
TouchScreen.h GFX Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction
Testing : (A2, D8) = 22
Testing : (A3, D9) = 32
Diagnosing as:-
XM,XP: (A2, D8) = 22
YP,YM: (A3, D9) = 32
ID = 0x9486
cx=165 cy=925 cz=200 LEFT, TOP, Pressure
cx=142 cy=528 cz=406 LEFT, MIDH, Pressure
cx=146 cy=112 cz=607 LEFT, BOT, Pressure
cx=523 cy=943 cz=279 MIDW, TOP, Pressure
cx=511 cy=113 cz=591 MIDW, BOT, Pressure
cx=894 cy=943 cz=414 RT, TOP, Pressure
cx=889 cy=529 cz=512 RT, MIDH, Pressure
cx=892 cy=115 cz=662 RT, BOT, Pressure
MCUFRIEND_kbv ID=0x9486 320 x 480
const int XP=8,XM=A2,YP=A3,YM=9; //320x480 ID=0x9486
const int TS_LEFT=126,TS_RT=915,TS_TOP=954,TS_BOT=95;
PORTRAIT CALIBRATION 320 x 480
x = map(p.x, LEFT=126, RT=915, 0, 320)
y = map(p.y, TOP=954, BOT=95, 0, 480)
Touch Pin Wiring XP=8 XM=A2 YP=A3 YM=9
LANDSCAPE CALIBRATION 480 x 320
x = map(p.y, LEFT=954, RT=95, 0, 480)
y = map(p.x, TOP=915, BOT=126, 0, 320)
I stopped at stage when I want to touch screen and get coordinates on COM to make sure that once I write rest of code defining areas to touch, it will actually go somewhere. I bet there are parts of code that can go to trash as they don’t do anything…
My code is below
#include <Adafruit_GFX.h> // Core graphics library
#include <MCUFRIEND_kbv.h> // Hardware-specific library
MCUFRIEND_kbv tft;
#include <URTouch.h>
URTouch myTouch( 6, 5, 4, 3, 2);
#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>
#include <FreeDefaultFonts.h>
#define BLACK 0x0000
#define RED 0xF800
#define GREEN 0x07E0
#define WHITE 0xFFFF
#define GREY 0x8410
#define YELLOW 0xFFE0
int page = 0;
int XX,YY;
void setup(void)
{
Serial.begin(9600);
uint16_t ID = tft.readID();
if (ID == 0xD3) ID = 0x9481;
tft.width();
tft.height();
tft.begin(ID);
tft.setRotation(1);
tft.fillScreen(BLACK);
myTouch.InitTouch();
myTouch.setPrecision(PREC_MEDIUM);
}
void loop()
{
if (page == 0)
{
HomeScreen();
if (myTouch.dataAvailable() > 0) {
myTouch.read();
XX=myTouch.getX(); // X coordinate where the screen has been pressed
YY=myTouch.getY(); // Y coordinates where the screen has been pressed
Serial.println("X = ");
Serial.println(XX);
Serial.println("Y = ");
Serial.println(YY);
}
}
if (page == 1)
{
FlapsScreen();
}
if (page == 2)
{
StepperScreen();
}
else {
page=0;
}
}
void HomeScreen()
{
//tft.fillScreen(BLACK);
showmsgXY(20, 10, 2, NULL, "Reinsch Engineering - HVAC v1");
showmsgXY(20, 30, 2, NULL, "Delorean DMC-12 Heaterbox controller");
tft.drawRoundRect(60,80,360,70, 10, YELLOW);
tft.fillRoundRect(61,81,358,68,10, GREY);
showmsgXY(180, 100, 4, NULL, "FLAPS");
tft.drawRoundRect(60, 170, 360, 70, 10, YELLOW);
tft.fillRoundRect(61, 171, 358, 68, 10, GREY);
showmsgXY(160, 190, 4, NULL, "STEPPER");
delay(300);
}
void FlapsScreen()
{
}
void StepperScreen()
{
}
void showmsgXY(int x, int y, int sz, const GFXfont *f, const char *msg)
{
int16_t x1, y1;
uint16_t wid, ht;
// tft.drawFastHLine(0, y, tft.width(), WHITE);
tft.setFont(f);
tft.setCursor(x, y);
tft.setTextColor(YELLOW);
tft.setTextSize(sz);
tft.print(msg);
delay(2000);
}
when I delete parts that are TOUCH related I have a good image, but if it added, it is causing issues and no coordinates returing on COM
I would appreciate your help. I’m trying to motorize my Heater box (HVAC) from my Delorean and this TFT TOUCH SCREEN is part of my test rig.
Standard unit is operated my electromechanical switches. They control vacuum delivery to actuators and position of hot/cold mixing flap. So far I added stepper motor from other car that is succesfully able to control mixing flap in whole range (some 3d printed parts were required). For delivering vacuum to correct actuator, I’ve used set of 6 small solenoids. Everything works separately. Now trying to build a closed testing loop with TFT TOUCH for manual operation of some functions.
I would appreciate your help!
regards,
Marek