Go Down

Topic: 2.4 inch LCD TFT Display Shield only shows white! (Read 44573 times) previous topic - next topic

andersmmg

I recently got a new LCD TFT Display Shield and when I try anything it only shows white! I can use the touchscreen library with no problems and can get coordinates but i can't show anything on the display! I just tried with the ADAFRUIT library and another one called TFTLCD.   :'(  :(  
Can someone help me?? It shows C0C0 as my driver chip and says it it unknown!
I hoped to use this but it won't work either:

Code: [Select]

#include "TFTLCD.h"
#include "TouchScreen.h"


//Duemilanove/Diecimila/UNO/etc ('168 and '328 chips) microcontoller:



#define YP A1  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 7   // can be a digital pin
#define XP 6   // can be a digital pin

#define TS_MINX 150
#define TS_MINY 120
#define TS_MAXX 920
#define TS_MAXY 940

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4

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



TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

#define BOXSIZE 40
#define PENRADIUS 3
int oldcolor, currentcolor;

void setup(void) {
  Serial.begin(9600);
  Serial.println("Paint!");
 
  tft.reset();
 
 
  uint16_t identifier = tft.readRegister(0x0);
  if (identifier == 0x9325) {
    Serial.println("Found ILI9325");
  } else if (identifier == 0x9328) {
    Serial.println("Found ILI9328");
  } else {
    Serial.print("Unknown driver chip ");
    Serial.println(identifier, HEX);
    while (1);
  }

  tft.initDisplay();
  tft.fillScreen(BLACK);
 
  tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
  tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
  tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
  tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
  tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
  tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
 // tft.fillRect(BOXSIZE*6, 0, BOXSIZE, BOXSIZE, WHITE);
 
 tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
 currentcolor = RED;
 
  pinMode(13, OUTPUT);
}



#define MINPRESSURE 10
#define MAXPRESSURE 1000



void loop()
{
  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);


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

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {

   
    if (p.y < (TS_MINY-5)) {
      Serial.println("erase");
     // press the bottom of the screen to erase
      tft.fillRect(0, BOXSIZE, tft.width(), tft.height()-BOXSIZE, BLACK);
     
    }
    // turn from 0->1023 to tft.width
    p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
    p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());

    if (p.y < BOXSIZE) {
       oldcolor = currentcolor;
 
 
       if (p.x < BOXSIZE) {
         currentcolor = RED;
         tft.drawRect(0, 0, BOXSIZE, BOXSIZE, WHITE);
       }
       else if (p.x < BOXSIZE*2) {
         currentcolor = YELLOW;
         tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, WHITE);
       }
       else if (p.x < BOXSIZE*3) {
         currentcolor = GREEN;
         tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, WHITE);
       }
       else if (p.x < BOXSIZE*4) {
         currentcolor = CYAN;
         tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, WHITE);
       }
       else if (p.x < BOXSIZE*5) {
         currentcolor = BLUE;
         tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, WHITE);
       }
       else if (p.x < BOXSIZE*6) {
         currentcolor = MAGENTA;
         tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE);
       }
       
       if (oldcolor != currentcolor) {
          if (oldcolor == RED) tft.fillRect(0, 0, BOXSIZE, BOXSIZE, RED);
          if (oldcolor == YELLOW) tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, YELLOW);
          if (oldcolor == GREEN) tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, GREEN);
          if (oldcolor == CYAN) tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, CYAN);
          if (oldcolor == BLUE) tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, BLUE);
          if (oldcolor == MAGENTA) tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, MAGENTA);
       }
    }
    if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
      tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
    }
  }
}

luisilva

Where did you buy the display? Do you have a link to it or any picture? I think you don't have the right library.

andersmmg

I don't have a picture or link, but it's one that says http://www.mcufriend.com on the back. I've tried going to that webpage, but it was taken down or something. I've tried to find others with the problem but everyone who gets it to work has a different solution and I can't get them to work. I think it may be the wrong pins but as it is a shield, I cannot change them physically.  :smiley-sad:
I'll post a picture as soon as I can get one.

