Real Time Clock Installation Help Needed

I am working with an arduino Mega, and a DS3231 AT24C32 IIC module precision Real time clock memory module Arduino I uploaded the Time, Time Alarm, and DS1307RTC libraries to the arduino libraries folder and imported them. I hooked the Real time clock up as instructed onThis Youtube Video for convenience fast forward to mark 3:25 for layout. However, when I uploaded the example sketch Set Time that came in the library I downloaded the serial monitor says

("DS1307 Communication Error :-{")
Please check your circuitry");

Do i need to hook it up differently than the guy did in the video? The red power light on the DS1307 is coming on.

#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>

const char *monthName[12] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};

tmElements_t tm;

void setup() {
  bool parse=false;
  bool config=false;

  // get the date and time the compiler was run
  if (getDate(__DATE__) && getTime(__TIME__)) {
    parse = true;
    // and configure the RTC with this info
    if (RTC.write(tm)) {
      config = true;
    }
  }

  Serial.begin(9600);
  while (!Serial) ; // wait for Arduino Serial Monitor
  delay(200);
  if (parse && config) {
    Serial.print("DS1307 configured Time=");
    Serial.print(__TIME__);
    Serial.print(", Date=");
    Serial.println(__DATE__);
  } else if (parse) {
    Serial.println("DS1307 Communication Error :-{");
    Serial.println("Please check your circuitry");
  } else {
    Serial.print("Could not parse info from the compiler, Time=\"");
    Serial.print(__TIME__);
    Serial.print("\", Date=\"");
    Serial.print(__DATE__);
    Serial.println("\"");
  }
}

void loop() {
}

bool getTime(const char *str)
{
  int Hour, Min, Sec;

  if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
  tm.Hour = Hour;
  tm.Minute = Min;
  tm.Second = Sec;
  return true;
}

bool getDate(const char *str)
{
  char Month[12];
  int Day, Year;
  uint8_t monthIndex;

  if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
  for (monthIndex = 0; monthIndex < 12; monthIndex++) {
    if (strcmp(Month, monthName[monthIndex]) == 0) break;
  }
  if (monthIndex >= 12) return false;
  tm.Day = Day;
  tm.Month = monthIndex + 1;
  tm.Year = CalendarYrToTm(Year);
  return true;
}

I think you need another library. Why did you use that library (for DS1307) instead one for your RTC? Try this one.

Why did you use that library (for DS1307) instead one for your RTC?

For some reason I was thinking the DS1307 was the chip in the red box which was standard, and the name of the chip was just upgraded because it included the temperature chip. Patting myself on the head for this.... Celebrating new years last night must have hit me harder than I anticipated.

How do I download the library you linked? I have only downloaded four libraries in the past, and am use to having one box that I drag to the libraries section and the I import it. But this link has

examples add optional unixtime support - based on a patch from feelinglucky a year ago
README don't do Wire.begin() in the lib in case the i2c registers need to be… 3 years ago
config.h add optional unixtime support - based on a patch from feelinglucky a year ago
ds3231.cpp add optional unixtime support - based on a patch from feelinglucky a year ago
ds3231.h add optional unixtime support - based on a patch from feelinglucky a year ago

Do I drag all of them to the libraries folder?

Untitled.png

In the bottom right side of the page you have a button saying "Download ZIP". Hit him as all the files are downloaded inside a zip file. Unzip and install.

I believe that what you did should have worked. I often use the DS1307 library with a DS3231. The error you got was from the failure of the i2c wire.write. It looks like you are on the correct pins of the mega for SDA/SCL. Try this I2C scanner and see if it finds your RTC.

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 8; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Sometimes the jumper wires or bread board holes are defective. Try some new wires and a different position.

You will gain more functionality with a DS3231 library, but you should have been able to set the time with what you used.

luisilva thank you, I downloaded the library. I've never really attempted or really even looked into trying to modify a library before, but was wondering if it would be a lot more difficult than modifying a sketch? Is it written in the same language/format as a sketch?

cattledog I tried the code you provided and the serial monitor printed this

XòþÐ2‡Òÿ

I received a similar response from the serial monitor before when I tried Thread post 112 on Automated Reptile Control System The guy mentioned it might have been caused by

when it comes to the serial monitor, are you using the right baud rate? if you are, i honestly do not know what it is trying to output. i believe i documented out all instances of serial.print as the code is stable.

Besides changing Serial.begin (9600); to Serial.begin (115200); in the code is there anything else I need to do to address the increased baud rate?

