0

ili9341 2'8 LCD question about white screen while power on
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ili9341 2'8 LCD question about white screen while power on

by meeke on Mon Jun 19, 2017 5:55 am

While the power on,the TFTLCD show white screen everytime.Is that backlight?
Can I turn it off,or fill screen with black while power on.
I have tried this below,initialize the TFT and fill screen with black immediately:
Code: Select all | TOGGLE FULL SIZE
void setup(void) {
tft.begin();
tft.fillScreen(ILI9341_BLACK);
//my code
}
void loop() {
//my code
}

but it seems doesn't work.When the power on,it still shows white before run the code tft.fillScreen(ILI9341_BLACK).

meeke
 
Posts: 5
Joined: Mon Jun 19, 2017 5:26 am

Re: ili9341 2'8 LCD question about white screen while power

by adafruit_support_rick on Mon Jun 19, 2017 10:07 am

Please post your entire sketch.

lease post pictures of both sides of your display, showing your soldering and wiring.

adafruit_support_rick
 
Posts: 34768
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: ili9341 2'8 LCD question about white screen while power

by meeke on Mon Jun 19, 2017 8:32 pm

adafruit_support_rick wrote:Please post your entire sketch.

lease post pictures of both sides of your display, showing your soldering and wiring.


TFT display and SD card will share the hardware SPI interface.
#define TFT_DC 9
#define TFT_CS 10
#define SD_CS 4 //SD card CS
//pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK
Attachments
微信图片_20170620082151.jpg
white screen while power on
微信图片_20170620082151.jpg (358.28 KiB) Viewed 111 times
微信图片_20170620082144.jpg
soldering and wiring
微信图片_20170620082144.jpg (267.68 KiB) Viewed 113 times

meeke
 
Posts: 5
Joined: Mon Jun 19, 2017 5:26 am

Re: ili9341 2'8 LCD question about white screen while power

by meeke on Tue Jun 20, 2017 3:36 am

Code: Select all | TOGGLE FULL SIZE
// This function opens a Windows Bitmap (BMP) file and
// displays it at the given coordinates.  It's sped up
// by reading many pixels worth of data at a time
// (rather than pixel by pixel).  Increasing the buffer
// size takes more of the Arduino's precious RAM but
// makes loading a little faster.  20 pixels seems a
// good balance.

#define BUFFPIXEL 20

