Pages: 1 ... 10 11 [12] 13   Go Down
Author Topic: LCD display with ILI9341 driver on Arduino  (Read 54283 times)
0 Members and 1 Guest are viewing this topic.
Villeurbanne (France)
Offline Offline
Full Member
***
Karma: 2
Posts: 129
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello !

I cut the pin Vcc (input) of the card and sold a wire from the cable to Raw and now it works.




The 3.3 V data outputs are strong enough to drive the ILI9340.
« Last Edit: August 11, 2014, 02:55:40 am by micol » Logged

*** Micol *** resolutly politically NOT correct

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again! Im still working with the ili9341, finally im working with the adafruit libraries and trying to show a picture from the SD.

It looks like the code is ok because the monitor serial show me that info but the LCD is still white.

Quote
Initializing SD card...OK!
Loading image 'flower.bmp'
File size: 230454
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 240x320
Loaded in 3846 ms

This is my code from the examples:

Code:
/***************************************************
  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
 
  Aditions by Carlos Silva - May 2014
 ****************************************************/


#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.
// MEGA pin 51 = MOSI, pin 50 = MISO, pin 52 = SCK.

#define TFT_DC 9
#define TFT_CS 10

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

#define SD_CS 4

void setup(void) {
  Serial.begin(9600);

  tft.begin();
  tft.fillScreen(ILI9341_BLUE);
 
  Serial.print("Initializing SD card...");
  if (!SD.begin(SD_CS)) {
    Serial.println("failed!");
  }
  Serial.println("OK!");

  bmpDraw("flower.bmp", 0, 0);
}

void loop() {
}

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

My connection scheme (i know its not the correct pic but its my firts sketch with fritzing...)
http://s28.postimg.org/onn5mvj0d/ili9341_bb.jpg

Any suggestion?
« Last Edit: August 12, 2014, 03:59:49 am by Rastud » Logged

Villeurbanne (France)
Offline Offline
Full Member
***
Karma: 2
Posts: 129
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello Rastud,

