ESP32 Display Controller and Graphics Library
fabgl::DS3231 Class Reference

DS3231 Real Time Clock driver. More...

#include <DS3231.h>

Public Member Functions

bool available ()
 Determines if DS3231 is reachable. More...
void begin (I2C *i2c)
 Initializes DS3231 driver. More...
void clockEnabled (bool value)
 Enables or disables DS3231 oscillator. More...
DateTime const & datetime ()
 Queries DS3231 for current date and time. More...
bool dateTimeValid ()
 Determines the validity of datetime. More...
bool setDateTime (DateTime const &value)
 Sets current date and time. More...
double temperature ()
 Forces DS3231 to read current temperature. More...

Detailed Description

DS3231 Real Time Clock driver.


fabgl::I2C    I2C;
fabgl::DS3231 DS3231;

void setup() {
  I2C.begin(GPIO_NUM_4, GPIO_NUM_15);  // 4 = SDA, 15 = SCL

  auto dt = DS3231.datetime();
  Serial.printf("%02d/%02d/%d  %02d:%02d:%02d\n", dt.dayOfMonth, dt.month, dt.year, dt.hours, dt.minutes, dt.seconds);
  Serial.printf("temp = %0.3f C\n", DS3231.temperature());

Member Function Documentation

◆ available()

bool fabgl::DS3231::available ( )

Determines if DS3231 is reachable.

True if the device has been correctly initialized.

◆ begin()

void fabgl::DS3231::begin ( I2C i2c)

Initializes DS3231 driver.

i2cPointer to I2C handler

◆ clockEnabled()

void fabgl::DS3231::clockEnabled ( bool  value)

Enables or disables DS3231 oscillator.

valueIf true oscillator is enabled (date and time are always maintained by external battery)

◆ datetime()

DateTime const & fabgl::DS3231::datetime ( )

Queries DS3231 for current date and time.

A DateTime structure containing current date and time

◆ dateTimeValid()

bool fabgl::DS3231::dateTimeValid ( )

Determines the validity of datetime.

After calling setDateTime() the datetime becomes valid.

False indicates that the oscillator either is stopped or was stopped for some period and may be used to judge the validity of the timekeeping data.

◆ setDateTime()

bool fabgl::DS3231::setDateTime ( DateTime const &  value)

Sets current date and time.

This methods also resets the invalid date flag.

valueDate and time to set

◆ temperature()

double fabgl::DS3231::temperature ( )

Forces DS3231 to read current temperature.

Current temperature in Celsius Degrees

The documentation for this class was generated from the following files: