How to use RTC DS1307Z (DS3231)

On Raspberry Pi 3 and later Rasbian OS information you must to enable the I2C hardware.

From terminal: sudo raspi-config

-select “5 interfacing option”
-select “P5 I2C”
-enable it

after that it is possible to configure the RTC IC with the terminal

  1. Login as root
  2. install i2c-tools apt-get install i2c-tools
  3. install libi2c-dev apt-get install libi2c-dev
  4. edit blacklist file nano /etc/modprobe.d/raspi-blacklist.conf
  5. Add # before blacklist spi-bcm2708
  6. Add # before blacklist i2c-bcm2708
  7. Edit nano /etc/modules
  8. Add rtc-ds1307
  9. Edit nano /etc/rc.local
  10. Add echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-0/new_device (Rasp Pi Revision 1) or echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device (Rasp Pi Revision 2 and B+)
  11. Add hwclock -s
  12. reboot

or with a compiled program. The DS1307Z (DS3231) is a device I2C, and then we must install i2c-tools and libi2c-dev before use it.