You problem is exactly the same as mine. What you write is like my post N° 147 (page 10) and my photo (post #152 page 11)
Either with Adafruit library 9340 and woof.bmp or with Adafruit library 9341 and flower.bmp
I tried with MEGA, UNO, ProMini with the same results.

For other applications, I now use Ucglib library, but it dont allow showing a picture from SD.

Logged

*** Micol *** resolutly politically NOT correct

Offline Offline
God Member
*****
Karma: 10
Posts: 736
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


My connection scheme (i know its not the correct pic but its my firts sketch with fritzing...)
http://s28.postimg.org/onn5mvj0d/ili9341_bb.jpg

What a mess  smiley-eek
Any suggestion?

At a first glance everything seems to be OK.

Not knowing the buffer specs I would try to reduce the SPI speed.
Place this on your setup and report

SPI_CLOCK_DIV64
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Not knowing the buffer specs I would try to reduce the SPI speed.
Place this on your setup and report

SPI_CLOCK_DIV64

Thanks for the advice but i still have the same results.
Logged

Offline Offline
God Member
*****
Karma: 10
Posts: 736
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Not knowing the buffer specs I would try to reduce the SPI speed.
Place this on your setup and report

SPI_CLOCK_DIV64

Thanks for the advice but i still have the same results.

The code you posted above was modified by me, so i am pretty sure it does work.
Ill give it a go and let you know. What's the buffer/level shifter you are using?
Logged

Offline Offline
God Member
*****
Karma: 10
Posts: 736
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just tested.

Since i didn't had a regular SD card at hand I used the card reader from other display, but other than that all standard.

Arduino mini powered from a lithium battery at 3.7V

[Prepare for the real mess  smiley-twist]

Just as a disclaimer i removed all the libraries and installed the ones from the zip file I uploaded earlier just to be sure. I am now using arduino 1.5.7



* IMG_20140813_165723685[1].jpg (1557.75 KB, 2592x1456 - viewed 55 times.)

* IMG_20140813_165740522[1].jpg (1436.98 KB, 2592x1456 - viewed 39 times.)
Logged

ivrea (to)
Offline Offline
Faraday Member
**
Karma: 87
Posts: 5062
miaaao ^-^
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Very beautiful your desktop. There is a little chaos ... organized   smiley-mr-green
Logged

my name is IGOR, not AIGOR

Offline Offline
God Member
*****
Karma: 10
Posts: 736
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Very beautiful your desktop. There is a little chaos ... organized   smiley-mr-green

Had to squeeze another breadboard between the keyboard and my actual project  smiley-wink
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code you posted above was modified by me, so i am pretty sure it does work.
Ill give it a go and let you know. What's the buffer/level shifter you are using?

Hi casemod, thanks for your help but still i cant show the picture.

The buffer im using is the CD4050BE, i think that is ok, right?

On the other hand im using a 2Gb micro SD with a SD adapter in FAT32 format and i just have the picture with nothing else. Maybe there is any problem with that?
Logged

Offline Offline
God Member
*****
Karma: 10
Posts: 736
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code you posted above was modified by me, so i am pretty sure it does work.
Ill give it a go and let you know. What's the buffer/level shifter you are using?

Hi casemod, thanks for your help but still i cant show the picture.

The buffer im using is the CD4050BE, i think that is ok, right?

On the other hand im using a 2Gb micro SD with a SD adapter in FAT32 format and i just have the picture with nothing else. Maybe there is any problem with that?

The SD seems to be working as per your last post,

Initializing SD card...OK!
Loading image 'flower.bmp'
....
Loaded in 3846 ms


So I am guessing the connections are OK. Grab some other library and try to get the LCD working on its own without the SD. Who knows, could be faulty.
Logged

Villeurbanne (France)
Offline Offline
Full Member
***
Karma: 2
Posts: 129
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

On yesterday, after about 4 months trying, I have got a bmp picture on my ILI9340.

I succeed with a ProMini 3.3 volts, witch avoid resistors and 4050. I don't know if it is the reason.
I use Adafruit_9340 library.  I don't succeed with Adafruit_9341 library.
I don't succed with ProMini 5 volts nor UNO nor MEGA.



Then, I modified the program so as to show several pictures alternantively. It works.

To save time, I made bmp pictures with 1 bit color (for instance black and white) but the program does not accept them and says : "BMP format not recognized". Is there any way to work with such pictures ?
Logged

*** Micol *** resolutly politically NOT correct

Offline Offline
God Member
*****
Karma: 10
Posts: 736
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To save time, I made bmp pictures with 1 bit color (for instance black and white) but the program does not accept them and says : "BMP format not recognized". Is there any way to work with such pictures ?

I see no reason why they would not work on the mini if you power it from 3.3V skipping the resistors/buffer.
You have a nice 3.3V breadboard voltage regulator, just link that to the 5V pin on the Uno or VCC on the 16MHz mini.

You need to remove the 5V wire from the serial connector on the mini or remove the resettable fuse on the uno, as per photo (Ignore any other mods). Then you can select 3.3/5 at will. Ill make a tutorial on this at some point, just waiting for the crystals for another board I have in parts.

Check the attached photo - Just remove the resettable fuse

You still have to save them in 24 bit format.

I havent found a workarround for this, technically it could be much faster.
there is however a toturial on how to convert raw images to native RGB565 TFT format so that they are loaded much faster.

Check here:
http://arduinoexplained.blogspot.co.uk/2012/05/image-slideshow-with-arduino.html


* IMG_20140815_111600019.jpg (854.63 KB, 1456x2592 - viewed 24 times.)
Logged

Villeurbanne (France)
Offline Offline
Full Member
***
Karma: 2
Posts: 129
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your quick answer.

You give me two ways of work. The hardware way will wait for another day and I explore the sotware way because the slideshow on the linked page is very attractive.
The link to a converter in the page is no more valid.

I downloaded another converter but it does not match. It is RGB565Converter_V0.3.
The result cannot be open by any software, even if I change the suffixe by .bmp.

The input picture size is 225 KO, the output size is 300 KO.
 smiley-roll
« Last Edit: August 15, 2014, 09:30:12 am by micol » Logged

*** Micol *** resolutly politically NOT correct

Offline Offline
God Member
*****
Karma: 10
Posts: 736
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your quick answer.

You give me two ways of work. The hardware way will wait for another day and I explore the sotware way because the slideshow on the linked page is very attractive.
The link to a converter in the page is no more valid.

I downloaded another converter but it does not match. It is RGB565Converter_V0.3.
The result cannot be open by any software, even if I change the suffixe by .bmp.

The input picture size is 225 KO, the output size is 300 KO.
 smiley-roll

http://www.henningkarlsen.com/electronics/t_imageconverter565.php
Try this one and see if you get the same results.
BTW the modified file has its own extension, its not a bmp and trying to load it as such wont display a correct output.

The UTFT library supports this method. Try to install it and have a look at this sketch for reference (the panel is different)

https://github.com/stanleyhuangyc/ArduinoTFT/blob/master/SDImageViewer/SDImageViewer.ino
Logged

Pages: 1 ... 10 11 [12] 13   Go Up
Jump to: