viulian:
so I switched to the Fat16 library.
Now everything runs smooth. Screen is rock stable, no jumpiness / shearing, no random pixels, and the values are correctly written to the sdcard.
Good to know that I am not alone - at least was. Most probably I must be missing something, as none of the SD libraries I tried so far seems to work correctly.
Using a simple code, only SD reader (CS on PIN4) and the Nokia display (on PINs 8-10+SPI)
#include <SPI.h>
#include <PCD8544_SPI.h>
#include <Fat16.h>
PCD8544_SPI lcd;
SdCard card;
Fat16 file;
bool Show1(const char* FileName) {
SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
Serial.print(F("Trying to open "));
Serial.println(String(FileName));
if (file.open(FileName, O_READ)) {
int i = 0;
uint8_t bmp[300];
memset(bmp,0,sizeof(bmp));
uint8_t w = 0;
uint8_t h = 0;
int16_t n;
Serial.print(F("Read "));
Serial.print(file.read(&w, sizeof(uint8_t)));
Serial.print(F(" bytes, width is "));
Serial.println(w);
Serial.print(F("Read "));
Serial.print(file.read(&h, sizeof(uint8_t)));
Serial.print(F(" bytes, height is "));
Serial.println(h);
while (file.read(&bmp[i], sizeof(uint8_t)) > 0) {
if (i % 10 == 0) { Serial.println(); }
Serial.print(F("0x"));
Serial.print(String(bmp[i], HEX));
Serial.print(F(", "));
i++;
}
Serial.println();
Serial.print(F("Total of "));
Serial.print(i);
Serial.println(" bytes");
file.close();
SPI.endTransaction();
SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
lcd.clear();
lcd.writeBitmap(bmp, 0, 0, w, h);
SPI.endTransaction();
memset(bmp,0,sizeof(bmp));
return true;
} else {
SPI.endTransaction();
SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
lcd.clear(); // REMEMBER THIS LINE
// lcd.print(F("Error opening"));
// lcd.gotoXY(0,1);
// lcd.print(String(FileName));
SPI.endTransaction();
Serial.print(F("Error opening "));
Serial.println(String(FileName));
return false;
}
}
void setup() {
lcd.begin(false, 0xBF, 0x02, 0x13);
Serial.begin(9600);
delay(5000);
if (!card.begin(4)) {
SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
lcd.clear();
lcd.print(F("Initializing"));
lcd.gotoXY(0,1);
lcd.print(F("SD card failed"));
SPI.endTransaction();
delay(5000);
return;
}
if (!Fat16::init(&card)) {
SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
lcd.clear();
lcd.print(F("Initializing"));
lcd.gotoXY(0,1);
lcd.print(F("FAT16 failed"));
SPI.endTransaction();
delay(5000);
return;
}
}
void loop() {
Show1("bmp1.txt");
delay(2500);
Show1("bmp2.txt");
delay(2500);
Show1("Fake.txt");
delay(2500);
}
Is producing the below output:
Trying to open bmp1.txt
Read 1 bytes, width is 18
Read 1 bytes, height is 1
{correct data removed here}
Total of 18 bytes
Trying to open bmp2.txt
Read 1 bytes, width is 42
Read 1 bytes, height is 5
{correct data removed here}
Total of 210 bytes
Trying to open Fake.txt
Error opening Fake.txt
Trying to open bmp1.txt
Read -1 bytes, width is 0
Read -1 bytes, height is 0
Total of 0 bytes
Trying to open bmp2.txt
Error opening bmp2.txt
Trying to open Fake.txt
Error opening Fake.txt
Trying to open bmp1.txt
Error opening bmp1.txt
Trying to open bmp2.txt
Error opening bmp2.txt
Trying to open Fake.txt
Error opening Fake.txt
Now... if I remove the line with the comment // REMEMBER THIS LINE everything starts to work perfectly... I just must not touch the LCD if something goes wrong... but why?! 