Problem with Adafruit Touch-Screen-TFT-LCD / goes blank

Sorry to bother anyone here but I can not get on with my Adafruit Touch-Screen-TFT-LCD. 2.8"

When I write somthing to the display it may go well and the dispaly shows the text at the position I want to place it. But I have very limitet settings that really work.

As soon as I change somthing in the curser position settings or text size. The display starts and shows the grafic for half a second and then the whole display turn white.

e.g.This is a setting that works:

void Status() {
tft.fillRect(0,0,340,32, BLUE);

tft.setTextSize(texts);
tft.setTextColor(WHITE);

tft.setCursor (44,2);

tft.print (Statustext);

}

If I change one figure as shown here the screen truns white as discribed.

tft.setCursor (44,5),

I am more or less a beginner, so please be patient with me.

Thank you for any support.

Please read Forum Instructions

Quote which library and which example name gives a problem.

David.

Hi David

I am including following libraries:

#include <Adafruit_TFTLCD.h>
#include <Adafruit_GFX.h>
#include <TouchScreen.h>

I am not sure what you mean by "which example name gives a problem"

I get no error message. After Uploading, It does show the the programmed screen first and then the display just turns white after half a second. The display stays white until I download the code again.

The bug seems to be random. As soon I change setting in cursor line for position or size, it may work or not.

e.g. change setCursor to 35,48 as showm here insead of 30,48 and the screen goes white.
In code:
void Screenhome (){
// Taste1
tft.setCursor(35,48);

I tried it with an Arduino Uno and Mega. I tried several Arduinos but it shows the same bug.

Thank you very much for your support.

Here is the whole code:

#include <Adafruit_TFTLCD.h> // Library
#include <Adafruit_GFX.h>
#include <TouchScreen.h>

#define LCD_CS A3 // Pin used by LCD
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4

#define TS_MINX 125 // value found by screen calibaratiomn (only enter once)
#define TS_MINY 93
#define TS_MAXX 908
#define TS_MAXY 908

#define YP A3 // define the pins to activate LCD
#define XM A2
#define YM 9
#define XP 8

#define BLACK 0x0000 // define color code
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

const int text = 3;
const int texts = 2;

String Statustext = "WERKSTATTSTATUS";

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //fixed defines used by TFT LCD Library
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364); //fixed defines used by Touch Screen library

boolean buttonEnabled = true;

//------------------------------------------------------------------------------------------------------

void setup() {
Serial.begin(9600);
tft.reset();
uint16_t identifier = tft.readID(); // Start Comunication with Touch
tft.begin(identifier);
tft.setRotation(1); // hoch
tft.fillScreen(BLACK);
}

void loop() {

Screenhome();
Status();
Button();
TestLCD();
}

void Screenhome (){
// Zeichnen der Tasten

// Taste1
tft.fillRect(5,35,100,100, RED);
tft.setCursor(30,48);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T1");

//Taste2
tft.fillRect(115,35,100,100,RED);
tft.setCursor(150,48);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T2");

//Taste3
tft.fillRect(225,35,100,100,RED);
tft.setCursor(250,48);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T3");

//Taste4
tft.fillRect(5,140,100,100,RED);
tft.setCursor(25,150);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T4");

//Taste5
tft.fillRect(115,140,100,100,YELLOW);
tft.setCursor(150,150);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T5");

//Taste 6
tft.fillRect(225,140,100,100,YELLOW);
tft.setCursor(250,150);
tft.setTextColor(BLACK);
tft.setTextSize(text);
tft.print("T6");

}

void Status() {
tft.fillRect(0,0,320,40, BLACK);

tft.setTextSize(texts);
tft.setTextColor(WHITE);

tft.setCursor (44,18);
// 44,2
tft.print (Statustext);

}