----------------------------------------------edit----------------------------------------------
when I use 9600 for the baud rate in the code cattledog provided the serial monitor says

I2C scanner. Scanning ...
Found address: 87 (0x57)
Found address: 104 (0x68)
Done.
Found 2 device(s).

At the lower right hand corner of the serial monitor with the IDE there is a little pull down window to set the baud rate. You change the baud rate on the monitor to match the baud rate in the sketch.

Thank you,

Just to let everyone know, now that I have changed the breadboard and wires out the sketch is working correctly now.

DS1307 configured Time=20:43:51, Date=Jan 1 2015

I didn't set the time myself, and am curious to figure out how to changed 20:43:51 to my correct time zone. But i'm happy it is working!

curious to figure out how to changed 20:43:51 to my correct time zone.

The first sketch is setting the time to match your computer. Is your computer showing the correct time for your time zone?

Yes, but my computer isn't using military time. My computer says 9:01PM now, but the arduino is converting it to 21:01 which is military time. I need to figure out how to tell it that i'm a civilian.

I also noticed this in the code of a different example

// during an alarm the INT pin of the RTC is pulled low
//
// this is handy for minimizing power consumption for sensor-like devices,
// since they can be started up by this pin on given time intervals.

But I am not seeing the INT pin on the DS3231 chip. Is this a type of built in Relay by chance?

#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return( (val/16*10) + (val%16) );
}
void setup()
{
  Wire.begin();
  Serial.begin(9600);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(30,42,21,4,26,11,14);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}
void displayTime()
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // send it to the serial monitor
  Serial.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  Serial.print(":");
  if (minute<10)
  {
    Serial.print("0");
  }
  Serial.print(minute, DEC);
  Serial.print(":");
  if (second<10)
  {
    Serial.print("0");
  }
  Serial.print(second, DEC);
  Serial.print(" ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print(" Day of week: ");
  switch(dayOfWeek){
  case 1:
    Serial.println("Sunday");
    break;
  case 2:
    Serial.println("Monday");
    break;
  case 3:
    Serial.println("Tuesday");
    break;
  case 4:
    Serial.println("Wednesday");
    break;
  case 5:
    Serial.println("Thursday");
    break;
  case 6:
    Serial.println("Friday");
    break;
  case 7:
    Serial.println("Saturday");
    break;
  }
}
void loop()
{
  displayTime(); // display the real-time clock data on the Serial Monitor,
  delay(1000); // every second
}

here is code.

If you want to write RTc time

uncomment the line from setup & upload the code. & set up your current time.

setDS3231time(30,42,21,4,26,11,14);
format 
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte

once time update comment the same line upload the code. this avoid the writing same time ; update from current time else whenver it started your time & date will be same.

Thomas499:
Thank you,

Just to let everyone know, now that I have changed the breadboard and wires out the sketch is working correctly now. I didn't set the time myself, and am curious to figure out how to changed 20:43:51 to my correct time zone. But i'm happy it is working!

I am a bit anal about those cheap clock-modules as they drift far too much for my liking... after a week, I'm unhappy with the results. So I built the GPS clock to eliminate that issue forever. But before the GPS clock, I modified my Mega2560 code to use an IR remote to set the time anytime I wanted... also, allows me to "hack" the clock to the exact second for sync with WWV. You can find the IR dedicated controller here. This approach I find is adequate for a cheap clock... push a button, point the universal remote set to Sony, correct the time, go get a beer.

Ray

AMPS-N- I have two questions about the code you posted. This code doesn't take the time from the computer, you have to set it yourself correct? or did it take the time from the computer from the previous sketch and then converts it based on that? The second question I have is where do the cases come from? Is there a part in the code similar to

