Introduction

After several months "Out of Stock", DS1307 RTC module has a big upgrade. It comes with a Gravity IIC interface, and the size is also reduced to fit miniaturization application. Gravity I2C DS1307 RTC module is a easy-to-use Real Time Clock module. It is cheap and affordable in most applications such as time clock, data logger, etc.. The new version DS1307 RTC module adopts high precision crystal oscillator which reduces time error dramatically. The test conducted shows the time error is only about 1 second in 24 hours (the average time error of Mechanical Watches is about 20s). The module is powered by single cell CR1220 (service life: 3~5 years). It is smaller and keeps EEPROM 4KB ROM to record information related to alarm clocks and events. Besides, you can set the IIC address by resistance adjustment. The Gravity DS1307 RTC module uses Gravity I2C interface and you can plug it on the DFRobot Gravity IO expansion shield directly. Cooperate with Arduino DS1307 library developed by DFRobot, it is easy to realize functions like setting time and time display. It can be widely used in DA (Data Acquisition).

Specification

Board Overview

Num Label Description
1 VCC 5V
2 GND GND
3 SCL I2C-Clock
4 SDA I2C-Data
5 SQ SQ
6 VCC 5V
7 GND GND
8 SCL I2C-Clock
9 SDA I2C-SDA

Tutorial

In this tutorial, you can set and read time.

Requirements

Connection Diagram

Gravity: I2C SD2405 RTC Module Arduino Connection Diagram

Sample Code

Please download DFRobot DS1307 RTC library. How to install Libraries in Arduino IDE

Note: #define updata_flag 0 //1 updata time,0 only show time
 /***************************************************
 * Real Time Clock Module
 * ****************************************************
 * How to apply the DS1307 clock module.
 * @author Dongzi(1185787528@qq.com)
 * @version  V1.0
 * @date  2017-08-21
 GNU Lesser General Public License.
 See <http://www.gnu.org/licenses/> for details.

 * All above must be included in any redistribution
 * ****************************************************/
 #include <Wire.h>
 #include <DS1307.h>
 #define updata_flag 0 //1 updata time,0 only show time
 //Modify the following data
 #define TIME_YR    17
 #define TIME_MTH   8
 #define TIME_DATE  21
 #define TIME_DOW   1
 #define TIME_HR    0
 #define TIME_MIN   1
 #define TIME_SEC   0
 char* str[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};//week
 int rtc[7];
 void showtime()     //
   {
    RTC.get(rtc,true);
   {
    Serial.print( rtc[6]);   /*YEAR MONTH DATE*/
    Serial.print("-");
    Serial.print( rtc[5]);
    Serial.print("-");
    Serial.println( rtc[4]);

    Serial.print( rtc[2]); /*HOUR  MIN SEC */
    Serial.print(":");
    Serial.print( rtc[1]);
    Serial.print(":");
    Serial.println( rtc[0]);

    Serial.println( str[rtc[3]-1]); /********WEEK*****/
    Serial.println("**********");
    }
   }
 void setup()
 {  Serial.begin(9600);
   Wire.begin();

   if(updata_flag)
  { Serial.println(" OldTime:  ");
   showtime();
    RTC.stop();

    RTC.set(DS1307_SEC,TIME_SEC); //---Update time----
    RTC.set(DS1307_MIN,TIME_MIN);
    RTC.set(DS1307_HR,TIME_HR);
    RTC.set(DS1307_DOW,TIME_DOW);
    RTC.set(DS1307_DATE,TIME_DATE);
    RTC.set(DS1307_MTH,TIME_MTH);
    RTC.set(DS1307_YR,TIME_YR);
    RTC.start();
    Serial.println(" SetTime:  ");
    showtime();
   }
 }
 void loop()
 { if(updata_flag==0)
     showtime();    //Output data from serial port
    delay(1000);
 }

Expected Results

DFR0151_Time_Setting.png

Appendix: EEPROM IIC Address Setting

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents

DFshopping_car1.png Get Gravity: I2C DS1307 RTC Module from DFRobot Store or DFRobot Distributor.

Turn to the Top