-->
Page 1 of 2

DS3231 RTC module

PostPosted: Sun Jan 18, 2015 8:08 pm
by lucashayes
I need a fairly accurate RTC for a project I'm working on so I wrote a LUA module for the DS3231.

Currently it supports setting and getting the time and date. Getting the temperature, and alarm features might be added when I have the time.

Code: Select allds3231=require("ds3231")
ds3231.init(3, 4)

-- Get date and time
second, minute, hour, day, date, month, year = ds3231.getTime();

-- Print date and time
print(string.format("Time & Date: %s:%s:%s %s/%s/%s",
    hour, minute, second, date, month, year))

-- Don't forget to release it after use
ds3231 = nil
package.loaded["ds3231"]=nil


I've also created a pull request for this to be added to the nodemcu repository: https://github.com/nodemcu/nodemcu-firmware/pull/114

For now you can get the module, documentation, and examples here: https://github.com/tobiebooth/nodemcu-f ... les/ds3231

Thanks!

Re: DS3231 RTC module

PostPosted: Mon Jan 19, 2015 3:31 am
by alonewolfx2
Is it work with ds1307?

Re: DS3231 RTC module

PostPosted: Mon Jan 19, 2015 11:28 am
by gwizz
Awesome work, thanks for sharing!! Even to my inexperienced eyes your code looks very clean, smells good too! :)

I'm sure Peter Scargill will be interested in this as well, he is very concerned with timekeeping with his projects.

If you can share any other details of your project I'd like to read about it?

Keep on hacking :D

Re: DS3231 RTC module

PostPosted: Mon Jan 19, 2015 3:39 pm
by lucashayes
alonewolfx2 wrote:Is it work with ds1307?


Looking at the DS1307 data sheet it does appear to use the same registers as the DS3231 so it probably will.

I don't have a 1307 on hand though to test with. If you try it and it works let me know :)