RTC se adelanta [SECUESTRADO]

Hola a todos
Antes que nada perdon por revivir este post pero necesito urgente solucionar este problema del RTC 3231 N (Supuestamente posee sensor de temperatura propio para correjir la oscilacion del cristal)
Tengo armado un datalogger con una placa mega 2560 para registrar temperatura y humerdad del sustrato de macetas de jazmin, pero cuando dejo registrando los datos observo en el registro 2 segundos adelantado cada 5 minuto, Lo gracioso es que si leo la hs del rtc al energizarlo este muestra la hs correcta, el problema lo observo cuando inicia el proceso de registro, pero al apagarlo y volver a encenderlo luego de unas hs o dias el reloj RTC

dejo un fragmento del registro TXT. de la SD

10, 5/8/2018  4:2:5, 80.80, 7.50, 123
11, 5/8/2018  4:3:5, 83.60, 7.30, 122
12, 5/8/2018  4:4:5, 85.10, 7.30, 126
13, 5/8/2018  4:5:5, 85.80, 7.20, 127
14, 5/8/2018  4:6:5, 85.70, 7.10, 125
15, 5/8/2018  4:7:7, 87.30, 7.10, 126
16, 5/8/2018  4:8:7, 87.60, 7.00, 127
17, 5/8/2018  4:9:7, 90.50, 7.10, 127
18, 5/8/2018  4:10:7, 91.40, 7.00, 128
19, 5/8/2018  4:11:[color=red]7[/color], 91.10, 7.00, 130
20, 5/8/2018  4:12:[color=blue]10[/color], 88.70, 6.90, 127
21, 5/8/2018  4:13:10, 91.60, 6.90, 127
22, 5/8/2018  4:14:10, 91.80, 6.90, 129
23, 5/8/2018  4:15:10, 91.70, 7.00, 131
24, 5/8/2018  4:16:[color=red]10[/color], 90.30, 6.80, 129
25, 5/8/2018  4:17:[color=blue]12[/color], 89.80, 6.90, 132
26, 5/8/2018  4:18:12, 93.00, 6.90, 129
27, 5/8/2018  4:19:12, 91.50, 6.80, 130

En color rojo marco el valor previo al salta y en azul post salto

