DS3231 RTC

Github Repo C Header C source JS source
mongoose-os-libs/arduino-ds3231     api_ds3231.js

Arduino DS3231 High Precision Real Time Clock (RTC) library for Mongoose OS

Tested and works on esp8266/esp32

Description

DS3231 is a low-cost, extremely accurate I2C real-time clock (RTC), with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. The device incorporates a battery input, disconnect the main power supply and maintains accurate timekeeping. Integrated oscillator improve long-term accuracy of the device and reduces the number of components of the production line. RTC maintains seconds, minutes, hours, day, date, month, and year information. Less than 31 days of the month, the end date will be automatically adjusted, including corrections for leap year. The clock operates in either the 24 hours or band / AM / PM indication of the 12-hour format. Provides two configurable alarm clock and a calendar can be set to a square wave output. Address and data are transferred serially through an I2C bidirectional bus.See product page link for more information about the hardware.

alt text

Features

  • Battery
  • Operating voltage: 3.3 - 5.5V
  • Clock chip: High-precision clock chip DS3231
  • Clock Accuracy: 0-40 °C range, the accuracy 2ppm, the error was about 1 minute
  • Calendar alarm clock with two
  • Programmable square-wave output
  • Real time clock generator seconds, minutes, hours, day, date, month and year timing and provide valid until the year 2100 leap year compensation

Usage

mos.yml, add:

config_schema:
 - ["i2c.enable", true]
libs:
 - origin: https://github.com/mongoose-os-libs/arduino-ds3231

init.js, add:

load('api_ds3231.js');

(JavaScript) usage example

#include "mgos_arduino_DS3231.h" 

JS API


DS3231.create

DS3231.create()

Create an instance of DS3231 with the methods described below.

myds.setVoltage

myds.setVoltage()

Destroy myds instance; it's illegal to call any methods on that instance afterwards. Return value: none.

myds.setTimeSeconds

myds.setTimeSeconds(seconds)

Set seconds, 0 to 59. Return value: none.

myds.setTimeMinutes

myds.setTimeMinutes(minutes)

Set minutes, 0 to 59. Return value: none.

myds.setTimeHours

myds.setTimeHours(hours)

Set hours, 0 to 23. Return value: none.

myds.setTimeDayOfTheWeek

myds.setTimeDayOfTheWeek(dayOfTheWeekDay)

Set day of the week, 1 to 7. Return value: none.

myds.setTimeDate

myds.setTimeDate(date)

Set day of month, 1 to 31. Return value: none.

myds.setTimeMonth

myds.setTimeMonth(month)

Set month, 1 to 12 Return value: none.

myds.setTimeYear

myds.setTimeYear(twoDigitYear)

Set two last digits of the year, 0 to 99. Return value: none.

myds.getTimeSeconds

myds.getTimeSeconds()

Get seconds, 0 to 59.

myds.getTimeMinutes

myds.getTimeMinutes()

Get minutes, 0 to 59.

myds.getTimeHours

myds.getTimeHours()

Get hours, 0 to 23.

myds.getTimeHoursIs12HourClock

myds.getTimeHoursIs12HourClock()

Return 1 if 12-hour format is used, 0 otherwise.

myds.getTimeHoursIsPM

myds.getTimeHoursIsPM()

Return 1 if it's later than the noon.

myds.getTimeDayOfTheWeek

myds.getTimeDayOfTheWeek()

Get day of week, 1 to 7.

myds.getTimeDate

myds.getTimeDate()

Get day of month, 1 to 31.

myds.getTimeMonth

myds.getTimeMonth()

Get month, 1 to 12.

myds.getTimeYear

myds.getTimeYear()

Get last two digits of the year, 0 to 99.

myds.getTimeYearCentury

myds.getTimeYearCentury()

Return 1 if year is between 2100 and 2199; 0 otherwise.

edit this doc