Hello, got a engine datalogger writing stuff to csv and due to fire the arduino stopped with nothing on the card except the initial creation of the file, I was wondering how writing to sd goes since I really assumed every line was written until I close(), if not I have to recode and if yes it means the arduino stopped at the first line and not because of the fire.
void createFile(){
sprintf(folder, "20%02d/%02d-%02d", yy, dd, mo);
sprintf(file, "20%02d/%02d-%02d/%02d-%02d.CSV", yy, dd, mo, hh, mi);
SD.mkdir(folder);
myFile=SD.open(file, FILE_WRITE);
myFile.println("timestamp,egt1,egt2,egt3,egt4,egt5,egt6,engine-temp,iat,exhaust-pressure,boost,H2O-pressure,oil-pressure,fuel-pressure,volt,RPM,wheelspeed");
myFile.close();
}
void writeData() {
if ((writeSD == 1) && (logBit == 0)) {
logBit = 1;
createFile();
startTime = millis();
myFile=SD.open(file, O_CREAT | O_WRITE | O_APPEND);
}
if ((writeSD == 1) && (logBit == 1)) {
sprintf(time, "%02d:%02d:%02d.", hh, mi, ss);
String writedata = "";
writedata += time;
writedata += (millis() - startTime);
writedata += ',';
writedata += egt1;
writedata += ',';
writedata += egt2;
writedata += ',';
writedata += egt3;
writedata += ',';
writedata += egt4;
writedata += ',';
writedata += egt5;
writedata += ',';
writedata += egt6;
writedata += ',';
writedata += clt;
writedata += ',';
writedata += iat;
writedata += ',';
writedata += pressure1;
writedata += ',';
writedata += pressure2;
writedata += ',';
writedata += pressure3;
writedata += ',';
writedata += pressure4;
writedata += ',';
writedata += pressure5;
writedata += ',';
writedata += volt;
writedata += ',';
writedata += rpm1;
writedata += ',';
writedata += rpm2;
myFile.println(writedata);
}
if ((writeSD == 0) && (logBit == 1)) {
logBit = 0;
myFile.close();
}
}
void setup() {
SD.begin(SD_CS);
}
void loop() {
while (true)
{
if (myTouch.dataAvailable()) // check for touch screen events
{
myTouch.read();
x=myTouch.getX();
y=myTouch.getY();
if ((y>=315) && (y<=390) && (x>=575) && (x<=790)) // START (575, 315, 790, 390)
{
drawFrame(575, 315, 790, 390);
myGLCD.setColor(LCD_white);
myGLCD.setBackColor (LCD_black);
myGLCD.print("STOP", 650, 425);
myGLCD.setColor(LCD_red);
myGLCD.print("START", 650, 340);
myGLCD.setBackColor (LCD_blue);
writeSD = 1;
}
if ((y>=400) && (y<=475) && (x>=575) && (x<=790)) // STOP (575, 400, 790, 475)
{
drawFrame(575, 400, 790, 475);
myGLCD.setColor(LCD_red);
myGLCD.setBackColor (LCD_black);
myGLCD.print("STOP", 650, 425);
myGLCD.setColor(LCD_white);
myGLCD.print("START", 650, 340);
myGLCD.setBackColor (LCD_blue);
writeSD = 0;
}
}
time_now = millis();
readSensors(); // 2632μs
grabTime(); // 1068μs
writeData(); // 6x1732μs + 1x4584μs = 14992μs / 7 = 2142μs average
updateDisplay();
printLEDbar();
printRPM(1); // 38300μs
printEGT(1); // 19320μs
printEGT(2); // 19320μs
while(millis() < time_now + period){
}
}
}