I got small datalogger in my project. But I have problem with millis() function. While usinge Serial Print it works fine, but when I want save my measurments on sd card I see only forst time log and later arduino lefts only free space. What Can I do.
Yours,
Elav
PS: Now I see that funcion pronts time sometimes but mainly I see free space
I do not think that the tab after the temp6 field is useful, and I would change the code to put the new line with the last datalog.print statement. See if this arrangement gets consistent printing of the millis() field.
void loop() {
digitalWrite (LED, HIGH);
czas = millis();
SPI.end();
pinMode(SO,INPUT);
pinMode(myCLK,OUTPUT);
double temp1 = termopara1.readThermocouple(CELSIUS);
double temp2 = termopara2.readThermocouple(CELSIUS);
double temp3 = termopara3.readThermocouple(CELSIUS);
double temp4 = termopara4.readThermocouple(CELSIUS);
double temp5 = termopara5.readThermocouple(CELSIUS);
double temp6 = termopara6.readThermocouple(CELSIUS);
SPI.begin();
datalog = SD.open("datalog.txt", FILE_WRITE);
if (datalog) {
datalog.print(czas);
datalog.print("\t");
if (temp1==10000) {
datalog.print("ERR");
datalog.print("\t");
} else {
datalog.print(temp1);
datalog.print("\t");
}
if (temp2==10000) {
datalog.print("ERR");
datalog.print("\t");
} else {
datalog.print(temp2);
datalog.print("\t");
}
if (temp3==10000) {
datalog.print("ERR");
datalog.print("\t");
} else {
datalog.print(temp3);
datalog.print("\t");
}
if (temp4==10000) {
datalog.print("ERR");
datalog.print("\t");
} else {
datalog.print(temp4);
datalog.print("\t");
}
if (temp5==10000) {
datalog.print("ERR");
datalog.print("\t");
} else {
datalog.print(temp5);
datalog.print("\t");
}
if (temp6==10000) {
datalog.println("ERR");//add new line and remove last tab
//datalog.print("\t");
} else {
datalog.println(temp6);//add new line and remove last tab
//datalog.print("\t");
}
//datalog.println();
}
else {
Serial.println("Nie mozna otworzyc pliku datalog.txt");
}
datalog.close();
digitalWrite(sdPIN, LOW);
digitalWrite (LED, LOW);
delay (40);
}
EDIT: I checked my code without SPI.end, begin, etc. And in that case my issue doesnt exists. But I have to use it, any ideas? Some delays or something?
EDIT2: Now I'm 100% sure that it's problem of SPI.end and SPI.begin, sometimes datalogging suspend almost at start
Why do you drive sdPIN LOW after datalog.close()? sdPIN should be HIGH to 'de-select' the SDcard. with it low, manipulations of the SCK, MOSI while sdPin is low will 'confuse' the SDcard.