void bmpDraw(char *filename, uint8_t x, uint16_t y) {

  File     bmpFile;
  int      bmpWidth, bmpHeight;   // W+H in pixels
  uint8_t  bmpDepth;              // Bit depth (currently must be 24)
  uint32_t bmpImageoffset;        // Start of image data in file
  uint32_t rowSize;               // Not always = bmpWidth; may have padding
  uint8_t  sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
  uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer
  boolean  goodBmp = false;       // Set to true on valid header parse
  boolean  flip    = true;        // BMP is stored bottom-to-top
  int      w, h, row, col;
  uint8_t  r, g, b;
  uint32_t pos = 0, startTime = millis();

  if((x >= tft.width()) || (y >= tft.height())) return;

  Serial.println();
  Serial.print(F("Loading image '"));
  Serial.print(filename);
  Serial.println('\'');

  // Open requested file on SD card
  if ((bmpFile = SD.open(filename)) == NULL) {
    Serial.print(F("File not found"));
    return;
  }

  // Parse BMP header
  if(read16(bmpFile) == 0x4D42) { // BMP signature
    Serial.print(F("File size: ")); Serial.println(read32(bmpFile));
    (void)read32(bmpFile); // Read & ignore creator bytes
    bmpImageoffset = read32(bmpFile); // Start of image data
    Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC);
    // Read DIB header
    Serial.print(F("Header size: ")); Serial.println(read32(bmpFile));
    bmpWidth  = read32(bmpFile);
    bmpHeight = read32(bmpFile);
    if(read16(bmpFile) == 1) { // # planes -- must be '1'
      bmpDepth = read16(bmpFile); // bits per pixel
      Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth);
      if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed

        goodBmp = true; // Supported BMP format -- proceed!
        Serial.print(F("Image size: "));
        Serial.print(bmpWidth);
        Serial.print('x');
        Serial.println(bmpHeight);

        // BMP rows are padded (if needed) to 4-byte boundary
        rowSize = (bmpWidth * 3 + 3) & ~3;

        // If bmpHeight is negative, image is in top-down order.
        // This is not canon but has been observed in the wild.
        if(bmpHeight < 0) {
          bmpHeight = -bmpHeight;
          flip      = false;
        }

        // Crop area to be loaded
        w = bmpWidth;
        h = bmpHeight;
        if((x+w-1) >= tft.width())  w = tft.width()  - x;
        if((y+h-1) >= tft.height()) h = tft.height() - y;

        // Set TFT address window to clipped image bounds
        tft.setAddrWindow(x, y, x+w-1, y+h-1);

        for (row=0; row<h; row++) { // For each scanline...

          // Seek to start of scan line.  It might seem labor-
          // intensive to be doing this on every line, but this
          // method covers a lot of gritty details like cropping
          // and scanline padding.  Also, the seek only takes
          // place if the file position actually needs to change
          // (avoids a lot of cluster math in SD library).
          if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
            pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
          else     // Bitmap is stored top-to-bottom
            pos = bmpImageoffset + row * rowSize;
          if(bmpFile.position() != pos) { // Need seek?
            bmpFile.seek(pos);
            buffidx = sizeof(sdbuffer); // Force buffer reload
          }

          for (col=0; col<w; col++) { // For each pixel...
            // Time to read more pixel data?
            if (buffidx >= sizeof(sdbuffer)) { // Indeed
              bmpFile.read(sdbuffer, sizeof(sdbuffer));
              buffidx = 0; // Set index to beginning
            }

            // Convert pixel from BMP to TFT format, push to display
            b = sdbuffer[buffidx++];
            g = sdbuffer[buffidx++];
            r = sdbuffer[buffidx++];
            tft.pushColor(tft.color565(r,g,b));
          } // end pixel
        } // end scanline
        Serial.print(F("Loaded in "));
        Serial.print(millis() - startTime);
        Serial.println(" ms");
      } // end goodBmp
    }
  }

  bmpFile.close();
  if(!goodBmp) Serial.println(F("BMP format not recognized."));
}

COM monitor log:
Initializing SD card...OK!

Loading image 'photo0.bmp'
File size: 109494
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 240x152
Loaded in 1592 ms
Show next photo...

Loading image 'photo1.bmp'
File size: 230454
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 240x320
Loaded in 3287 ms
Show next photo...

Loading image 'photo2.bmp'
File size: 230454
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 240x320
Loaded in 3290 ms

Displaying a BMP image(240*320) requires about 3s,even though I've modified BUFFPIXEL to increase the buffer size,it still requires about 3s.
Is there any other way makes loading a little faster?


#define BUFFPIXEL 20 -> #define BUFFPIXEL 200
uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer -> uint16_t buffidx = sizeof(sdbuffer);

COM monitor log:
Initializing SD card...OK!

Loading image 'photo0.bmp'
File size: 109494
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 240x152
Loaded in 1848 ms
Show next photo...

Loading image 'photo1.bmp'
File size: 230454
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 240x320
Loaded in 3825 ms
Show next photo...

Loading image 'photo2.bmp'
File size: 230454
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 240x320
Loaded in 3827 ms

meeke
 
Posts: 5
Joined: Mon Jun 19, 2017 5:26 am

Re: ili9341 2'8 LCD question about white screen while power

by meeke on Tue Jun 20, 2017 3:53 am

