Setting a DS3231 RTC via Serial

I am developing a Data logger with the Nano board and 4 Channel AI module from Circutar. Nanoshield

For time reference I am using a DS3231 module. Since code space is a bit tight I am unable to add code for setting the RTC time & date using three push buttons.

But the whole unit has access to Serial port which I am using for downloading the CSV file from the SD card. I think there is a method to use the Time library and get teh PC time. Unable to lay my hands on that link ….

Also is there any other method to do this ?

search term: Arduino set RTC compiler time

one of many threads on this subject

Ardubit:
Since code space is a bit tight ..............Also is there any other method to do this ?

You might consider whether you need to do this at all. DS3231 is pretty accurate - to a point that may be beyond what your real needs are.

@Geek Emeritus

thanks ... exactly the term i was looking for. Will take on from here.

Nick_Pyner:
You might consider whether you need to do this at all. DS3231 is pretty accurate - to a point that may be beyond what your real needs are.

:wink: Yes yes … the accuracy that the DS3231 delivers is pretty good. My requirement is only for the first time and later to correct any drift after long time . So even though its once in a bluemoon, i need to provide the facility to the user.

Searched and located a sample code that could do what I want …

But when I try to compile for a Nano, i get an error ‘DS3231 clock’ redeclared as different kind of symbol’

If try renaming clock to myClock, then I get a error " setSyncProvider() not defined in this scope"

Whats happening ? ( I am sure C++ experts will be tired with this… sorry)

#include <Wire.h>         //http://arduino.cc/en/Reference/Wire (included with Arduino IDE)
#include <DS3231.h>       //Jarzebski DS3231

#include <Time.h>         //http://www.arduino.cc/playground/Code/Time  
DS3231 clock;
RTCDateTime dt;

uint32_t syncProvider()
{
  dt = clock.getDateTime();
  return dt.unixtime;
}

void setup(void)
{
  Serial.begin(9600);
  Wire.begin();
  clock.begin();
  setSyncProvider(syncProvider);   // 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(void)
{
  timeDateDisplay();
  delay(1000);
}

void timeDateDisplay(void)
{
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(' ');
  Serial.print(month());
  Serial.print("/");
  Serial.print(day());
  Serial.print("/");
  Serial.print(year());
  Serial.println();
  Serial.print("Unix Time ");
  Serial.println(now());
  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);
}