Dejo el sketch que arme (rejuntando info) (aclaro que soy Ing. Agr. con CERO formacion en electronica y programacion

Desde ya muchas gracias a todos por su ayuda

#include <Time.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>
#include <LiquidCrystal.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <DHT.h>

//SENSORES DE DHT22
#define DHT1PIN 23
#define DHT1TYPE DHT22
DHT dht(DHT1PIN, DHT1TYPE);

#define SDFILE_PIN_CS 53

LiquidCrystal lcd(12, 11, 10, 9, 8, 7);

char fecha[20];
const int chipSelect = 53;
const int fuente =  2;// ESTABA EN 6
const int sensorPin = 0;

int cuenta = 1;
int id;
const int fuentePin =  12;      // the number of the LED pin

File sdFile;

void setup() {

  Wire.begin();
  Serial.begin(9600);

  // configuracion del/los pines PWM
  pinMode(12, OUTPUT);
  digitalWrite(12, LOW);


  lcd.begin(20, 4);
  while (!Serial) ;
  Serial.println("INICIANDO DATALOGGER...");

  pinMode(53, OUTPUT); // el pinde la sd es 53
  pinMode(fuente, OUTPUT);
  dht.begin();

  if (!SD.begin(chipSelect)) {
    Serial.println("Tarjeta SD erronea,o no presente");
    return;
  }

  Serial.println("Tarjeta SD inicializada.");

  char fecha[20];
  String dataString = "";
  File sdFile = SD.open("data.txt", FILE_WRITE);
  dataString = String ("ID, FECHA, HORA,HR %, T *C, Humedad de sustrato");
  if (sdFile) {
    sdFile.println(dataString);
    sdFile.close();
    Serial.println(dataString);

    /****************************************/
    // Cargar la hora actual desde el RTC e indicar que esto suceda de forma automática durante loop()
    // Utilizamos el método RTC.get() de la libreria DS1307RTC. El RTC debe estar conectado como se
    // indica en el texto y debe tener la fecha y hora correctas
    setSyncProvider(RTC.get);
    if (timeStatus() != timeSet)
      Serial.println("Fallo de RTC");
    else
      Serial.println("Sincronizado con RTC");

    // Crear las alarmas y configurar las funciones correspondientes a cada una

    Alarm.timerRepeat (60, LeerSensores);

    
    /***************
       Alarm.timerRepeat (Period, TimerFunction);
      https://github.com/PaulStoffregen/TimeAlarms

      Descripción: Llama continuamente a la Función
      de temporizador proporcionada por el usuario
      después de transcurrido el período determinado
      en segundos.
    */
  }
}
//////////////////////////////////////////////////////
void loop() {
  //digitalClockDisplay();
  // Esperar 1 segundo y procesar las Alarmas mientras tanto...
  // El metodo Alarm.delay() procesa en el fondo las alarmas y llamara a las funciones indicadas
  Alarm.delay(1000);
  }
///////////////////////////////////////////////////////

void LeerSensores() //ACTIVAR PIN 12
{
  Serial.print("Encendiendo!!!, ");
  digitalWrite(12, HIGH);
  sensores();
  Reposo();

}

void Reposo() //DESACTIVAR PIN 12
{
  Serial.print("Apagando Luz ☺☺☺☺☺☺☺, ");
  digitalWrite(12, LOW);
}

/**
   Funciones para la impresion del reloj al monitor serial de arduino
*/


void sensores() {
  {
    float h1 = dht.readHumidity();
    float t1 = dht.readTemperature();
    //float f1 = dht.readTemperature(true);
    int humedad = analogRead(sensorPin);

    if (isnan(h1) || isnan(t1)) {
      Serial.println("Falla en la lectura del sensor DHT22");
      return;
    }
    {
      int id = cuenta++;
      Serial.print(id);
      Serial.print(", ");
      digitalClockDisplay();
      Serial.print(", ");
      Serial.print(h1);
      Serial.print("%, ");
      Serial.print(t1);
      Serial.print("*C ");
      Serial.print(", ");
      Serial.print(humedad);
      Serial.print(", ");

      lcd.setCursor(0, 0);
      lcd.print(day());
      lcd.print("/");
      lcd.print(month());
      lcd.print("/");
      lcd.print(year());
      lcd.print(" ");
      lcd.print(hour());
      lcd.print(":");
      lcd.print(minute());
      lcd.print(":");
      lcd.print(second());
      lcd.setCursor(5, 1);
      lcd.print(h1);
      lcd.setCursor(0, 1);
      lcd.print("HR =");
      lcd.setCursor(0, 2);
      lcd.print("T*C =");
      lcd.setCursor(6, 2);
      lcd.print(t1);
      lcd.setCursor(0, 3);
      lcd.print("Id: ");
      lcd.setCursor(7, 3);
      lcd.print(id);




      sdFile = SD.open("data.txt", FILE_WRITE);
      if (sdFile) {
        sdFile.print(id);
        sdFile.print(", ");
        sdFile.print(day());
        sdFile.print("/");
        sdFile.print(month());
        sdFile.print("/");
        sdFile.print(year());
        sdFile.print("  ");// si HACE falta poner una coma entre los corchetes
        sdFile.print(hour());
        sdFile.print(":");
        sdFile.print(minute());
        sdFile.print(":");
        sdFile.print(second());
        sdFile.print(", ");
        sdFile.print(h1);
        sdFile.print(", ");
        sdFile.print(t1);
        sdFile.print(", ");
        sdFile.println (humedad);
        sdFile.close();
        Serial.println("Dato guardado en SD");
      }
      else
      {
        Serial.println("ERROR: registro no guardado en Tarjeta SD");
        Serial.println();

      }
    }
  }
}
void digitalClockDisplay() {

  Serial.print(day());
  Serial.print("/");
  Serial.print(month());
  Serial.print("/");
  Serial.print(year());
  Serial.print(", ");
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(", ");
}

void printDigits(int digits) {
  Serial.print(":");
  if (digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

jczepulis: El problema lo tienes porque no estas usando el RTC para consultar los sensores cada un minuto, sino que usas el tiempo de arduino usando Alarm.timerRepeat (60, LeerSensores); en el setup y Alarm.delay(1000); en el loop.
No es el RTC que se va adelantando sino que arduino se va atrasando.

Lo que yo haría seria consultar el reloj cada segundo en el loop y cuando MinutoActual no sea igual a MinutoAnterior vaya a leer los sensores y hacer la rutina de grabar los datos en la memoria SD.

Saludos

Como bien dijiste para que revives un hilo del 2016 o de mas de 4 meses si sabes que no se debe hacer?
Lo que si debes hacer es crear un hilo propio como ahora hice con tu post y la respuesta.
Lee las normas del foro. Te las paso por privado ya que a pesar de estar en el primer post de cada sección veo que luce como invisible para la mayoría.

surbyte Gracias.

Daniel_Arg:
jczepulis: El problema lo tienes porque no estas usando el RTC para consultar los sensores cada un minuto, sino que usas el tiempo de arduino usando Alarm.timerRepeat (60, LeerSensores); en el setup y Alarm.delay(1000); en el loop.
No es el RTC que se va adelantando sino que arduino se va atrasando.

Lo que yo haría seria consultar el reloj cada segundo en el loop y cuando MinutoActual no sea igual a MinutoAnterior vaya a leer los sensores y hacer la rutina de grabar los datos en la memoria SD.

Saludos

DAniel te entiendo,
La forma en la que lo trabaje es mediante alarmas (por eso las librerias usadas y su configuracion en el Setup, al final logre leerlas a un momento fijo pero utilizando el siguiente codigo

 0 HORAS
      Alarm.alarmRepeat(0, 0, 0, LeerSensores);
      Alarm.alarmRepeat(0, 15, 0, LeerSensores);
      Alarm.alarmRepeat(0, 30, 0, LeerSensores);
      Alarm.alarmRepeat(0, 45, 0, LeerSensores);

        // 1 HORAS
      Alarm.alarmRepeat(1, 0, 0, LeerSensores);
      Alarm.alarmRepeat(1, 15, 0, LeerSensores);
      Alarm.alarmRepeat(1, 30, 0, LeerSensores);
      Alarm.alarmRepeat(1, 45, 0, LeerSensores);

        // 2 HORAS
      Alarm.alarmRepeat(2, 0, 0, LeerSensores);
      Alarm.alarmRepeat(2, 15, 0, LeerSensores);
      Alarm.alarmRepeat(2, 30, 0, LeerSensores);
      Alarm.alarmRepeat(2, 45, 0, LeerSensores);
        // 3 HORAS
      Alarm.alarmRepeat(3, 0, 0, LeerSensores);
      Alarm.alarmRepeat(3, 15, 0, LeerSensores);
      Alarm.alarmRepeat(3, 30, 0, LeerSensores);
      Alarm.alarmRepeat(3, 45, 0, LeerSensores);
        // 4 HORAS
      Alarm.alarmRepeat(4, 0, 0, LeerSensores);
      Alarm.alarmRepeat(4, 15, 0, LeerSensores);
      Alarm.alarmRepeat(4, 30, 0, LeerSensores);
      Alarm.alarmRepeat(4, 45, 0, LeerSensores);
        // 5 HORAS
      Alarm.alarmRepeat(5, 0, 0, LeerSensores);
      Alarm.alarmRepeat(5, 15, 0, LeerSensores);
      Alarm.alarmRepeat(5, 30, 0, LeerSensores);
      Alarm.alarmRepeat(5, 45, 0, LeerSensores);
        // 6 HORAS
      Alarm.alarmRepeat(6, 0, 0, LeerSensores);
      Alarm.alarmRepeat(6, 15, 0, LeerSensores);
      Alarm.alarmRepeat(6, 30, 0, LeerSensores);
      Alarm.alarmRepeat(6, 45, 0, LeerSensores);
        // 7 HORAS
      Alarm.alarmRepeat(7, 0, 0, LeerSensores);
      Alarm.alarmRepeat(7, 15, 0, LeerSensores);
      Alarm.alarmRepeat(7, 30, 0, LeerSensores);
      Alarm.alarmRepeat(7, 45, 0, LeerSensores);
        // 8 HORAS
      Alarm.alarmRepeat(8, 0, 0, LeerSensores);
      Alarm.alarmRepeat(8, 15, 0, LeerSensores);
      Alarm.alarmRepeat(8, 30, 0, LeerSensores);
      Alarm.alarmRepeat(8, 45, 0, LeerSensores);

        // 9 HORAS
      Alarm.alarmRepeat(9, 0, 0, LeerSensores);
      Alarm.alarmRepeat(9, 15, 0, LeerSensores);
      Alarm.alarmRepeat(9, 30, 0, LeerSensores);
      Alarm.alarmRepeat(9, 45, 0, LeerSensores);

        // 10 HORAS
      Alarm.alarmRepeat(10, 0, 0, LeerSensores);
      Alarm.alarmRepeat(10, 15, 0, LeerSensores);
      Alarm.alarmRepeat(10, 30, 0, LeerSensores);
      Alarm.alarmRepeat(10, 45, 0, LeerSensores);
        // 11 HORAS
      Alarm.alarmRepeat(11, 0, 0, LeerSensores);
      Alarm.alarmRepeat(11, 15, 0, LeerSensores);
      Alarm.alarmRepeat(11, 30, 0, LeerSensores);
      Alarm.alarmRepeat(11, 45, 0, LeerSensores);

        // 12 HORAS
      Alarm.alarmRepeat(12, 0, 0, LeerSensores);
      Alarm.alarmRepeat(12, 15, 0, LeerSensores);
      Alarm.alarmRepeat(12, 30, 0, LeerSensores);
      Alarm.alarmRepeat(12, 45, 0, LeerSensores);

        // 13 HORAS
      Alarm.alarmRepeat(13, 0, 0, LeerSensores);
      Alarm.alarmRepeat(13, 15, 0, LeerSensores);
      Alarm.alarmRepeat(13, 30, 0, LeerSensores);
      Alarm.alarmRepeat(13, 45, 0, LeerSensores);

        // 14 HORAS
      Alarm.alarmRepeat(14, 0, 0, LeerSensores);
      Alarm.alarmRepeat(14, 15, 0, LeerSensores);
      Alarm.alarmRepeat(14, 30, 0, LeerSensores);
      Alarm.alarmRepeat(14, 45, 0, LeerSensores);

        // 15 HORAS
      Alarm.alarmRepeat(15, 0, 0, LeerSensores);
      Alarm.alarmRepeat(15, 15, 0, LeerSensores);
      Alarm.alarmRepeat(15, 30, 0, LeerSensores);
      Alarm.alarmRepeat(15, 45, 0, LeerSensores);

        // 16 HORAS
      Alarm.alarmRepeat(16, 0, 0, LeerSensores);
      Alarm.alarmRepeat(16, 15, 0, LeerSensores);
      Alarm.alarmRepeat(16, 30, 0, LeerSensores);
      Alarm.alarmRepeat(16, 45, 0, LeerSensores);
        // 17 HORAS
      Alarm.alarmRepeat(17, 0, 0, LeerSensores);
      Alarm.alarmRepeat(17, 15, 0, LeerSensores);
      Alarm.alarmRepeat(17, 30, 0, LeerSensores);
      Alarm.alarmRepeat(17, 45, 0, LeerSensores);
        // 18 HORAS
      Alarm.alarmRepeat(18, 0, 0, LeerSensores);
      Alarm.alarmRepeat(18, 15, 0, LeerSensores);
      Alarm.alarmRepeat(18, 30, 0, LeerSensores);
      Alarm.alarmRepeat(18, 45, 0, LeerSensores);
        // 19 HORAS
      Alarm.alarmRepeat(19, 0, 0, LeerSensores);
      Alarm.alarmRepeat(19, 15, 0, LeerSensores);
      Alarm.alarmRepeat(19, 30, 0, LeerSensores);
      Alarm.alarmRepeat(19, 45, 0, LeerSensores);

        // 20 HORAS
      Alarm.alarmRepeat(20, 0, 0, LeerSensores);
      Alarm.alarmRepeat(20, 15, 0, LeerSensores);
      Alarm.alarmRepeat(20, 30, 0, LeerSensores);
      Alarm.alarmRepeat(20, 45, 0, LeerSensores);
        // 21 HORAS
      Alarm.alarmRepeat(21, 0, 0, LeerSensores);
      Alarm.alarmRepeat(21, 15, 0, LeerSensores);
      Alarm.alarmRepeat(21, 30, 0, LeerSensores);
      Alarm.alarmRepeat(21, 45, 0, LeerSensores);
       // 22 HORAS
      Alarm.alarmRepeat(22, 0, 0, LeerSensores);
      Alarm.alarmRepeat(22, 15, 0, LeerSensores);
      Alarm.alarmRepeat(22, 30, 0, LeerSensores);
      Alarm.alarmRepeat(22, 45, 0, LeerSensores);
      // 23 HORAS
      Alarm.alarmRepeat(23, 0, 0, LeerSensores);
      Alarm.alarmRepeat(23, 15, 0, LeerSensores);
      Alarm.alarmRepeat(23, 30, 0, LeerSensores);
      Alarm.alarmRepeat(23, 45, 0, LeerSensores);

de esta manera logre registros cada 15 minutos exactos, pero no es nada elegante semejante cantidad e codigo

Estas armando un logger cada 5 min y usas TimeALarm para ello?
Porque no simplemente usas millis()?

algo como

// como global
unsigend long Start;

// en el loop
if (millis() - Start > 300000UL) { 
   // loggear
   Start = millis();
}