LCD Touch screen not updating

So I have been working on a simple first project with a touch screen LCD. I have been trying to get a menu like thing where i could click on a button and I would get a new page. The main page only has one button for the moment but that is now very important. the problem is that when I push the button the arduino registers everything and redirects me to the new page(from what I can see in the serial output). Only the LCD doesn't update. I have tried nearly every option I could think of like a tft.reset(), tft.fillScreen() but nothing makes the screen update.

Driver: ILI9341

#include <TouchScreen.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>
#include <Adafruit_TFTLCD.h>

// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.

// Hardware-specific library

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

#define TS_MINX 126
#define TS_MINY 110
#define TS_MAXX 939
#define TS_MAXY 901

#define YP A2 // must be an analog pin, use "An" notation!
#define XM A3 // must be an analog pin, use "An" notation!
#define YM 8 // can be a digital pin
#define XP 9 // can be a digital pin

#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

boolean buttonEnabled = false;
int screen = 0;

void setup() {
Serial.begin(9600);
Serial.println("Starting...");

tft.reset();
tft.begin(0x9341);
tft.setRotation(1);

}

void loop() {

while (screen==0){

//home screen
tft.fillScreen(BLACK);

//Draw white frame
tft.drawRect(0,0,319,240,WHITE);

//Print "Kies test" Text
tft.setCursor(30,30);
tft.setTextColor(WHITE);
tft.setTextSize(4);
tft.print("Kies test");

//Create Red Button
tft.fillRect(60,180, 200, 40, RED);
tft.drawRect(60,180,200,40,WHITE);
tft.setCursor(80,188);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("Test servo");

TSPoint p = ts.getPoint(); //Get touch point
if (p.z > ts.pressureThreshhold) {

Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\n");
if(p.x>280 && p.x<796 && p.y>720 && p.y<845){
Serial.println("Servotest btn pressed");
buttonEnabled = false; //Disable button
screen=1;

}
}
}

while (screen==1){
// home screen
tft.fillScreen(RED);

//Draw white frame
tft.drawRect(0,0,319,240,WHITE);

//Print "Kies test" Text
tft.setCursor(30,30);
tft.setTextColor(WHITE);
tft.setTextSize(4);
tft.print("Kies test");

//Create Red Button
tft.fillRect(60,180, 200, 40, BLUE);
tft.drawRect(60,180,200,40,WHITE);
tft.setCursor(80,188);
tft.setTextColor(WHITE);
tft.setTextSize(3);
tft.print("Test servo");

TSPoint p = ts.getPoint(); //Get touch point
if (p.z > ts.pressureThreshhold) {

Serial.print("X = "); Serial.print(p.x);
Serial.print("\tY = "); Serial.print(p.y);
Serial.print("\n");
if(p.x>280 && p.x<796 && p.y>720 && p.y<845){
Serial.println("Servoback btn pressed");
buttonEnabled = false; //Disable button
screen=0;

}
}
}
}

Your code displays a black screen. Then if you press in a specific spot, the LCD is suppose to turn all red?
And it doesn't?

There is some confusion over which screen you have.

I suspect it is a Mcufriend-style Shield. The Touch pins are shared with the TFT. So you must always restore the Analog pins after any call to the Touch e.g.

    TSPoint p = ts.getPoint();  //Get touch point
    pinMode(YP, OUTPUT);
    pinMode(XM, OUTPUT);

It is possible that YM, XP are on 8, 9. It is more common to be on 6, 7.

You do not need the Adafruit_SPITFT headers. You have a regular parallel Mcufriend shield. Use a genuine Adafruit_TFTLCD library from Adafruit (or MCUFRIEND_kbv)

David.

1 Like

ieee488:
Your code displays a black screen. Then if you press in a specific spot, the LCD is suppose to turn all red?
And it doesn't?

It is a black background with a white rectangle and a button, if i press the button the background should change to a red one with different text.

david_prentice:
There is some confusion over which screen you have.

I suspect it is a Mcufriend-style Shield. The Touch pins are shared with the TFT. So you must always restore the Analog pins after any call to the Touch e.g.

    TSPoint p = ts.getPoint();  //Get touch point

pinMode(YP, OUTPUT);
    pinMode(XM, OUTPUT);




It is possible that YM, XP are on 8, 9. It is more common to be on 6, 7.

You do not need the Adafruit_SPITFT headers. You have a regular parallel Mcufriend shield. Use a genuine Adafruit_TFTLCD library from Adafruit (or MCUFRIEND_kbv)

David.

This worked beautifully, thanks a lot this post can be closed.

PS: for anyone wondering what screen it was, here is the link: Velleman IO for Arduino VMA412: 2.8 INCH TOUCH SCREEN FOR UNO/MEGA DEVELOPMENT BOARD – Velleman – Wholesaler and developer of electronics