- KEYWORDS: Module,RTC,Real Time Clock,Clock,Time,Date
Note: Espruino contains its own RTC - see [[Clocks]]. However if you need a battery backed-up RTC with full calendar functionality then this may be a better solution.
The DS3231 RTC chip is used in a few off the shelf modules. This document assumes that you are using the precision rtc module from Jeelabs.
Espruino | JeeLabs Precision RTC Module |
---|---|
3V3 | VCC |
GND | GND |
B6 (SCL) | DIO |
B7 (SDA) | AIO |
Note: Connect I2C pull up resistors on B6 and B7 to 3V3.
The following reads from the RTC module and prints the date and time in a string to the console every second.
I2C1.setup({scl:B6,sda:B7});
var rtc = require("DS3231").connect(I2C1);
setInterval(function() {
console.log(rtc.readDateTime());
}, 1000);
To set the day. The day is required so that the clocks move forwards and backwards for daylight saving in the UK. Please note that you need to call the readDateTime function at least every second for this to work.
rtc.setDow("day of the week")
To set the date:
rtc.setDate(date,month,year);
To set the time:
rtc.setTime(hours,minutes);