goltermc

I also recently got a similar 2.8 inch lcd display and got only a white screen.

I spent quite a while trying several "libraries" out with no success. Just a white screen.
I finally settled in on using the AdaFruit AdaTFTLCD library. I started putting serial print statements within the readID method and the problem went away. The sample code I'm using looks like this (within setup)


 tft.reset();

 uint16_t identifier = tft.readID();

By putting a delay (serial.print statement) into readID , I think I was allowing the reset operation to complete! I have not looked at the specs for the chipset which drives the display BUT it is often the case that a hardware reset takes a lot of time. In the end I put a delay(500) inside of the tft.reset method. I now read the device id successfully and have everything working.

You could also put the delay into the arduino setup code like this


 tft.reset();

 delay(500);

 uint16_t identifier = tft.readID();


andersmmg

#4
Dec 29, 2014, 07:14 pm Last Edit: Dec 29, 2014, 07:27 pm by andersmmg
By putting a delay (serial.print statement) into readID , I think I was allowing the reset operation to complete! I have not looked at the specs for the chipset which drives the display BUT it is often the case that a hardware reset takes a lot of time. In the end I put a delay(500) inside of the tft.reset method. I now read the device id successfully and have everything working.

You could also put the delay into the arduino setup code like this


 tft.reset();

 delay(500);

 uint16_t identifier = tft.readID();

I tried that, but it just said

Unknown driver chip 0

instead of

Unknown driver chip C0C0

Edit: It says C0C0 if I use the adafruit library.
:smiley-sad:  :smiley-sad:

The display is still white too.  :smiley-small:

goltermc

Try this

I've attached my modified AdaTFTLCD arduino library as a zip file.

Unzip this in your arduino libraries directory (There is probably already an AdaTFTLCD directory there rename it before you unzip the one I am providing)

Restart the arduino IDE (or it will not be using the new library)

Open File->Examples->AdaTFT->graphicstest build that and see if it works.

Let me know how it goes


andersmmg

#6
Dec 29, 2014, 08:07 pm Last Edit: May 30, 2015, 02:24 am by andersmmg
I did it and the serial monitor says :

Code: [Select]

TFT LCD test
Using Adafruit 2.8" TFT Arduino Shield Pinout
TFT size is 240x320
Unknown LCD driver chip: C0C0
If using the Adafruit 2.8" TFT Arduino shield, the line:
  #define USE_ADAFRUIT_SHIELD_PINOUT
should appear in the library header (Adafruit_TFT.h).
If using the breakout board, it should NOT be #defined!
Also if using the breakout, double-check that all wiring
matches the tutorial.

I also got the same when I added delay(500); after the reset function and before the driver detection.
I've put the current code on http://code.jazinc.cu.cc/codecollab/text/#tft-code

goltermc

Hmmm..

C0C0 was what I got before I put the delay in the code.

One more thing to try.

Change this code


  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D 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."));
    return;
  }

to this


  if(identifier == 0x9325) {
    Serial.println(F("Found ILI9325 LCD driver"));
  } else if(identifier == 0x9328) {
    Serial.println(F("Found ILI9328 LCD driver"));
  } else if(identifier == 0x7575) {
    Serial.println(F("Found HX8347G LCD driver"));
  } else if(identifier == 0x9341) {
    Serial.println(F("Found ILI9341 LCD driver"));
  } else if(identifier == 0x8357) {
    Serial.println(F("Found HX8357D 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."));
    //return;
    identifier = 0x9341;
  }

If that doesn't work change the identifier to each of the possibilities , one at a time and see if one of them works.


andersmmg

#8
Dec 29, 2014, 08:23 pm Last Edit: Dec 29, 2014, 08:24 pm by andersmmg
This in serial and still a white screen! :smiley-sad: BTW: Thanks for all this help!

Code: [Select]

TFT LCD test
Using Adafruit 2.8" TFT Arduino Shield Pinout
TFT size is 240x320
Unknown LCD driver chip: C0C0
If using the Adafruit 2.8" TFT Arduino shield, the line:
  #define USE_ADAFRUIT_SHIELD_PINOUT
should appear in the library header (Adafruit_TFT.h).
If using the breakout board, it should NOT be #defined!
Also if using the breakout, double-check that all wiring
matches the tutorial.
Benchmark                Time (microseconds)
Screen fill              450128
Text                     297976
Lines                    2970048
Horiz/Vert Lines         63876
Rectangles (outline)     51568
Rectangles (filled)      1263664
Circles (filled)         854356
Circles (outline)        1294216
Triangles (outline)      943164
Triangles (filled)       871560
Rounded rects (outline)  421340
Rounded rects (filled)   1591216
Done!

andersmmg

I tried all of it and changed delays, but it still will not work! Help!!!   :smiley-sad:  :smiley-sad:

goltermc

Hi andersmmg,

I do not think you are using the library I provided. If you were your serial monitor would read


Using Adafruit 2.8" TFT Breakout Board Pinout

The message you are getting is

Using Adafruit 2.8" TFT Arduino Shield Pinout

This indicates you are using an unmodified  Adafruit_TFTLCD.h.

The pinout of the "made in china" TFTLCD shields is apparently different than the pinout used by a real AdaFruit Module.

In libraries/AdaTFTLCD/Adafruit_TFTLCD.h the line

#define USE_ADAFRUIT_SHIELD_PINOUT 1

must be commented out. Without this I believe the adafruit library will ignore the pinout the example is providing.

The Adafruit_TFTLCD.h which I provided has this line commented out.





goltermc

The change I made to Adafruit_TFTLCD.cpp is very simple.

Open libraries/AdaTFTLCD/Adafruit_TFTLCD.cpp in an editor and search for Adafruit_TFTLCD::reset(void).

This is the reset method. It should look something like this.

void Adafruit_TFTLCD::reset(void) {

  CS_IDLE;
//  CD_DATA;
  WR_IDLE;
  RD_IDLE;

#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  digitalWrite(5, LOW);
  delay(2);
  digitalWrite(5, HIGH);
#else
  // if we have a reset pin defined ( _reset )
  if(_reset) {
    digitalWrite(_reset, LOW);
    delay(2);
    digitalWrite(_reset, HIGH);
  }
#endif

  // Data transfer sync
  CS_ACTIVE;
  CD_COMMAND;
  write8(0x00);
  for(uint8_t i=0; i<3; i++) WR_STROBE; // Three extra 0x00s
  CS_IDLE;
 
  // let the display recover from the reset
  delay(500);

}


The last two lines are what I added. If they are not there then add them. If they are there add

Serial.println("Added delay to the reset method");

Save the file and rebuild the test and rerun it. If you do not see

Added delay to the reset method

in the serial monitor, this library is not being used.



andersmmg

#12
Dec 30, 2014, 04:58 am Last Edit: Dec 30, 2014, 04:59 am by andersmmg
It is using that library and I triple checked that it is commented out and not defined, but I still get
Code: [Select]

Using Adafruit 2.8" TFT Arduino Shield Pinout

!!!!!!!!! :smiley-sad:  :smiley-confuse:

Quote
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
  Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
  Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif

Is that how it's supposed to be?

goltermc

It would appear that your adruino installation is getting the Adafruit_TFTLCD library from elsewhere.
So lets try a different approach.

I'm attaching a zipped adruino project which has all the Adafruit_TFTLCD library files renamed and local to the project.

Unzip this and it will create a directory called AndersmmgLcd. This should be placed in the same directory as your other Adruino projects.

Restart Arduino. Under File->Sketch you should see

AndersmmgLcd

Open this , build it and upload to your board.


goltermc

Oops forgot to attach the zip


Go Up