Post your best Lua script examples here

User avatar
By lucashayes
#7653 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!
User avatar
By alonewolfx2
#7664 Is it work with ds1307?
User avatar
By gwizz
#7708 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
User avatar
By lucashayes
#7735
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 :)