Skip to content

Set.ino

Arnd edited this page Dec 12, 2020 · 2 revisions

Sample Arduino sketch to demonstrate setting, reading and calibrating an attached DS3231M real time clock. The DS3231M comes in a SO16 or SO8 package but is also available as an Adafruit Breakout board. The chip does not require external components such as oscillators/crystals and the associated capacitors.

Sample circuit

The image below shows the breadboard layout that I used for this sample program.

Program Overview

The sketch has been tested on Arduino Micro and ATMega 2560 and uses the serial port at 115200 baud. It starts off by initializing the serial interface and instantiates and initializes the DS3231M with the date/time that the library was pre-compiled (note that this might be earlier than when the sketch was compiled, which can lead to confusion). The sketch makes use of the sprintf() function to print out the date/time since this function allows formatting leading zeroes, which the Serial.print() function does not. The program outputs the date/time to the display every second and also toggles the Arduino builtin LED every second.

The date/time can be set by entering the command "SETDATE yyyy-mm-dd hh:nn:ss" in the serial monitor and sending it to the Arduino. The command is not case sensitive, but the date and time must be entered as shown above otherwise the command will be rejected.

Clone this wiki locally