Maxim DS3231 RTC topic

Classes for the Maxim DS3231 high-precision, temperature-corrected real-time clock.

Introduction

The I2C Maxim DS3231 real time clock (RTC) is absolutely required for time-keeping on all AVR boards. This library also makes use of of the DS3231 for its on-board temperature sensor. This temperature is not equivalent to an environmental temperature measurement and should only be used to as a diagnostic. Internally, the DS3231 uses the temperature it measures to compensate for temperature variation in the crystal speed. This improves the timekeeping accuracy and reduces time drift.

The DS3231 requires a 3.3V power supply and most breakouts or boards that integrate the DS3231 (including the Mayfly) use a coin battery to supply the clock. Using separate power supply for the clock prevents the time from resetting if the main board loses power.

Sensor Datasheet

Datasheet

Sensor Constructor

MaximDS3231::MaximDS3231(uint8_t measurementsToAverage = 1) explicit

Construct a new Maxim DS3231 object.

Parameters
measurementsToAverage The number of measurements to take and average before giving a "final" result from the sensor; optional with a default value of 1.


Example Code

The Maxim DS3231 RTC is used in nearly all of the examples, including the menu a la carte example.

1#include <sensors/MaximDS3231.h>
2
3// Create a DS3231 sensor object
4MaximDS3231 ds3231(1);
5
6// Create a temperature variable pointer for the DS3231
7Variable* ds3231Temp =
8 new MaximDS3231_Temp(&ds3231, "12345678-abcd-1234-ef00-1234567890ab");

Classes

class MaximDS3231
The Sensor sub-class for the Maxim DS3231 when used as a low-accuracy temperature sensor.
class MaximDS3231_Temp
The Variable sub-class used for the temperature output from a DS3231.

Sensor Variable Counts

The number of variables that can be returned by the DS3231

#define DS3231_NUM_VARIABLES = 1
Sensor::_numReturnedValues; the DS3231 can report 1 value.
#define DS3231_INC_CALC_VARIABLES = 0
Sensor::_incCalcValues; we don't calculate any additional values.

Sensor Timing

The sensor timing for a Maxim DS18 RTC

#define DS3231_WARM_UP_TIME_MS = 0
Sensor::_warmUpTime_ms; the DS3231 should never be powered off so there is no warm-up time.
#define DS3231_STABILIZATION_TIME_MS = 0
Sensor::_stabilizationTime_ms; the DS3231 should never be powered off so there is no stabilization time.
#define DS3231_MEASUREMENT_TIME_MS = 200
Sensor::_measurementTime_ms; the DS3231 takes 200ms to complete a measurement - A single temperature conversion takes 200ms.

Temperature

The temperature variable from a Maxim DS18 RTC

  • Range is -55°C to 125°C
  • Accuracy: ± 3°C

MaximDS3231_Temp::MaximDS3231_Temp(MaximDS3231* parentSense, const char* uuid = "", const char* varCode = "BoardTemp") explicit

Construct a new MaximDS3231_Temp object.

Parameters
parentSense The parent MaximDS3231 providing the result values.
uuid A universally unique identifier (UUID or GUID) for the variable; optional with the default value of an empty string.
varCode A short code to help identify the variable in files; optional with a default value of "BoardTemp".

#define DS3231_TEMP_RESOLUTION = 2
Decimals places in string representation; temperature should have 2 - resolution is -0.25°C (10 bit).
#define DS3231_TEMP_VAR_NUM = 0
Sensor variable number; temperature is stored in sensorValues[0].
#define DS3231_TEMP_VAR_NAME = "temperatureDatalogger"
Variable name in ODM2 controlled vocabulary; "temperatureDatalogger".
#define DS3231_TEMP_UNIT_NAME = "degreeCelsius"
Variable unit name in ODM2 controlled vocabulary; "degreeCelsius" (°C)
#define DS3231_TEMP_DEFAULT_CODE = "BoardTemp"
Default variable short code; "BoardTemp".

Define documentation

#define DS3231_NUM_VARIABLES = 1

Sensor::_numReturnedValues; the DS3231 can report 1 value.


#define DS3231_INC_CALC_VARIABLES = 0

Sensor::_incCalcValues; we don't calculate any additional values.


#define DS3231_WARM_UP_TIME_MS = 0

Sensor::_warmUpTime_ms; the DS3231 should never be powered off so there is no warm-up time.


#define DS3231_STABILIZATION_TIME_MS = 0

Sensor::_stabilizationTime_ms; the DS3231 should never be powered off so there is no stabilization time.


#define DS3231_MEASUREMENT_TIME_MS = 200

Sensor::_measurementTime_ms; the DS3231 takes 200ms to complete a measurement - A single temperature conversion takes 200ms.


#define DS3231_TEMP_RESOLUTION = 2

Decimals places in string representation; temperature should have 2 - resolution is -0.25°C (10 bit).


#define DS3231_TEMP_VAR_NUM = 0

Sensor variable number; temperature is stored in sensorValues[0].


#define DS3231_TEMP_VAR_NAME = "temperatureDatalogger"

Variable name in ODM2 controlled vocabulary; "temperatureDatalogger".


#define DS3231_TEMP_UNIT_NAME = "degreeCelsius"

Variable unit name in ODM2 controlled vocabulary; "degreeCelsius" (°C)


#define DS3231_TEMP_DEFAULT_CODE = "BoardTemp"

Default variable short code; "BoardTemp".