Hi all!
I am having quite strange problem with my current project.
I am using Arduino Mega 2560r3 with RTC (I2C), SD (SPI) and B/W dot matrix lcd (UART).
Basic operation of my project - read 8 analog samples, create average and write it into SD with timestamp.
Finally connected SD module with compatible SD (worst experience ever - tried 8 cards and only the last one worked!!!). Checked it with "CardInfo" sketch.
THE PROBLEM: My program reads current date from RTC and creates string which is used as filename. But program only writes s file, but nothing into it! It is still 0 bytes... If I change filename, file is written, but again - empty.
Once I have done "something" and everything worked correctly - had data in files. Later againt "something" happened and now I have again empty files
I thought about some bad connections (something like WR - write protection), but SD doesnt have anything like this.
Could it be software related? I am suspicious about function "sprintf()" that caused some problems early...
Thanks for any ideas!
I may post full code, but dont want to paste all (over 300 lines and still growing - not finished), so here is part of code that writes into SD:
//filename
sprintf (DateField, "20%02u%02u%02u.CSV",year,date,month); // http://forum.arduino.cc/index.php?PHPSESSID=go7j8f5fpvr23ooqtbr23lnmd0&topic=106697.msg800508#msg800508
mydisp.setPrintPos(0, 5);
mydisp.print("FILE: ");
mydisp.print(DateField);
mydisp.print(" ");
//ukladani do souboru
String dataString = "";
File dataFile = SD.open(DateField, FILE_WRITE);
dataString += String(mVvalueInt);
// if the file is available, write to it:
if (dataFile) {
SDerror=false;
if (FirstStart==true) {
dataFile.println("SYSTEM ONLINE");
//dataFile.println("FILENAME - TIME - DOSE (nSv/h)");
}
dataFile.print(DateField);
dataFile.print(" - ");
sprintf (TimeField, "%02u:%02u:%02u",hour,minute,second);
dataFile.print(TimeField);
dataFile.print(" - ");
dataFile.print(dataString);
dataFile.println("");
dataFile.close();
}
// if the file isn't open, pop up an error:
else {
SDerror=true;
}