void Button (){

TSPoint p = ts.getPoint(); // if touch the programm will display message

if (p.z > ts.pressureThreshhold) {
//Map funtion to convert the value from Touch into pixel
p.x = map(p.x, TS_MAXX, TS_MINX, 0,330);
p.y = map(p.y, TS_MAXY, TS_MINY, 0,480);
}

// Taste 1
if(p.x>65 && p.x<176 && p.y>17 && p.y<148 && buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T1");
Status();
}

// Taste 2
if(p.x>67 && p.x<172 && p.y>190 && p.y<316 && buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T2");
Status();
}

// Taste 3
if(p.x>65 && p.x<356 && p.y>362 && p.y<479 && buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T3");
Status();
}

// Taste 4
if(p.x>202 && p.x<315 && p.y>17 && p.y<146&& buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T4");
Status();
}

// Taste 5
if(p.x>202 && p.x<323 && p.y>179 && p.y<303 && buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T5");
Status();
}

// Taste 6
if(p.x>203 && p.x<311 && p.y>357 && p.y<478 && buttonEnabled){
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
Statustext = ("T6");
Status();
}

}

void TestLCD() {
// a point object holds x y and z coordinates
TSPoint p = ts.getPoint();

// we have some minimum pressure we consider 'valid'
// pressure of 0 means no pressing!
if (p.z > ts.pressureThreshhold) {
p.x = map(p.x, TS_MAXX, TS_MINX, 0,320);
p.y = map(p.y, TS_MAXY, TS_MINY, 0,480);
Serial.print("X = "); Serial.print(p.x);
Serial.print("\t Y = "); Serial.print(p.y);
Serial.print("\t Pressure = "); Serial.println(p.z);
}

// delay(50);
}

Please edit your existing message to put the "code" into Code Window(s),
The Forum Instructions tell you what to do.

David.

#include <Adafruit_TFTLCD.h> // Library
#include <Adafruit_GFX.h>   
#include <TouchScreen.h>



#define LCD_CS A3     // Pin used by LCD
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4



#define TS_MINX 125 // value found by screen calibaratiomn (only enter once)
#define TS_MINY 93
#define TS_MAXX 908
#define TS_MAXY 908



#define YP A3  // define the pins to activate LCD
#define XM A2
#define YM 9
#define XP 8

#define BLACK   0x0000    // define color code
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

const int text = 3;
const int texts = 2;

String Statustext = "WERKSTATTSTATUS";

Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); //fixed defines used by TFT LCD Library
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 364); //fixed defines used by Touch Screen library

boolean buttonEnabled = true;

//------------------------------------------------------------------------------------------------------


void setup() {
  Serial.begin(9600);
  tft.reset();
  uint16_t identifier = tft.readID(); // Start Comunication with Touch
  tft.begin(identifier);
  tft.setRotation(1); // hoch
  tft.fillScreen(BLACK);
}


void loop() {


Screenhome();
Status();
Button();
TestLCD();
}


void Screenhome (){
// Zeichnen der Tasten

// Taste1
tft.fillRect(5,35,100,100, RED);
  tft.setCursor(30,48);
  tft.setTextColor(BLACK);
  tft.setTextSize(text);
  tft.print("T1"); 

//Taste2
tft.fillRect(115,35,100,100,RED);
  tft.setCursor(150,48);
  tft.setTextColor(BLACK);
  tft.setTextSize(text);
  tft.print("T2");


//Taste3
tft.fillRect(225,35,100,100,RED);
  tft.setCursor(250,48);
  tft.setTextColor(BLACK);
  tft.setTextSize(text);
  tft.print("T3");

//Taste4
tft.fillRect(5,140,100,100,RED); 
  tft.setCursor(25,150);
  tft.setTextColor(BLACK);
  tft.setTextSize(text);
  tft.print("T4");

//Taste5
tft.fillRect(115,140,100,100,YELLOW);
  tft.setCursor(150,150);
  tft.setTextColor(BLACK);
  tft.setTextSize(text);
  tft.print("T5"); 

//Taste 6
tft.fillRect(225,140,100,100,YELLOW); 
  tft.setCursor(250,150);
  tft.setTextColor(BLACK);
  tft.setTextSize(text);
  tft.print("T6");

}


void Status() { 
tft.fillRect(0,0,320,40, BLACK);

  tft.setTextSize(texts);
    tft.setTextColor(WHITE);
 
  tft.setCursor (44,18);
// 44,2
  tft.print (Statustext);

}


