Hello everyone,
I'm trying to add an SD Card module to my project.
All the settings and writing on the card succeeded and everything worked properly, my problem after about an hour or so I get an error message that the file could not be opened.
From a search I did on the internet, I realized that using String has a lot of memory
So what's the solution?
Post your code.
void sd_card(){
DateTime now = rtc.now();
char buf2[] = "DD/MM/YY,hh:mm:ss";
int Gas_sensor = Gen_air_quality();
float RTC_temp = rtc.getTemperature();
float dht_temp = dht.readTemperature();
float lm75a_Temp = lm75a.getTemperature();
float Calc_temp = Gen_air_temp();
float Gen_volt = Gen_batt_state();
String dataString = String(now.toString(buf2)) + ", " + String(Gas_sensor) + ", " + String(RTC_temp) + ", " + String(dht_temp)+ ", "
- String(lm75a_Temp) + ", " + String(Calc_temp) + ", " + String(Gen_volt);
File logFile = SD.open("LOG.csv", FILE_WRITE);
if (logFile) {
logFile.print(dataString);
delay(100);
logFile.close();
}
else {
Serial.println(F("Error opening Log File"));
//General_error_alarm();
lcd.clear();
lcd.setCursor(4, 1);
lcd.print(F("Error Opening"));
lcd.setCursor(6, 2);
lcd.print(F("Log File !"));
delay(5000);
lcd.clear();
}
delay(2000);
}