Hi, I´m newbie in this forum and relatively newbie in Arduino Platform…But I made other projects with this platform successfuly. In may I finished my studies of “Graduate of Marine Engineering” and simultaneously of “Naval Technical Engineering: Specialized in propulsion and ship services”. In this second studies, I need to make a final studies project and I decided to make a datalogger of temperatures and other conditions of the engine room, saving this parameters in an SD card and being viewed in an LCD. Now I have a part of the components like an SD card writer-reader or DS18B20 temperature sensor. I tried a lot of codes and I make a lot of modifications and I always have the same problem: The refresh time isn´t exact…Each minute it delays about one second. I bought a DS1307 RTC too for display time and date, but I dont know when it will arrive…It will help me to have precission delays? or should I do any modification in my actual code without DS1307?
In both codes I have a txt file (COMMANDS.txt) with the refresh_rate in the first line.
This is one code:
/Desarrollado a partir de Datalogger de la libreria SD y del script de 18B20/
#include <SD.h>
#include <OneWire.h>
#include <DallasTemperature.h>long lastReadTime = 0;
//Define puerto 18B20s
#define ONE_WIRE_BUS 11
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);//SPI SD Card Pins
//MOSI = Pin 11
//MISO = Pin 12
//SCLK = PIN 13
int CS_pin = 53;
int pow_pin = 8;float refresh_rate = 0.0; //Dataloger Refresh Rate
void setup(void)
{
Serial.begin(9600);
sensors.begin();//Inicializa sensores 18B20//--------------------------------------------------------------TARJETA---------------------------------------------------
Serial.println(“Inicializando tarjeta”);pinMode(CS_pin, OUTPUT);//Pin CS es la salida
pinMode(pow_pin, OUTPUT); //De donde toma tension
digitalWrite(pow_pin, HIGH);//La debe tomar altaif (!SD.begin(CS_pin)) //inicializa tarjeta SD
{
Serial.println(“Fallo de tarjeta SD”);
return;
}
Serial.println(“Tarjeta lista”);//Lee informacion de configuracion
File commandFile = SD.open(“COMMANDS.txt”);
if (commandFile)
{
Serial.println(“Leyendo configuracion”);float decade = pow(10, (commandFile.available() - 1));
while(commandFile.available())
{
float temp = (commandFile.read() - ‘0’);
refresh_rate = temp*decade+refresh_rate;
decade = decade/10;
}
Serial.print("Tiempo refresco = ");
Serial.print(refresh_rate);
Serial.println(“ms”);
commandFile.close();
}
else
{
Serial.println(“No se puede leer configuracion”);
return;
}//Write Log File Header
File logFile = SD.open(“LOG.csv”, FILE_WRITE);
if (logFile)
{
logFile.println(", , , ,"); //Dejar linea en blanco si no hay datos previos
String header = “ID, Light, Temp, IR1, IR2”;
logFile.println(header);
logFile.close();
Serial.println(header);
}
else
{
Serial.println(“No se puede abrir LOG”);
}}
//--------------------------------------------------------------FIN TARJETA-------------------------------------------------void loop()
{
sensors.requestTemperatures(); // Obtener temperaturas DS18B20long currentTime = millis();
if (currentTime > lastReadTime + refresh_rate) {
File logFile = SD.open(“LOG.csv”, FILE_WRITE);
logFile.println(sensors.getTempCByIndex(0));
logFile.close();
Serial.println(sensors.getTempCByIndex(0));
lastReadTime = millis();}
}
Thanks a lot for your time