my entire project
Code: Select all | TOGGLE FULL SIZE
/***************************************************
  This is our Bitmap drawing example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651

  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/


#include <Adafruit_GFX.h>    // Core graphics library
#include "Adafruit_ILI9341.h" // Hardware-specific library
#include <SPI.h>
#include <SD.h>

// TFT display and SD card will share the hardware SPI interface.
// Hardware SPI pins are specific to the Arduino board type and
// cannot be remapped to alternate pins.  For Arduino Uno,
// Duemilanove, etc., pin 11 = MOSI, pin 12 = MISO, pin 13 = SCK.

#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

#define SD_CS 4
#define PIC_NUM 3
#define KEYpin 18

uint32_t OverTime;
uint8_t OverFlg = 1;

void setup(void) {
  //uint32_t Time;
  pinMode(KEYpin,INPUT);
 
  Serial.begin(9600);

  tft.begin();

  tft.fillScreen(ILI9341_BLACK);

  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("failed!");
    return;
  }
  Serial.println("OK!");
  bmpDraw("photo0.bmp", 0, 84);
  OverTime = millis() + 2000;
}
void loop() {
  int ButtonState = digitalRead(KEYpin);

  if(OverFlg < PIC_NUM)
  {
    if(millis() >= OverTime)
    {
      unsigned char pic_name[13];
      tft.fillScreen(ILI9341_BLACK);
      Serial.println("Show next photo...");
      sprintf(pic_name,"photo%d.bmp",OverFlg);
      bmpDraw(pic_name, 0, 0);
      OverTime = millis() + 2000;
      OverFlg++;
    }
  }
  else
  {
    if(ButtonState==0)
    {
      delay(10);//延时消抖处理
      if(ButtonState==0)               
      {
        unsigned char pic_name[13];
        static unsigned char pic_num = 5;
        tft.fillScreen(ILI9341_BLACK);
       
        if(pic_num < PIC_NUM)
        {
          unsigned char pic_name[13];
          Serial.println("Show next photo...");
          sprintf(pic_name,"photo%d.bmp",pic_num);
          if(pic_num)
            bmpDraw(pic_name, 0, 0);
          else
            bmpDraw(pic_name, 0, 84);
          pic_num++;
        }
        else
        {
          static unsigned char num = 1;
          if(num < 7)
          {
            Serial.println("Show next picture...");
            sprintf(pic_name,"picture%d.bmp",num);
            bmpDraw(pic_name, 0, 0);
            num++;
            pic_num++;
          }
          if(num == 7)
          {
            num = 1;
            pic_num = 0;
          }     
        }
        while(digitalRead(KEYpin)==0)//等待按键松开,避免多张切换
        {
          //Serial.println("按键未松开");   
        }   
      } 
    }
    else
    {
     
    } 
  }
}



// This function opens a Windows Bitmap (BMP) file and
// displays it at the given coordinates.  It's sped up
// by reading many pixels worth of data at a time
// (rather than pixel by pixel).  Increasing the buffer
// size takes more of the Arduino's precious RAM but
// makes loading a little faster.  20 pixels seems a
// good balance.

#define BUFFPIXEL 20

void bmpDraw(char *filename, uint8_t x, uint16_t y) {

  File     bmpFile;
  int      bmpWidth, bmpHeight;   // W+H in pixels
  uint8_t  bmpDepth;              // Bit depth (currently must be 24)
  uint32_t bmpImageoffset;        // Start of image data in file
  uint32_t rowSize;               // Not always = bmpWidth; may have padding
  uint8_t  sdbuffer[3*BUFFPIXEL]; // pixel buffer (R+G+B per pixel)
  uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer
  boolean  goodBmp = false;       // Set to true on valid header parse
  boolean  flip    = true;        // BMP is stored bottom-to-top
  int      w, h, row, col;
  uint8_t  r, g, b;
  uint32_t pos = 0, startTime = millis();

  if((x >= tft.width()) || (y >= tft.height())) return;

  Serial.println();
  Serial.print(F("Loading image '"));
  Serial.print(filename);
  Serial.println('\'');

  // Open requested file on SD card
  if ((bmpFile = SD.open(filename)) == NULL) {
    Serial.print(F("File not found"));
    return;
  }

  // Parse BMP header
  if(read16(bmpFile) == 0x4D42) { // BMP signature
    Serial.print(F("File size: ")); Serial.println(read32(bmpFile));
    (void)read32(bmpFile); // Read & ignore creator bytes
    bmpImageoffset = read32(bmpFile); // Start of image data
    Serial.print(F("Image Offset: ")); Serial.println(bmpImageoffset, DEC);
    // Read DIB header
    Serial.print(F("Header size: ")); Serial.println(read32(bmpFile));
    bmpWidth  = read32(bmpFile);
    bmpHeight = read32(bmpFile);
    if(read16(bmpFile) == 1) { // # planes -- must be '1'
      bmpDepth = read16(bmpFile); // bits per pixel
      Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth);
      if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed

        goodBmp = true; // Supported BMP format -- proceed!
        Serial.print(F("Image size: "));
        Serial.print(bmpWidth);
        Serial.print('x');
        Serial.println(bmpHeight);

        // BMP rows are padded (if needed) to 4-byte boundary
        rowSize = (bmpWidth * 3 + 3) & ~3;

        // If bmpHeight is negative, image is in top-down order.
        // This is not canon but has been observed in the wild.
        if(bmpHeight < 0) {
          bmpHeight = -bmpHeight;
          flip      = false;
        }

        // Crop area to be loaded
        w = bmpWidth;
        h = bmpHeight;
        if((x+w-1) >= tft.width())  w = tft.width()  - x;
        if((y+h-1) >= tft.height()) h = tft.height() - y;

        // Set TFT address window to clipped image bounds
        tft.setAddrWindow(x, y, x+w-1, y+h-1);

        for (row=0; row<h; row++) { // For each scanline...

          // Seek to start of scan line.  It might seem labor-
          // intensive to be doing this on every line, but this
          // method covers a lot of gritty details like cropping
          // and scanline padding.  Also, the seek only takes
          // place if the file position actually needs to change
          // (avoids a lot of cluster math in SD library).
          if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
            pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
          else     // Bitmap is stored top-to-bottom
            pos = bmpImageoffset + row * rowSize;
          if(bmpFile.position() != pos) { // Need seek?
            bmpFile.seek(pos);
            buffidx = sizeof(sdbuffer); // Force buffer reload
          }

          for (col=0; col<w; col++) { // For each pixel...
            // Time to read more pixel data?
            if (buffidx >= sizeof(sdbuffer)) { // Indeed
              bmpFile.read(sdbuffer, sizeof(sdbuffer));
              buffidx = 0; // Set index to beginning
            }

            // Convert pixel from BMP to TFT format, push to display
            b = sdbuffer[buffidx++];
            g = sdbuffer[buffidx++];
            r = sdbuffer[buffidx++];
            tft.pushColor(tft.color565(r,g,b));
          } // end pixel
        } // end scanline
        Serial.print(F("Loaded in "));
        Serial.print(millis() - startTime);
        Serial.println(" ms");
      } // end goodBmp
    }
  }

  bmpFile.close();
  if(!goodBmp) Serial.println(F("BMP format not recognized."));
}

// These read 16- and 32-bit types from the SD card file.
// BMP data is stored little-endian, Arduino is little-endian too.
// May need to reverse subscript order if porting elsewhere.

uint16_t read16(File &f) {
  uint16_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read(); // MSB
  return result;
}

uint32_t read32(File &f) {
  uint32_t result;
  ((uint8_t *)&result)[0] = f.read(); // LSB
  ((uint8_t *)&result)[1] = f.read();
  ((uint8_t *)&result)[2] = f.read();
  ((uint8_t *)&result)[3] = f.read(); // MSB
  return result;
}

meeke
 
Posts: 5
Joined: Mon Jun 19, 2017 5:26 am

Re: ili9341 2'8 LCD question about white screen while power

by adafruit_support_rick on Tue Jun 20, 2017 8:31 am

Ah, I see what you're asking.
You can try connecting the LITE pin. Drive the pin LOW to turn off the backlight when you start up. Fill the screen with black, then drive the pin HIGH to turn the backlight on.

There's no way to make it go faster on a Uno. Also, as you can see, increasing BUFFPIXEL just makes it go slower.

adafruit_support_rick
 
Posts: 34768
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Re: ili9341 2'8 LCD question about white screen while power

by meeke on Wed Jun 21, 2017 3:14 am

adafruit_support_rick wrote:Ah, I see what you're asking.
You can try connecting the LITE pin. Drive the pin LOW to turn off the backlight when you start up. Fill the screen with black, then drive the pin HIGH to turn the backlight on.

There's no way to make it go faster on a Uno. Also, as you can see, increasing BUFFPIXEL just makes it go slower.

Thank you very much.According to what you said, backlight still on while power on,becasue it is HIGH when power on.
I guess that is LCD LITE work earlier than MCU controls .
So I changed the idea,connecting LITE with a resistance to the ground and then use an IO to drive the LITE pin HIGH to turn the backlight on,and it worked.

meeke
 
Posts: 5
Joined: Mon Jun 19, 2017 5:26 am

Re: ili9341 2'8 LCD question about white screen while power

by adafruit_support_rick on Wed Jun 21, 2017 10:22 am

nice!

adafruit_support_rick
 
Posts: 34768
Joined: Tue Mar 15, 2011 11:42 am
Location: Buffalo, NY

Please be positive and constructive with your questions and comments.