Go Down

Topic: DS3231.h --- Library for DS3231 (or DS3232) real-time clock (Read 17114 times) previous topic - next topic

Ayars

I've written a header file/library/examples for the DS3231 clock: it's available here:
    http://hacks.ayars.org/2011/04/ds3231-real-time-clock.html

I wrote it for the DS3231, but the timekeeping registers are identical on the DS3232 so it'll work for that also.

This forum has been incredibly helpful to me over the years, and I hope this is a start on repayment. Drop me an email if you use it, and let me know if you find bugs so I can fix them right away.

-Eric Ayars
<firstname at lastname.org>

Wagner Sartori Junior

Great work.

Just a suggestion, why not integrate on the Time Library? There's some examples using DS1307 already, just have to port to work with your library.

Time Library Link:
http://www.arduino.cc/playground/Code/Time

Wagner Sartori Junior

I'm with some spare time so I made the library.
https://bitbucket.org/trunet/ds3231rtc

Fully compatible with Time Library and has getTemp method to retrieve temperature.

Just use the TimeRTC examples provided on Time and change DS1307RTC.h to DS3231RTC.h.

GreyGnome

Thanks, Eric.  This is cool, I'll be needing that chip in the future and I am glad to have your work!
:D

WanaGo

Hi,

I was just curious if you are planning to upgrade this library to Arduino 1.0?

https://github.com/trunet/DS3231RTC

Regards
James

Wagner Sartori Junior

it just needs minor updates. I can work with this next week maybe.

jhub

#6
Feb 09, 2012, 05:00 am Last Edit: Feb 09, 2012, 06:55 pm by jhub Reason: 1
As it turns out i ran into the same issue with the 1.0 ide and ended up updating it myself.
I ran the examples and they seem to work just fine.

i do not know if you already updated the code or not but here is the a copy of the files i updated.
The example codes remains unchanged but is now in an ino file.

http://soiling-detector.googlecode.com/files/DS3231updated.zip

Your orig lib and examples helped me understand how to get this IC up and running for my datalogger.
I have found a few of your sketches to be rather helpful.
Thank you

Wagner Sartori Junior

that's the way open source software works... thanks for your help and I'll update the code later.

ievolve



http://soiling-detector.googlecode.com/files/DS3231updated.zip


I set my clock with the example in the zip, and when I run the example test for some reason one time is exactly 6 hours off of the other.  The logs look like:

2012 2 17 5 19 30 25 24h T=20.00 O+
Alarm 1: 5 DoW 19 22 30 enabled
Alarm 2: 17 Date 19 23 enabled
12/2/17day of the week :5
13:30:26

Any ideas where I can look for the bug?  Or ideas what it may be?

ievolve

It appears from my tests that getHour() is returning the proper hours, but getTime() is not, looking at the code and there didnt seem to be any glaring differences though, any local pros have an idea?

ievolve

Found it, there is a bug on line 40 of DS3231.cpp where the hours are run through bdcToDec() twice.  To fix this, on line 40 change:

tempBuffer = bcdToDec(Wire.read());

to

tempBuffer = Wire.read();

After this your getTime() calls should read correctly!

redbear79

hm... how will i get leading zeros?

can anybody help?

NewAgeRyan85

#12
May 23, 2014, 05:47 pm Last Edit: May 25, 2014, 09:21 pm by NewAgeRyan85 Reason: 1
Leading  Zeros formatting. Enjoy 8)
05/23/2014


Code: [Select]
// Display the time >  getTime() function
Clock.getTime(year, month, date, DoW, hour, minute, second);

       if (month < 10)
         {
           Serial.print("0");
           Serial.print(month, DEC);
         }
       else
         {
           Serial.print(month, DEC);
         }

       Serial.print("/");

if (date < 10)
         {
           Serial.print("0");
           Serial.print(date, DEC);
         }
      else
         {
           Serial.print(date, DEC);
         }
         
       Serial.print("/");
       
       Serial.print("2");
if (Century)
         { // Won't need this until 2100 - or if clock gets reset.
Serial.print("1");
 }
       else
         {
Serial.print("0");
 }
       if (year < 10)             // used if the clock gets reset or if the year is 2100 - 2110
         {
           Serial.print("0");
         }
Serial.println(year);

       Serial.print("day of the week : ");
Serial.println(DoW, DEC);

       if (hour <10)
         {
           Serial.print("0");
           Serial.print(hour, DEC);
         }
else
         {
           Serial.print(hour, DEC);
         }
         
       Serial.print(":");

       if (minute < 10)
         {
           Serial.print("0");
           Serial.print(minute, DEC);
         }
       else
         {
           Serial.print(minute, DEC);
         }
       Serial.print(":");
       if (second < 10)
       {
         Serial.print("0");
         Serial.println(second, DEC);
         
       }
else
       {
         Serial.println(second, DEC);
       }

// simple way to format the output to include the leading zeros.
// with adjustments for formatting the year if clock gets reset or year 2100+
// NewAgeRyan85



Go Up