void Button (){

  TSPoint p = ts.getPoint(); // if touch the programm will display message
 
  if (p.z > ts.pressureThreshhold) {   
   //Map funtion to convert the value from Touch into pixel
  p.x = map(p.x, TS_MAXX, TS_MINX, 0,330);
  p.y = map(p.y, TS_MAXY, TS_MINY, 0,480);
  }     

  // Taste 1
  if(p.x>65 && p.x<176 && p.y>17 && p.y<148 && buttonEnabled){ 
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  Statustext =  ("T1");
  Status();   
   } 

 
  // Taste 2
  if(p.x>67 && p.x<172 && p.y>190 && p.y<316  && buttonEnabled){ 
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  Statustext =  ("T2");
  Status();   
   } 

   // Taste 3
  if(p.x>65 && p.x<356 && p.y>362 && p.y<479  && buttonEnabled){ 
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  Statustext =  ("T3");
  Status();   
   } 

  // Taste 4
  if(p.x>202 && p.x<315 && p.y>17 && p.y<146&& buttonEnabled){ 
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  Statustext =  ("T4");
  Status();   
   } 

  // Taste 5
  if(p.x>202 && p.x<323 && p.y>179 && p.y<303  && buttonEnabled){ 
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  Statustext =  ("T5");
  Status();   
   } 

  // Taste 6
  if(p.x>203 && p.x<311 && p.y>357 && p.y<478  && buttonEnabled){ 
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  Statustext =  ("T6");
  Status();   
   }
 
  }

 

void TestLCD() {
  // a point object holds x y and z coordinates
  TSPoint p = ts.getPoint();
 
  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!
  if (p.z > ts.pressureThreshhold) {
      p.x = map(p.x, TS_MAXX, TS_MINX, 0,320);
     p.y = map(p.y, TS_MAXY, TS_MINY, 0,480);
     Serial.print("X = "); Serial.print(p.x);
     Serial.print("\t    Y = "); Serial.print(p.y);
     Serial.print("\t    Pressure = "); Serial.println(p.z);
  }

//  delay(50);
}

Thank You David

I added the code now as it should be. Sorry I am still a beginner.
I have the subroutines in different tabs, but I think that should not matter.

I also descovered that the Touchscreen only works with version. 1.5.3 of Adafruit GFX Library. If I choose a higher version the code can not be compiled. It showse "textsize_1" errors and more.
I found this answer in the Forum.

One more thing. I only tried with one touchscreen. I ordered 2 new once to check whether there is a hardware problem with the touchscreen. But I do not think so since the bug is absolutly reproducible.

Thank you and regards
Bernhard

First off. It is better to

edit your existing message to put the "code" into Code Window(s)

than to repeat the same code in a new message.

Adafruit_TFTLCD library is elderly and been hacked many times. textsize has been replaced by textsize_x in recent Adafruit_GFX library.
I recommend that you use MCUFRIEND_kbv library if you are using a Mcufriend shield. The statements are "neater"

#include <MCUFRIEND_kbv.h>
#include <TouchScreen.h>

//copy-paste Calibration values from Calibration sketch
const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341
const int TS_LEFT = 907, TS_RT = 136, TS_TOP = 942, TS_BOT = 139;

MCUFRIEND_kbv tft;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); //use Calibration values

You must ALWAYS restore XM, YP mode after EVERY call to ts.getPoint()
Your White screen is due to the library leaving control pins as Analog.

    TSPoint p = ts.getPoint();
    pinMode(XM, OUTPUT);  //.kbv ALWAYS restore pinMode()
    pinMode(YP, OUTPUT);

Look at the MCUFRIEND_kbv examples. I map the p.x and p.y values to pixel values. And only use the pixel_x and pixel_y values when there is a valid touch.

I suggest that you look at some of your duplicated code sequences. It is often worth writing a helper function. Or just restructuring the existing statements.

David.

Thank you very much.

It will take a bit of time for me to try all this.

Your support is very much appriciated.
Bernhard

Move the pinMode() statements to immediately after the getPoint() calls.

That is all to fix your White screen.

Tidying up your code requires you to do some thinking.

Personally, I would print on paper.
Then I can drink a nice cup of tea. Cross out code with a pencil. Draw arrows to show how the code works. Identify sequences that can be improved.

David.

Thank you David

All works now. :slight_smile: