DS3231 RTC
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 boards. This document assumes that you are using the precision rtc module from Jeelabs.
The DS3231 (About Modules) module communicates with the DS3231 over I2C.
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, { DST : true });
setInterval(function() {
console.log(rtc.readDateTime());
}, 1000);
Initialising
Initialise the module by calling require("DS3231").connect
, passing in an
I2C
interface and an optional option
object:
var rtc = require("DS3231").connect(I2C1, {
DST : true // make UK daylight saving changes automatically (default=true)
});
Daylight saving
The day of the week is required so that the clocks move forwards and backwards at the correct times for daylight saving in the UK.
You need to specify this as follows:
// one of "Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"
rtc.setDow("Monday")
Please note that you need to call the readDateTime function at least every second for daylight saving to work.
Setting Date/Time
To set the date:
rtc.setDate(date,month,year);
To set the time:
rtc.setTime(hours,minutes);
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.