I recently purchased an Arduino LCD TFT Screen http://arduino.cc/en/Main/GTFT (from Robot Mesh), and I have been having trouble getting it to read from the SD card slot. Strangely enough it works some times, and other times it fails to find the SD card or to find the images on it. When messing around with the example files for loading images (Examples > TFT > Arduino > TFTBitmapLogo) there doesn't seem to be a problem finding and loaded the image every time I reset the arduino. However, running my own project with the same image does not seem to be consistent. Below is my code:
#include <SPI.h>
#include <SD.h>
#include <TFT.h>
#define sd 4
#define lcd 10
#define dc 9
#define rst 8
TFT tfts = TFT(10, 9, 8);
PImage logo;
void setup(){
tfts.begin();
Serial.begin(9600);
while(!Serial){
tfts.background(10, 151, 156);
}
tfts.background(0, 0, 0);
tfts.stroke(0, 255, 0);
Serial.println("Initializing...");
tfts.print("SD CARD STATUS: ");
if(!SD.begin(sd)){
tfts.stroke(255, 0, 0);
tfts.println("Failed!");
tfts.println("Reboot with SD");
Serial.println("Missing SD card/ SD setup could be incorrect");
return;
}
Serial.println("Initialization success");
tfts.println("OK!");
tfts.begin();
/*for(int i = 0; i < 255; i += 51){
screen.background(i, i, i);
}*/
logo = tfts.loadImage("al.bmp");
if(!logo.isValid()){
tfts.background(0, 0, 0);
tfts.stroke(255, 0, 0);
tfts.text("x", (tfts.width()/2) - 1, (tfts.height()/2) - 1);
Serial.println("SD card may lack proper files, will continue");
delay(3000);
return;
}
tfts.background(255, 255, 255);
tfts.image(logo, tfts.width()/2 - logo.width()/2, tfts.height()/2 - logo.height()/2);
Serial.println("Diagnostic success");
delay(3000);
tfts.begin();
}
PImage background;
void loop(){
background = tfts.loadImage("b.png");
if(!background.isValid()){
tfts.background(0, 0, 0);
tfts.stroke(255, 0, 0);
tfts.println("Missing files!");
Serial.println("SD card missing proper files!");
}
tfts.image(background, 0, 0);
}
Thank you in advance for any help provided!