Chronodot Library Update

Posted 2011.12.01 17.40 in Computers/Internet/Technology by Stephanie

Arduino has just released their 1.0 software update. This is a Big Deal, but it does break some prior content. Changes to the basic libraries and the Wire library have resulted in my simple Chronodot library no longer functioning.

Fortunately it was a quick and simple fix which I’ve attached below.

One of these days I’ll learn how to use Git and do a real repository thing…


Chronodot Library Update

Note – this library is backwards compatible to older Arduino IDEs as well.


  1. jiffyjeff says:

    Hi Stephanie,
    I glanced at your Chronodot library. Thanks for your effort! If you’re so inclined, hosting it on a source control system (github) would help identify the latest version and would help solicit bugfixes and updates. I was looking at the code next to the Maxim DS3231 datasheet and noticed what appears to be a bug: Line 185 of Chronodot.cpp specifies an unsigned int for the integer portion of the temperature, it should probably be a signed int (According to Maxim it’s a two’s complement value). I’m guessing you haven’t tested your Chronodot code below freezing! 🙂

    Anyway, I would like to borrow your code and fix up bugs if I find them — if you make it easy to contribute I’ll be happy to do so. Again, thank you for the code and have a nice day!

    1. jiffyjeff says:

      … Whoops, got ahead of myself – If it is a two’s complement – the unsigned int is fine, but proper handling of the temp conversion for negative numbers (>127) should be handled. Then again, I haven’t tried the code — I might be missing something. 🙂 Thanks!

    2. Stephanie says:

      Hello Jiffyjeff,

      Thanks for the comments! I hate to admit it but I’ve never used github – I know I need to learn how to use it one of these days…

      Please feel free to use the code and do with it as you wish!

      You are quite correct that I’ve never tried it with my Chronodot below zero – I originally intended to use a Chronodot as the heart of a thermostat for my home HVAC system, as I figured it would save me the bother of using a separate temperature sensor. So I really never thought about it being exposed to anything above the 90’s or below the mid-60’s.

      Thinking about when I first threw it together, I probably used an unsigned int as I was using the ‘byte’ variable type for my temperatures in the thermostat sketch.


  2. Stephanie says:

    So today I finally dove into that whole github thing, and set up a repository for the library:

    I have not had a chance to play with that int / unsigned int for handling negative temperatures but I will get to that eventually.


  3. Tom says:

    Hi Stephanie, I am using your Chronodot library and it works great. Really nice and simple to use.
    I am newish to the arduino fan club and use your lib in a Stopwatch sketch. I wanted to learn more about the Alarms and clock outputs on the chronodot and found another lib for the DS3231 chip at:

    It has some nice code for using the alarms and clock output.

    Question: would you consider implementing the time set, alarm, and clock frequency get/set etc routines within you Chronodot lib?


    1. Stephanie says:

      Hi Tom,

      At the time I was originally working on this I did intend to do something with the other capabilities of the chip, including the alarm and frequency functions. The feedback I received back then however was that those functions weren’t as useful as there were easier ways to do those things. So I just left things as-is.

      Unfortunately, I’m not able to work further on my version of the libarry at the moment due to other demands on my time.

      There is a time set function in the library though, the Chronodot.adjust function takes a DateTime object and sets the clock. It’s up to your sketch to build the datetime object however works best for you.

  4. Pat says:

    Hi Stephanie, I’ve downloaded your updated Library without any problems. I am however not able to get the correct time when uploading your example sketch. The sketch is working but the time/year/month/day… is all wrong. any thoughts on how i would go about changing the time?

    1. Stephanie says:

      Hello Pat,

      The sample sketch checks to see if the chronodot is currently running(*), and if not it sets the time to the date and time that the sketch was compiled.

      The chronodot stops running if there is no power and no backup battery – when it is first powered on it sets a control bit to indicate that it had been stopped. When the time is set, that bit is reset and as long as it has either power or a backup battery it will continue to keep time after that.

      To set the time to something else, you need to use the Chronodot.adust function to send it a datetime object that has the desired date and time in it. You can build a datetime object within the sketch. How you do that will depend on what your sketch is doing.

      You could create a serial function that lets you send time and date info from the serial console, or if you have an ethernet shield connected you could have the sketch grab the time from an NTP server. Or if you just want something simple, use the adust function from the sample sketch in your ‘setup’ function, but without the test to see if the clock is running.

      Or for something more complicated, you could add a few buttons and a display and write it into your sketch to capture button presses and toggle the time and date settings. When I made my DIY thermostat (versions 1 and 2) I wrote a complete statemachine just for setting the time and date with four pushbuttons and an LCD display. My DIY thermostat also has code to set the time from a serial command. (I removed the buttonpress routine from the 3rd version as I never used it and it was just taking up space.)

      1. Pat says:

        Thanks for the quick reply, i ended up using a couple of buttons which i used to write the time/date etc… for the chronodot. Problem solved.

        A second question, i know the chronodot can operate in 12-hour mode and im pretty sure from the datasheet that the code is:
        B01000000 as opposed to B00110000 which would be 24-hour format.

        When i change it, the RTC outputs a time which seems to be in 12-format but is 2 hours off. Right now to get the time displayed in 12-hour format I’m using some if statements. Any thoughts you may have would be appreciated.



Leave a Comment