HOME    PROJECTS    LIBRARIES    RESOURCES    LINKS    CONTACT  
Select category:
Arduino
  DS1302
  DS1307
  DS3231
  DS3234
  KeyPad
  LCD5110_Basic
  LCD5110_Graph
  LCD5110_SPIflash
  LEDmatrix7219
  MCP4725
  MGLCD
  OLED_I2C
  OLED_SPIflash
  OLED_StatusIcons
  relay8
  SPIflash
  tinyFAT
  URTouch
  UTFT
  UTFT_Buttons
  UTFT_Geometry
  UTFT_SPIflash
  UTFT_tinyFAT
  WiiChuck
chipKit
TI LaunchPad

IF YOU LIKE,
and use any of my projects or libraries, and would like to encourage further development you can donate through PayPal here:

Rather donate hardware directly? Then click here.





Library: DS1307

This library was made because I wanted an easy way to interface and use the DS1307 I²C Real-Time Clock without the need for the Wire library.

DS1307DS1307 pinoutMy Arduino running the DS1307_LCD Demo

The DS1307 serial real-time clock (RTC) is a low-power, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I²C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator, but the library only supports the 24-hour mode. The DS1307 has a built-in power-sense circuit that detects power failures and automatically switches to the backup supply. Timekeeping operation continues while the part operates from the backup supply.

 IMPORTANT: 

The library has not been tested in combination with the Wire library and I have no idea if they can share pins. Do not send me any questions about this. If you experience problems with pin-sharing you can move the DS1307 SDA and SCL pins to any available pins on your development board. This library will in this case fall back to a software-based, TWI-/I2C-like protocol which will require exclusive access to the pins used.

Download:

DS1307.zip
(Filesize is 373.64 KiB. Downloaded 33590 times)


A few demos are included to demonstrate most of the functions.
This is a multi-platform library that will work with several different development board types.

Latest changes:
v2.013 Feb 2016added begin()
  added getUnixTime()
  added support for Arduino Due, Arduino Leonardo, Bobuino and chipKit
  added support for hardware I2C (all platforms)
  modified setDOW() to calculate DOW from RTC date if desired
  fixed a bug that made the library freeze when using D0 for SDA
  fixed a bug in getMonthStr() and getDOWStr()
For a full list of changes please see the file version.txt included in the download.

Nice to know:

The DS1307 is a 5 volt device and operating it at 3.3 volt may cause issues. If you experience issues communicating with the DS1307 the first thing you should do is make sure it is running at 5 volts. Remember to use proper level shifters for the SDA and SCL lines if you are using a development board running at 3.3 volts.

This library will default to I2C Fast Mode (400 KHz) when using the hardware I2C interface.

I highly recommend using the DS3231 (or DS3232) instead of the DS1307. While the DS3231/DS3232 may be slightly more expensive than the DS1307 it is much more accurate due to the internal TCXO (temperature-compensated crystal oscillator) and crystal. This also means that you don’t have to use an external crystal like you have to with the DS1307.

Datasheet:

CLICK HERE TO VIEW

Compatibility:

WorkingArduino Duemilanove w/ATmega328
WorkingArduino Uno
WorkingArduino Leonardo
WorkingArduino Mega
WorkingArduino Mega2560
WorkingArduino Due
WorkingBobuino
Not tested, UnsupportedTeensy 3.x
Working = Working   Not working: Not working
Not tested, Unsupported = Not tested, Unsupported

Manual:

CLICK HERE TO VIEW
The manual is included in the download

License:

By downloading the library you accept the following license:
Creative Commons BY-NC-SA Logo
Creative Commons (CC BY-NC-SA 3.0)
View SummaryView Legal