RTC de datalogging shield con ds1307 y arduino con ch340

Hola, tengo problemas al querer poner en hora el rtc a la hora exacta de mi pc, tengo la duda de que tenga que ver que el arduino sea con ch340, ya que en el shield, probé si se podía escribir en la sd y funcionó. mi unico problema es el rtc que por medio del código no se quiere poner en hora exacta.. por favor podrían colaborarme?

esto es o que me sale en el monitor serial luego del codigo

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"



RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {



  Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2017, 6, 7, 11, 34, 0));
  }
}

void loop () {
    DateTime now = rtc.now();
    
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
    
    Serial.print(" since midnight 1/1/1970 = ");
    Serial.print(now.unixtime());
    Serial.print("s = ");
    Serial.print(now.unixtime() / 86400L);
    Serial.println("d");
    
    // calculate a date which is 7 days and 30 seconds into the future
    DateTime future (now + TimeSpan(7,12,30,6));
    
    Serial.print(" now + 7d + 30s: ");
    Serial.print(future.year(), DEC);
    Serial.print('/');
    Serial.print(future.month(), DEC);
    Serial.print('/');
    Serial.print(future.day(), DEC);
    Serial.print(' ');
    Serial.print(future.hour(), DEC);
    Serial.print(':');
    Serial.print(future.minute(), DEC);
    Serial.print(':');
    Serial.print(future.second(), DEC);
    Serial.println();
    
    Serial.println();
    delay(3000);
}

// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

Parece que el constructor de DateTime no está realmente programado para recibir punteros de la memoria flash; de ahí que la fecha inicial sea 165/165/2165 a las 165:165:85. Prueba sin F() a ver qué tal.

Si el reloj no camina, por algo es que la condición if (!rtc.isrunning()) se cumplió...

probé sin las F's y aún nada amigo...

La hora exacta no se pone con
sketch was compiled

rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

Ese es el momento de la compilación que estará mas o menos próximo.
La hora exacta la puedes ingresar con la rutina Serial para actualizar la hora.

// Librerias que uso en mi caso 
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>

// solo agrega esto en el loop
if (Serial.available()>0 ) {
    processSerialCommand();
  }


void processSerialCommand() {
  char c = Serial.read(); 

  switch(c) {
    case 'T':
      // Command to set RTC time and update DriftInfo.DriftStart in the RTC battery back memory
      // Command format: TYYMMDDHHMMSS
      // Example: 2012 Oct 21 1:23pm is T121021132300
            
      delay(100); // Wait for all data to arrive
      Serial.println("Procesando entrada THHMMSSDDMMYY");
      if (Serial.available() >= 13 ){  // process only if all expected data is available
          tmElements_t tme;
          time_t newTime;
          Serial.println("Estoy dentro");
          // Parse incomming 12 ASCII charaters into time_t
          // no error checking for numeric values in YYMDDHHMMSS fields, so be carefull!
          c = Serial.read(); tme.Hour = c - '0';
          c = Serial.read(); tme.Hour = 10*tme.Hour; tme.Hour += c-'0';
          c = Serial.read(); tme.Minute = c - '0';
          c = Serial.read(); tme.Minute = 10*tme.Minute; tme.Minute += c-'0';
          c = Serial.read(); tme.Second = c - '0';
          c = Serial.read(); tme.Second = 10*tme.Second; tme.Second += c-'0';
          c = Serial.read(); tme.Day = c - '0';
          c = Serial.read(); tme.Day = 10*tme.Day; tme.Day += c-'0';
          c = Serial.read(); tme.Month = c - '0';
          c = Serial.read(); tme.Month = 10*tme.Month; tme.Month += c-'0';
          c = Serial.read(); tme.Year = c - '0';
          c = Serial.read(); tme.Year = 10*tme.Year; tme.Year += c-'0'; tme.Year += 30;
          

          Serial.print("RTC Set to: "); 
          //SerialDisplayDateTime(newTime);


          newTime = makeTime(tme);
          RTC.set(newTime);   // set the RTC and the system time to the received value
          setTime(newTime);
/*
        tmDriftInfo diUpdate = RTC.read_DriftInfo();  // update DriftInfo in RTC
        diUpdate.DriftStart = newTime;
        RTC.write_DriftInfo(diUpdate);

        */
        char buf[30];
        sprintf(buf,"Hora %02d:%02d:%02d %02d/%02d/%02d", hour(newTime), minute(newTime), second(newTime), day(newTime), month(newTime), year(newTime));
        Serial.println(buf);
      }
      break;
    /*case 'I':
      // read and display DriftInfo from RTC memory
      tmDriftInfo diRead = RTC.read_DriftInfo();
      if (diRead.DriftStart == 0 | diRead.DriftDays == 0 | diRead.DriftSeconds == 0) {
        Serial.println("DriftInfo not set yet!");
        break;
      }
      Serial.println("*** DriftInfo Read from RTC Memory ***");
      Serial.print("DriftStart   : ");
      SerialDisplayDateTime(diRead.DriftStart); Serial.println();
      Serial.print("DriftDays    : ");
      Serial.println(diRead.DriftDays);
      Serial.print("DriftSeconds : ");
      Serial.println(diRead.DriftSeconds);
      Serial.print("Day(s) since drift start: ");
      Serial.println(float(now()-diRead.DriftStart)/float(SECS_PER_DAY));
      long tmp = now() - diRead.DriftStart;
      tmp *= diRead.DriftSeconds;
      Serial.print("Your RTC has Drifted(seconds): ");
      Serial.println(float(tmp)/float(SECS_PER_DAY * diRead.DriftDays));
      break;
*/
  }
  while (Serial.available()){ 
        Serial.read(); } // clear serial buffer
}

