Touchscreen turns white after touch ili9486 driver

Hi,

I'm new here so forgive me my beginners mistakes.

I'm using a 3.5" display. The startscreen is shown wel and the touch is also ok and correspond correct.
The screen used: https://www.otronic.nl/nl/35-inch-touch-screen-tft-shield-voor-arduino-uno-e.html

The code I've partly written:

`#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <TouchScreen.h>

// 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



// Assign human-readable names to some common 16-bit color values:
#define	BLACK   0x0000
#define	BLUE    0x001F
#define	RED     0xF800
#define	GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

// Color definitions
#define ILI9341_BLACK       0x0000      /*   0,   0,   0 */
#define ILI9341_NAVY        0x000F      /*   0,   0, 128 */
#define ILI9341_DARKGREEN   0x03E0      /*   0, 128,   0 */
#define ILI9341_DARKCYAN    0x03EF      /*   0, 128, 128 */
#define ILI9341_MAROON      0x7800      /* 128,   0,   0 */
#define ILI9341_PURPLE      0x780F      /* 128,   0, 128 */
#define ILI9341_OLIVE       0x7BE0      /* 128, 128,   0 */
#define ILI9341_LIGHTGREY   0xC618      /* 192, 192, 192 */
#define ILI9341_DARKGREY    0x7BEF      /* 128, 128, 128 */
#define ILI9341_BLUE        0x001F      /*   0,   0, 255 */
#define ILI9341_GREEN       0x07E0      /*   0, 255,   0 */
#define ILI9341_CYAN        0x07FF      /*   0, 255, 255 */
#define ILI9341_RED         0xF800      /* 255,   0,   0 */
#define ILI9341_MAGENTA     0xF81F      /* 255,   0, 255 */
#define ILI9341_YELLOW      0xFFE0      /* 255, 255,   0 */
#define ILI9341_WHITE       0xFFFF      /* 255, 255, 255 */
#define ILI9341_ORANGE      0xFD20      /* 255, 165,   0 */
#define ILI9341_GREENYELLOW 0xAFE5      /* 173, 255,  47 */
#define ILI9341_PINK        0xF81F

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

//Param For 3.5"
#define TS_MINX 118
#define TS_MAXX 906

#define TS_MINY 92
#define TS_MAXY 951

#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

char currentPage;

void setup(void) {
  
  Serial.begin(9600);
  Serial.println(F("TFT LCD test"));

  tft.reset();
/*
  uint16_t identifier = tft.readID();
  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x4535) {
    Serial.println(F("Found LGDP4535 LCD driver"));
  }else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9595) {
    Serial.println(F("Found HX8347-I LCD driver"));
  } else if(identifier == 0x4747) {
    Serial.println(F("Found HX8347-D LCD driver"));
  } else if(identifier == 0x8347) {
    Serial.println(F("Found HX8347-A LCD driver"));
  }else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  }else if(identifier == 0x7783) {
    Serial.println(F("Found ST7781 LCD driver"));
  }else if(identifier == 0x8230) {
    Serial.println(F("Found UC8230 LCD driver"));  
  }else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D LCD driver"));
  } else if(identifier==0x0101){     
      identifier=0x9341;
      Serial.println(F("Found 0x9341 LCD driver"));
  }else if(identifier==0x7793){     
       Serial.println(F("Found ST7793 LCD driver"));
  }else if(identifier==0xB509){     
       Serial.println(F("Found R61509 LCD driver"));
  }else if(identifier==0x9486){     
       Serial.println(F("Found ILI9486 LCD driver"));
  }else if(identifier==0x9488){     
       Serial.println(F("Found ILI9488 LCD driver"));
  }else {
    Serial.print(F("Unknown LCD driver chip: "));
    Serial.println(identifier, HEX);
    Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
    Serial.println(F("  #define USE_ADAFRUIT_SHIELD_PINOUT"));
    Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
    Serial.println(F("If using the breakout board, it should NOT be #defined!"));
    Serial.println(F("Also if using the breakout, double-check that all wiring"));
    Serial.println(F("matches the tutorial."));
    identifier=0x9488; 
  }
  */
  tft.begin(0x9486);
  delay(100);
  Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
  tft.setRotation(3);
  tft.fillScreen(BLACK);

  currentPage = '0'; // Indicates that we are at Home Screen
  drawHomeScreen();  // Draws the Home Screen

}

  


void loop(void) {

  TSPoint p = ts.getPoint();
  
  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!
  if (p.z > ts.pressureThreshhold) {
    int TvalX = p.y; // Switch X and Y because mode is Landscape
     TvalX = map(TvalX, 10, 1000, 1, 480);
     Serial.print("X = "); Serial.print(TvalX);
     Serial.print('\n');
     //Serial.print("----------");
     int TvalY = p.x; // Switch X and Y because mode is Landscape
     TvalY = map(TvalY, 10, 1000, 1, 320);
     Serial.print("Y = "); Serial.print(TvalY);
     Serial.print('\n');
     //Serial.print("tPressure = "); Serial.println(p.z);
     Serial.println("----------");
  
  if ((TvalX >= 140) && (TvalX <= 400) && (TvalY >= 16) && (TvalY <= 200)) {
    tft.fillRoundRect(100, 150, 300, 50, 10, BLUE); // Highlights the button
    delay(1000);
    currentPage = '1'; 
    // Check currentPage value
    drawAutomaticmode(); 
    }   
  }
}
    


void drawHomeScreen() {
  // Title
  tft.fillScreen(BLACK); // Sets the background color of the area where the text will be printed to black
  tft.setTextColor(WHITE); // Sets color to white
  tft.setCursor(110,0);
  tft.setTextSize(3); // Sets font to big
  tft.println("Stokkenvangspel"); // Prints the string on the screen
  tft.setCursor(150,35);
  tft.setTextColor(WHITE); // Sets color to white
  tft.setTextSize(2); // Sets the font to small
  tft.println("by E-Electronics"); // Prints the string
  tft.fillRoundRect(0, 60, 480, 3, 0, RED);
  tft.setCursor(120,70);
  tft.setTextColor(RED); // Sets color to white
  tft.setTextSize(3);
  tft.print("Selecteer spel");
  tft.fillRoundRect(0, 100, 480, 3, 0, RED);

  // Button - Automatisch
  tft.fillRoundRect(100, 150, 300, 50, 10, GREEN); // Draws filled rounded rectangle
  tft.drawRoundRect(100, 150, 300, 50, 10, WHITE); // Draws rounded rectangle without a fill, so the overall appearance of the button looks like it has a frame
  tft.setTextSize(3); // Sets the font to big
  tft.setTextColor(RED);
  tft.setCursor(152,163);
  tft.print("Automatisch"); // Prints the string
  
  //Button - Handmatig
  tft.fillRoundRect(100, 220, 300, 50, 10, GREEN); // Draws filled rounded rectangle
  tft.drawRoundRect(100, 220, 300, 50, 10, WHITE); // Draws rounded rectangle without a fill, so the overall appearance of the button looks like it has a frame
  tft.setTextSize(3); // Sets the font to big
  tft.setTextColor(RED);
  tft.setCursor(170,235);
  tft.print("Handmatig"); // Prints the string
}

void drawAutomaticmode() {
    
    Serial.println("Drawing Automatic mode"); // Confirm entry to mode
    Serial.println("Current page "); Serial.print(currentPage);// Confirm entry to mode
    tft.drawCircle(240, 160, 100, BLUE);
    Serial.println("Drawed circle");
    //tft.fillScreen(BLACK);      // Clear screen
    //tft.setTextColor(WHITE);    // Set text color
    //tft.setTextSize(3);         // Set text size
    //tft.setCursor(100, 150);    // Set cursor position
    //tft.println("Automatisch"); // Display simple text
}
 
`

After touching the button "Automatisch" the screen turns white and does not respond anymore. When I touch the button area I see the correct coordinates in the serial monitor.

Does anyone have a clue to solve this?

Topic moved !! Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

Whenever you call the getTouch() function, you need to set the analog pins (A2 and A3), that are shared with the display, back to output mode afterwards.

Many thanks david_2018. Works fine now!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.