Library
cd ~/Arduino/libraries
mkdir DS3231
wget http://domoticx.phoenixinteractive.nl/arduino/libraries/ds13xx_ds32xx/DS3231%20v1.01.7z
wget http://145.130.102.57/domoticx/arduino/libraries/ds13xx_ds32xx/DS3231%20v1.01.7z
mv DS3231* DS3231
cd DS3231
7z x DS3231\ v1.01.7z
Connection
Source
// DS3231_Serial_Easy (C)2014 Henning Karlsen
// web: http://electronics.henningkarlsen.com/
//
// A quick demo of how to use my DS3231-library to
// quickly send time and date information over a serial link
//
// To use the hardware I2C (TWI) interface of the Arduino you must connect
// the pins as follows:
//
// Arduino Uno/2009:
// ----------------------
// DS3231: SDA pin -> Arduino Analog 4 or the dedicated SDA pin
// SCL pin -> Arduino Analog 5 or the dedicated SCL pin
// VCC pin -> Arduino 5V
// GND pin -> Arduino GND
#include <DS3231.h>
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);
Time waktu;
void setup() {
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
// rtc.writeProtect(false);
rtc.writeProtect(true);
// Setup Serial connection
Serial.begin(9600);
// The following lines can be commented out to use the values already stored in the DS1302
// rtc.setDOW(MONDAY); // Set Day-of-Week to MONDAY
// rtc.setTime(13, 0, 0); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(29, 2, 2016); // Set the date to Feb 2, 2016
}
void loop() {
waktu = rtc.getTime();
int dataJam = waktu.hour;
int dataMenit = waktu.min;
int dataDetik = waktu.sec;
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// Wait one second before repeating :)
delay (1000);
}