Si te da errores ve agregando la variables correspondientes

hola surbyte,

que partes de mi código debo omitir para combinarlo con tu sugerencia?? para poder armarlo ya correctamente y dejarlo bien montado, si por favor puedes colaborarme

Ya te puse mi solución serial, ahora trabaja un poco tu con el código del que dispones. Yo no uso esa librería.

MI librería es esta DS1307RTC y el ejemplo esta disponible al bajarla.

/*
* TimeRTCSet.pde
* example code illustrating Time library with Real Time Clock.
*
* RTC clock is set in response to serial port time message 
* A Processing example sketch to set the time is inclided in the download
*/

#include <Time.h>  
#include <Wire.h>  
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t


void setup()  {
  Serial.begin(9600);
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet) 
     Serial.println("Unable to sync with the RTC");
  else
     Serial.println("RTC has set the system time");      
}

void loop()
{
  if(Serial.available())
  {
     time_t t = processSyncMessage();
     if(t >0)
     {
        RTC.set(t);   // set the RTC and the system time to the received value
        setTime(t);          
     }
  }
   digitalClockDisplay();  
   delay(1000);
}

void digitalClockDisplay(){
  // digital clock display of the time
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(month());
  Serial.print(" ");
  Serial.print(year()); 
  Serial.println(); 
}

void printDigits(int digits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

/*  code to process time sync messages from the serial port   */
#define TIME_MSG_LEN  11   // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER  'T'   // Header tag for serial time sync message

time_t processSyncMessage() {
  // return the time if a valid sync message is received on the serial port.
  while(Serial.available() >=  TIME_MSG_LEN ){  // time message consists of a header and ten ascii digits
    char c = Serial.read() ; 
    Serial.print(c);  
    if( c == TIME_HEADER ) {       
      time_t pctime = 0;
      for(int i=0; i < TIME_MSG_LEN -1; i++){   
        c = Serial.read();          
        if( c >= '0' && c <= '9'){   
          pctime = (10 * pctime) + (c - '0') ; // convert digits to a number    
        }
      }   
      return pctime; 
    }  
  }
  return 0;
}

Aca esta en formato de tiempo UNIX.
Mi rutina esta en formato normal.