for(int x = 2;x<8;x++{

that tells it how many cases there are? On the code you posted at first glance it would appear it would automatically start on case 1, and go from there, but as you can see from the code below from the Reptile reference that I posted earlier this code starts at case 0 and then goes to case 1 so I'm trying to understand out how cases work.

// Call this method in response to finding a substitution character '\002' within some
// URI content to send the appropriate replacement text, depending on the URI index and
// the substitution index within the content.
void sendSubstitute(EthernetClient client, int nUriIndex, int nSubstituteIndex, BUFFER & requestContent)
{
  if (nUriIndex < NUM_PAGES)
  {
    // Page request
    switch (nUriIndex)
    {
 /***************************************************************************
 //                  PAGE 1
 ***************************************************************************/
      case 0:
        switch (nSubstituteIndex)
        {
          case 0: 
            sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[30])));  //client.print("0.0.0.1");
            wdt_reset();
            break;
          case 1: 
            client.print(ip_to_str(localip));
            wdt_reset();
            break;
          case 2: 
            sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[32])));  //client.print(system_date);
            wdt_reset();
            break;
          case 3: 
            client.print(hour);
            sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[0])));  //client.print(":");
            if (minute<10)
            {
              sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[1])));  //client.print("0");
            }
            client.print(minute);
            sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[0])));  //client.print(":");
            if (second<10)
            {
              sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[1])));  //client.print("0");
            }
            client.print(second);
           
            sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[2])));  //client.print(" ");
            switch(dayOfWeek){
            case 1: 
              sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[3])));  //client.print("Sun");
              break;
            case 2: 
              sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[4])));  //client.print("Mon");
              break;
            case 3: 
              sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[5])));  //client.print("Tue");
              break;
            case 4: 
              sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[6])));  //client.print("Wed");
              break;
            case 5: 
              sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[7])));  //client.print("Thu");
              break;
            case 6: 
              sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[8])));  //client.print("Fri");
              break;
            case 7: 
              sendProgMemAsString(client, (char*)pgm_read_word(&(basic_table[9])));  //client.print("Sat");
              break;
            }

mrburnette. I thought about purchasing a GPS for this, but they are expensive, and this clock will be located inside and I am unsure if GPS would work well without a view of the sky (any thoughts?) . I was thinking about seeing if I could program it to sync to the NTP database every 24 hours, or when a button is pressed to sync to their code. I don't know how hard this would be, I know i would have to code a base time reference for the time zone, and to make it account for daylights savings time and so on. Out of curiosity how far will they drift after a week? A few seconds, minutes, hours? I am going to look into the IR dedicated controller you referenced, this sounds like a neat learning example to start with.

--------------------------------edit---------------------------------------
Does anyone know of a book or site that would be an ideal starting point for a beginner to learn the ropes of binary coding?

this adds the Timezone.h library to the NTP clock functionality.

It doesn't use an RTC, because it just syncs to the server (frequently)

Note I use a non-standard I2C library for RTC, so you may have to mess with that a bit. This should show you how to do what you want to do, though.

#include <Wire.h>
#include <SPI.h>         
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <Time.h>
#include <Timezone.h>
#include <LiquidCrystal_I2C.h>

#define DEBUG_ON

#ifdef DEBUG_ON
#define DEBUG_PRINT(x)   Serial.print(x)
#define DEBUG_PRINTLN(x) Serial.println(x)
#define SERIAL_START(x)  Serial.begin(x)
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTLN(x)
#define SERIAL_START(x)
#endif
//
LiquidCrystal_I2C lcd(0x27, 16, 2);
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0}; // fetching time indicator
//
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
unsigned int localPort = 8888;      // local port to listen for UDP packets
IPAddress timeServer(132, 163, 4, 101); // time-a.timefreq.bldrdoc.gov NTP server
// IPAddress timeServer(132, 163, 4, 102); // time-b.timefreq.bldrdoc.gov NTP server
// IPAddress timeServer(132, 163, 4, 103); // time-c.timefreq.bldrdoc.gov NTP server
const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets 
const char *dayOfWeek[] = {"Null","Sunday ","Monday ", "Tuesday ", "Wednesday ", "Thursday ", "Friday ", "Saturday "};
// 
EthernetUDP Udp; // A UDP instance to let us send and receive packets over UDP
TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240};  //Eastern Daylight Time = UTC - 4 hours
TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300};   //Eastern Standard Time = UTC - 5 hours
Timezone usET(usEDT, usEST);
TimeChangeRule *tcr;
boolean justStarted = true;
//
void setup() 
{
  Serial.begin(9600);
  //
  DEBUG_PRINTLN(F("configuring ethernet"));
  if (Ethernet.begin(mac) == 0) // start Ethernet and UDP
  {
    DEBUG_PRINTLN(F("Failed to configure Ethernet using DHCP")); 
    while(true){
    }
  }
  //
  Udp.begin(localPort);
  //
  lcd.init();
  lcd.clear();
  lcd.backlight();
  lcd.createChar(0, clock);
  lcd.print("Hello, Jim!");
  delay(3000);
}
//
void loop()
{
  updateLCD();
  getNTPtime();
}
//
void updateLCD()
{
  
  static int lastSecond; 
  time_t rightNow = now();
  if (second(rightNow) != lastSecond)
  {
    lcd.setCursor(0,0);
    lcd.print(F("Time:"));
    DEBUG_PRINT(F("Time:"));
    lcd.print(hourFormat12(rightNow) < 10 ? F(" ") : F(""));
    DEBUG_PRINT(hourFormat12(rightNow) < 10 ? F(" ") : F(""));
    lcd.print(hourFormat12(rightNow));
    DEBUG_PRINT(hourFormat12(rightNow));
    lcd.print(minute(rightNow) < 10 ? F(":0") : F(":"));
    DEBUG_PRINT(minute(rightNow) < 10 ? F(":0") : F(":"));
    lcd.print(minute(rightNow));
    DEBUG_PRINT(minute(rightNow));
    lcd.print(second(rightNow) < 10 ? F(":0") : F(":"));
    DEBUG_PRINT(second(rightNow) < 10 ? F(":0") : F(":"));
    lcd.print(second(rightNow));
    DEBUG_PRINT(second(rightNow));
    lcd.print(isAM() ? "am" : "pm");
    DEBUG_PRINT(isAM() ? " am " : " pm ");
    lcd.setCursor(0,1);
    lcd.print(dayOfWeek[weekday(rightNow)]);
    DEBUG_PRINTLN(dayOfWeek[weekday(rightNow)]);
    lcd.print(F("      "));
    lcd.setCursor(11,1);
    lcd.print(month(rightNow) < 10 ? F(" ") : F(""));
    lcd.print(month(rightNow));
    lcd.print(day(rightNow) < 10 ? F("/0") : F("/"));
    lcd.print(day(rightNow));
  }
  lastSecond = second(rightNow);
}
//
unsigned long sendNTPpacket(IPAddress& address) // Send an NTP request to the time server at the given address 
{
  memset(packetBuffer, 0, NTP_PACKET_SIZE); 
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;            // Stratum, or type of clock
  packetBuffer[2] = 6;            // Polling Interval
  packetBuffer[3] = 0xEC;         // Peer Clock Precision
  packetBuffer[12]  = 49; 
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;		   
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer,NTP_PACKET_SIZE);
  Udp.endPacket(); 
}
//
void receiveTime(unsigned long newTime)
{
  DEBUG_PRINT(F("Time value received: "));
  int lastSecond = second();
  int lastMinute = minute();
  int lastHour = hour();
  setTime(newTime);
  if ((second() != lastSecond) || (minute() != lastMinute) || (hour() != lastHour))
  {
    DEBUG_PRINTLN(F("Clock updated...."));
    DEBUG_PRINT(F("Sensor's time currently set to:"));
    DEBUG_PRINT(hourFormat12() < 10? F(" 0") : F(" "));
    DEBUG_PRINT(hourFormat12());
    DEBUG_PRINT(minute() < 10? F(":0") : F(":"));
    DEBUG_PRINT(minute());
    DEBUG_PRINTLN(isAM()? F("am") : F("pm"));
    DEBUG_PRINT(month());
    DEBUG_PRINT(F("/"));
    DEBUG_PRINT(day());
    DEBUG_PRINT(F("/"));
    DEBUG_PRINTLN(year());
    DEBUG_PRINTLN(dayOfWeek[weekday()]);
  }
  lcd.setCursor(15,0);
  lcd.print(F(" "));
}
//
void getNTPtime()
{
  static unsigned long lastUpdateTime;
  const unsigned long interval = 60000UL;
  if ((millis() - lastUpdateTime >= interval))
  {
    lcd.setCursor(15,0);
    lcd.write(0);
    sendNTPpacket(timeServer); // send an NTP packet to a time server
    delay(1000);  
    if (Udp.parsePacket()) 
    {  
      Udp.read(packetBuffer,NTP_PACKET_SIZE);  // read the packet into the buffer
      unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
      unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);  
      unsigned long secsSince1900 = highWord << 16 | lowWord;  
      DEBUG_PRINT(F("Seconds since Jan 1 1900 = "));
      DEBUG_PRINTLN(secsSince1900);               
      Serial.print(F("Unix time = "));
      time_t utcEpoch = secsSince1900 - 2208988800UL;//seventyYears = 2208988800UL
      DEBUG_PRINTLN(utcEpoch);                               
      receiveTime(usET.toLocal(utcEpoch, &tcr) + 2);  //about 2 seconds to call for time
    }
    lastUpdateTime += interval;
  }
}

i don know your application

yes it is true it take user defined RTC.when you planning to use the GPS. Then it will really work out for you

