Here is a stripped down version that makes a new file every day.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <PCD8544.h> // Nokia 5110
#include "Wire.h"
#include <SD.h>
#include <SPI.h> // SD
#define DS1307_ADDRESS 0x68
char filename[] = "00000000.CSV";
File myFile;
char dumpName[] = "00000000.CSV";
File dumpFile;
static PCD8544 lcd;
// Green group Dee Why (red or amber LED shields)
byte InThermo[8] = {0x28, 0x69, 0xC2, 0xB0, 0x03, 0x00, 0x00, 0x9F };
byte OutThermo[8] = {0x28, 0x7A, 0x8B, 0xC0, 0x03, 0x00, 0x00, 0x2F};
byte DrainThermo[8] = {0x28, 0x54, 0xF7, 0x2D, 0x04, 0x00, 0x00, 0x68};
#define ONE_WIRE_BUS 3
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
byte second, minute, hour, weekDay, day, month, year;
int k=0;
const int chipSelect = 4;
float tempC, InTemp, OutTemp, DrainTemp, diff;
// Define the strings for our datastream IDs
char sensorId0[] = "InThermo";
char sensorId1[] = "OutThermo";
char sensorId2[] = "DrainThermo";
char strIn[8]; // export to BT Graphic
char strOut[8]; // ditto
char strDrain[8];// ditto
char strdiff[8]; // ditto
char charBuf [13]; // assemble read file name
String readString;
String stringOne, stringTwo, stringThree, stringFour;
String stringFive, stringSix;
//_________________________________________
void setup() {
Serial3.begin(115200);
lcd.begin(84, 48);
// Register the custom symbols...
lcd.createChar(DEGREES_CHAR, degrees_glyph);
lcd.createChar(SLASH_CHAR, slash_glyph);
pinMode(0, INPUT_PULLUP); // just a precaution for bluetooth
Serial.begin(115200);
delay(300);//Wait for newly restarted system to stabilize
lcd.setCursor (0,0);
lcd.println("Init SD CARD");
// make sure that the default chip select pin 53 is set to
// output, even if you don't use it:
pinMode(53, OUTPUT);//MEGA
myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
delay(2000);
GetClock();
getFileName();
lcd.setCursor(0,3);
lcd.println(filename);
delay(2000);
lcd.clear();
//Sequence for bluetooth
// "Evalue1,value2,value3\n"
//so insert three variable between four strings,E,,\n two are the same twice,
//to make a fourth string
stringOne = "E";
stringTwo = ",";
stringThree = "\n";
running();
}
//________________________________________________________________
void loop() {
GetClock();
if (today != day)
{
today = day;
getFileName();
}
while (available())
{
delay(3);
char c = read();
readString += c;
}// end while
if (readString.length() >0)
{
getDump();
readString="";
} // end if
//get the values from the DS8B20's
sensors.requestTemperatures();
InTemp = sensorValue(InThermo);
OutTemp = sensorValue(OutThermo);
DrainTemp = sensorValue(DrainThermo);
diff = OutTemp - InTemp;
dtostrf(InTemp,4, 2, strIn);
dtostrf(OutTemp,4, 2, strOut);
dtostrf(diff,4, 2, strdiff);
stringFour = stringOne + strIn + stringTwo + strOut + stringTwo + strdiff + stringThree;
Serial3.println(stringFour);
(print temps and time to lcd)
k=k+1;
if (k>9 )
{
myFile.print(hour);
myFile.print(":");
myFile.print(minute);
myFile.print(":");
myFile.print(second);
myFile.print(",");
myFile.print(InTemp);
myFile.print(",");
myFile.print(OutTemp);
myFile.print(",");
myFile.print(DrainTemp);
myFile.print(",");
myFile.println(diff);
k=0;
}
delay(850);
} // loop ends here
//sensorValue function
float sensorValue (byte deviceAddress[])
{
tempC = sensors.getTempC (deviceAddress);
return tempC;
}
byte bcdToDec(byte val) {
// Convert binary coded decimal to normal decimal bers
return ( (val/16*10) + (val%16) );
}
void running(){
(lcd print stuff)
}
void getFileName(){
myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
sprintf(filename, "%02d%02d%02d.csv", year, month, day);
myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
}
void GetClock(){
// Reset the register pointer
Wire.beginTransmission(DS1307_ADDRESS);
byte zero = 0x00;
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
weekDay = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
day = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
void getDump() {
stringSix = "2015" + readString + ".csv";
stringSix.toCharArray(charBuf, 15);
myFile.close();//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>CLOSE
File dumpFile = SD.open(charBuf);
if (dumpFile)
{
lcd.clear();
lcd.setCursor (0,1);
lcd.println("DUMP FROM ");
lcd.setCursor (0,2);
lcd.println(charBuf);
while (dumpFile.available())
{
write(dumpFile.read());
}
dumpFile.close();
myFile = SD.open(filename, FILE_WRITE);//<<<<<<<<<<<<< OPEN
lcd.clear();
running();
}
else {
println("error opening file");
}
}