Hello guys,
I posted half of my problem (the display flickers) at this forum post. I put a 10k pullup resistor to the CS leg of the SD card which seems to make it flicked a bit less, however...
I have a function, which reads a file and prints it to the LCD:
bool Show1(const char* FileName) {
Serial.println("Opening file...");
File myFile = SD.open(FileName);
if (myFile) {
uint8_t bmp[288];
int i;
uint8_t w;
uint8_t h;
for (i=0; i<sizeof(bmp); i++) { bmp[i] = 0; }
myFile.read((uint8_t *)&w, sizeof(w));
myFile.read((uint8_t *)&h, sizeof(h));
Serial.println("Dimensions: "+String(w)+"x"+String(h));
i = 0;
while (myFile.available()) {
myFile.read((uint8_t *)&bmp[i], sizeof(bmp[i]));
Serial.print(String(bmp[i])+", ");
if (i % 10 == 9) { Serial.println(); }
i++;
}
myFile.close();
lcd.clear(0);
lcd.writeBitmap(bmp, 0, 0, w, h);
lcd.renderAll();
Serial.println();
return true;
} else {
Serial.println("Failed to open file!");
return false;
}
}
I call this function three times:
if (!Show1("bmp1.txt")) {
Serial.println("Failed to show file");
}
delay(10000);
if (!Show1("bmp2.txt")) {
Serial.println("Failed to show file");
}
delay(10000);
if (!Show1("bmp3.txt")) {
Serial.println("Failed to show file");
}
delay(10000);
The first and the last picture shows, for the middle the function dies at this line:
File myFile = SD.open(FileName);
Now the strange thing. If I insert a dummy call before bmp2.txt, let's say fake.txt... as the file does not exist, fake.txt will fail but bmp2.txt will show up! The next one will fail though... which makes me think something should be wrong as I MUST have a failed call before each successful one, otherwise it won't work.
Now why it is strange? In the moment I remove the LCD display (physically or just the display part from the function) it works fine and dumps files on the serial console...
I'm going crazy here. Anyone has any ideas?