Hi
I ordered a "2.2" 18-bit color TFT LCD display with microSD card breakout - ILI9340" some weeks back, and I am having troubles getting it to work reliably.
Wiring (Arduino Uno): GND = GND | VIN = 5V | DC = 9 | RST = <none> | SDCS = 4 | CS = 10 | MOSI = 11 | MISO = 12 | SCK = 13 | BL = <none>
It seems to work fine, especially when using different draw methods (no problems with "graphicstest"). I do however have problems when drawing bitmaps from the SD card. Sometimes it works for a longer period of time, sometimes for a short, sometimes not at all. It seems to crash, and I cant really find any pattern. The screen will eventually just "go white", with no errors in serial output. I am using the "spitftbitmap" example, and it works as is. If I however use the loop function, and make it draw different bitmaps in succession (tried different delays), it will sooner or later "crash" (again: sometimes sooner, sometimes later). (I've tried with the original purple.bmp and others).
Sometimes, the card won't initialize either, and I have to pull power, and it will "work" again.
Short video (30s) demonstrating the problem: https://www.youtube.com/watch?v=1fjz2hoj3TQ
I have tried three different SDHC-cards: (1) SanDisk Ultra 32GB class 10, (2) Sandisk 4GB class 2, (3) no-name 4GB class 4
Problems with 2.2" 18-bit TFT ILI9340 - crashes randomly - f
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- petterhj
- Posts: 4
- Joined: Sat May 09, 2015 9:09 am
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Problems with 2.2" 18-bit TFT ILI9340 - crashes randomly
Looks like an SRAM problem. Can you post your sketch?
- petterhj
- Posts: 4
- Joined: Sat May 09, 2015 9:09 am
Re: Problems with 2.2" 18-bit TFT ILI9340 - crashes randomly
This is one of the sketches I have been using while testing:
Code: Select all
/***************************************************
This is based on the Bitmap drawing example for the Adafruit ILI9341 Breakout and Shield
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <MemoryFree.h>
#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 SD_CS 4
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup(void) {
Serial.begin(9600);
Serial.println(freeMemory()); // PRINTS "1018"
tft.begin();
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS)) {
Serial.println("failed!");
}
Serial.println("OK!");
tft.fillScreen(ILI9341_BLACK);
}
void homecare(bool on) {
tft.setRotation(135);
if (on == true) {
bmpDraw("grn.bmp", 77, 0);
} else {
tft.fillRect(77, 0, 166, 41, ILI9341_BLACK);
}
}
void snap(bool on) {
tft.setRotation(45);
if (on == true) {
bmpDraw("ylw.bmp", 77, 0);
bmpDraw("cat.bmp", 80, 41);
} else {
tft.fillRect(77, 0, 166, 41, ILI9341_BLACK);
bmpDraw("fb.bmp", 80, 41);
}
}
void menu(bool on) {
tft.setRotation(90);
if (on == true) {
bmpDraw("red.bmp", 37, 40);
} else {
tft.fillRect(37, 40, 166, 41, ILI9341_BLACK);
}
}
void activity(bool on) {
tft.setRotation(0);
if (on == true) {
bmpDraw("blu.bmp", 37, 40);
} else {
tft.fillRect(37, 40, 166, 41, ILI9341_BLACK);
}
}
void loop() {
Serial.println(freeMemory()); // PRINTS "1018"
// ON
delay(8000);
snap(true);
delay(1000);
homecare(true);
delay(1000);
menu(true);
delay(1000);
activity(true);
// OFF
delay(8000);
snap(false);
delay(1000);
homecare(false);
delay(1000);
menu(false);
delay(1000);
activity(false);
Serial.println(freeMemory()); // PRINTS "1018"
}
// 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;
}
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Problems with 2.2" 18-bit TFT ILI9340 - crashes randomly
Wow. I don't see anything wrong with that. freeMemory always prints out 1018 from the loop function? It never changes?
One thing - the setRotation function only takes arguments of 0, 1, 2 or 3. It doesn't take degrees a an argument:
https://learn.adafruit.com/adafruit-gfx ... he-display
One thing - the setRotation function only takes arguments of 0, 1, 2 or 3. It doesn't take degrees a an argument:
https://learn.adafruit.com/adafruit-gfx ... he-display
- petterhj
- Posts: 4
- Joined: Sat May 09, 2015 9:09 am
Re: Problems with 2.2" 18-bit TFT ILI9340 - crashes randomly
Thats right, any call to freeMemory prints 1018 in this sketch. I don't get why it does not work. Yesterday it was working for a really long time, but now it failed on the first bitmap. Resetting the Arduino now just results in a white screen (won't even respond to fillScreen()). According to the serial output, it initializes the SD card correctly, and is telling me that it loads and draws the bitmaps without any errors. The screen is now just white and won't draw anything. It might work for a time again after a while. I've tried taking out the SD card, reinsert it, pulling power, reupload the sketch. Sometimes it works, but I just can't find any pattern.adafruit_support_rick wrote:Wow. I don't see anything wrong with that. freeMemory always prints out 1018 from the loop function? It never changes?
Oh, right. I changed it (altough it didn't make any difference crash wise) :)adafruit_support_rick wrote:One thing - the setRotation function only takes arguments of 0, 1, 2 or 3. It doesn't take degrees a an argument:
https://learn.adafruit.com/adafruit-gfx ... he-display
- petterhj
- Posts: 4
- Joined: Sat May 09, 2015 9:09 am
Re: Problems with 2.2" 18-bit TFT ILI9340 - crashes randomly
I have now also tried using an external microSD reader breakout. Same results, unfortunately.
- adafruit_support_rick
- Posts: 35092
- Joined: Tue Mar 15, 2011 11:42 am
Re: Problems with 2.2" 18-bit TFT ILI9340 - crashes randomly
Ouch! That was my next suggestion. I'm kind of stumped at this point. I'll see if the library author has any ideas.petterhj wrote:I have now also tried using an external microSD reader breakout. Same results, unfortunately.
Please be positive and constructive with your questions and comments.