The TinyGPS ++ library by Mikal Hart @ TinyGPS++ | Arduiniana
Will extract accurate time from the GPS GGA or the RMC sentence.
retrieving time data doesn't require a full view of the sky and works Very well in the house..
I've done a half dozed clocks with TinyGPS++ and they Always work first time..

Doc

I will order a TinyGPS soon. I would like to understand the basic coding first provided in the examples. The code I am looking at comes from the rtc_ds3231.h library example

#include <Wire.h>
#include "ds3231.h"
#include "rtc_ds3231.h"

#define BUFF_MAX 128

uint8_t time[8];
char recv[BUFF_MAX];
unsigned int recv_size = 0;
unsigned long prev, interval = 5000;

void setup()
{
    Serial.begin(9600);
    Wire.begin();
    DS3231_init(DS3231_INTCN);
    memset(recv, 0, BUFF_MAX);
    Serial.println("GET time");
}

void loop()
{
    char in;
    char buff[BUFF_MAX];
    unsigned long now = millis();
    struct ts t;

    // show time once in a while
    if ((now - prev > interval) && (Serial.available() <= 0)) {
        DS3231_get(&t);

        // there is a compile time option in the library to include unixtime support
#ifdef CONFIG_UNIXTIME
        snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d %ld", t.year,
             t.mon, t.mday, t.hour, t.min, t.sec, t.unixtime);
#else
        snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year,
             t.mon, t.mday, t.hour, t.min, t.sec);
#endif

        Serial.println(buff);
        prev = now;
    }

    if (Serial.available() > 0) {
        in = Serial.read();

        if ((in == 10 || in == 13) && (recv_size > 0)) {
            parse_cmd(recv, recv_size);
            recv_size = 0;
            recv[0] = 0;
        } else if (in < 48 || in > 122) {;       // ignore ~[0-9A-Za-z]
        } else if (recv_size > BUFF_MAX - 2) {   // drop lines that are too long
            // drop
            recv_size = 0;
            recv[0] = 0;
        } else if (recv_size < BUFF_MAX - 2) {
            recv[recv_size] = in;
            recv[recv_size + 1] = 0;
            recv_size += 1;
        }

    }
}

void parse_cmd(char *cmd, int cmdsize)
{
    uint8_t i;
    uint8_t reg_val;
    char buff[BUFF_MAX];
    struct ts t;

    //snprintf(buff, BUFF_MAX, "cmd was '%s' %d\n", cmd, cmdsize);
    //Serial.print(buff);

    // TssmmhhWDDMMYYYY aka set time
    if (cmd[0] == 84 && cmdsize == 16) {
        //T355720619112011
        t.sec = inp2toi(cmd, 1);
        t.min = inp2toi(cmd, 3);
        t.hour = inp2toi(cmd, 5);
        t.wday = inp2toi(cmd, 7);
        t.mday = inp2toi(cmd, 8);
        t.mon = inp2toi(cmd, 10);
        t.year = inp2toi(cmd, 12) * 100 + inp2toi(cmd, 14);
        DS3231_set(t);
        Serial.println("OK");
    } else if (cmd[0] == 49 && cmdsize == 1) {  // "1" get alarm 1
        DS3231_get_a1(&buff[0], 59);
        Serial.println(buff);
    } else if (cmd[0] == 50 && cmdsize == 1) {  // "2" get alarm 1
        DS3231_get_a2(&buff[0], 59);
        Serial.println(buff);
    } else if (cmd[0] == 51 && cmdsize == 1) {  // "3" get aging register
        Serial.print("aging reg is ");
        Serial.println(DS3231_get_aging(), DEC);
    } else if (cmd[0] == 65 && cmdsize == 9) {  // "A" set alarm 1
        DS3231_set_creg(DS3231_INTCN | DS3231_A1IE);
        //ASSMMHHDD
        for (i = 0; i < 4; i++) {
            time[i] = (cmd[2 * i + 1] - 48) * 10 + cmd[2 * i + 2] - 48; // ss, mm, hh, dd
        }
        boolean flags[5] = { 0, 0, 0, 0, 0 };
        DS3231_set_a1(time[0], time[1], time[2], time[3], flags);
        DS3231_get_a1(&buff[0], 59);
        Serial.println(buff);
    } else if (cmd[0] == 66 && cmdsize == 7) {  // "B" Set Alarm 2
        DS3231_set_creg(DS3231_INTCN | DS3231_A2IE);
        //BMMHHDD
        for (i = 0; i < 4; i++) {
            time[i] = (cmd[2 * i + 1] - 48) * 10 + cmd[2 * i + 2] - 48; // mm, hh, dd
        }
        boolean flags[5] = { 0, 0, 0, 0 };
        DS3231_set_a2(time[0], time[1], time[2], flags);
        DS3231_get_a2(&buff[0], 59);
        Serial.println(buff);
    } else if (cmd[0] == 67 && cmdsize == 1) {  // "C" - get temperature register
        Serial.print("temperature reg is ");
        Serial.println(DS3231_get_treg(), DEC);
    } else if (cmd[0] == 68 && cmdsize == 1) {  // "D" - reset status register alarm flags
        reg_val = DS3231_get_sreg();
        reg_val &= B11111100;
        DS3231_set_sreg(reg_val);
    } else if (cmd[0] == 70 && cmdsize == 1) {  // "F" - custom fct
        reg_val = DS3231_get_addr(0x5);
        Serial.print("orig ");
        Serial.print(reg_val,DEC);
        Serial.print("month is ");
        Serial.println(bcdtodec(reg_val & 0x1F),DEC);
    } else if (cmd[0] == 71 && cmdsize == 1) {  // "G" - set aging status register
        DS3231_set_aging(0);
    } else if (cmd[0] == 83 && cmdsize == 1) {  // "S" - get status register
        Serial.print("status reg is ");
        Serial.println(DS3231_get_sreg(), DEC);
    } else {
        Serial.print("unknown command prefix ");
        Serial.println(cmd[0]);
        Serial.println(cmd[0], DEC);
    }
}
    // show time once in a while
    if ((now - prev > interval) && (Serial.available() <= 0)) {
        DS3231_get(&t);

        // there is a compile time option in the library to include unixtime support
#ifdef CONFIG_UNIXTIME
        snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d %ld", t.year,
             t.mon, t.mday, t.hour, t.min, t.sec, t.unixtime);
#else
        snprintf(buff, BUFF_MAX, "%d.%02d.%02d %02d:%02d:%02d", t.year,
             t.mon, t.mday, t.hour, t.min, t.sec);
#endif

I don't understand why unixtime isn't showing up.

Also, the year is showing up as 1915 instead of 2015. I'm trying to figure out how to correct it.

boolean flags[5] = { 0, 0, 0, 0 };

is this where you set the timer?

when the timer goes off is that when it will take a temp reading? Right now the serial monitor is only showing the time as 1915.01.04 15:27:48

parse means it stores the data taken correct? How do I access this data? In the examples i've seen so far every code that used parsed also used a SD card. Is the SD card built into the DS3231 chip?

Dear Thomas,

Here code GPS & time sync with Ds1307. This code might help you to understand & implement for DS3231

It work on RTC. Every predefined time GPS get synch with RTC.

If RTC failed. It works on GPS.

GPS_syn.zip (5.36 KB)

AMPS

I downloaded your library and tried the code example.

 This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Mega 2560 or Mega ADK"
gps_c:11: error: 'TinyGPS' does not name a type
gps_c.ino: In function 'void gps_data()':
gps_c:35: error: 'gps' was not declared in this scope
gps_c:58: error: 'gps' was not declared in this scope
gps_c.ino: In function 'int get_year()':
gps_c:88: error: 'gps' was not declared in this scope
gps_c.ino: In function 'int get_month()':
gps_c:99: error: 'gps' was not declared in this scope
gps_c.ino: In function 'int get_day()':
gps_c:111: error: 'gps' was not declared in this scope
gps_c.ino: In function 'int get_hour()':
gps_c:123: error: 'gps' was not declared in this scope
gps_c.ino: In function 'int get_min()':
gps_c:135: error: 'gps' was not declared in this scope
gps_c.ino: In function 'int get_sec()':
gps_c:146: error: 'gps' was not declared in this scope
gps_c.ino: In function 'float get_latitude()':
gps_c:157: error: 'gps' was not declared in this scope
gps_c.ino: In function 'float get_longitude()':
gps_c:169: error: 'gps' was not declared in this scope
gps_c.ino: In function 'time_t gpsTimeSync()':
gps_c:186: error: 'gps' was not declared in this scope

These are the errors that came up when i tried to compile the code in the example. Are all the libraries that I need for the example included in the zip?

Edit: adding the extra libraries made it so when I view examples I can no longer see the WiFi example library. See attachment: Is there a way to scroll or to combine some of these new added libraries into a folder (possibly named added library examples)?

Is there a way to scroll

Upgrade to a later version of the IDE in which this problem has been fixed.