This website uses 'cookies' to give you the best, most relevant experience. Using this website means you're happy with this. read more Accept & Close
Start Games
Do It Yourself
DIY & Home Improvement

ESP8266 wiht DS1307 RTC, NV SRAM and Square-Wave output signal

ESP8266 wiht DS1307 RTC, NV SRAM and Square-Wave output signal
ESP8266 wiht DS1307 RTC, NV SRAM and Square-Wave output signal
The DS1307 is real time clock (RTC) with plus 56 bytes of NV SRAM. Address and data are
transferred serially through an I2C bus. Additional functionality is programmable
Square-Wave output signal. You can set four frequency (1Hz, 4kHz, 8kHz, 32kHz) on the SQW/OUT pin.

Step 1: Components

Step 2: Connect the DS1307 to ESP8266

Connect the DS1307 to ESP8266
Schematic diagram of connecting ESP8266 with DS1307

Step 3: Setup frequency on the SQW/OUT pin

To set the frequency, use this function:
DS1307 Square-Wave output signal 1hz
DS1307 Square-Wave output signal 1hz
DS1307 Square-Wave output signal 4096hz
DS1307 Square-Wave output signal 4096hz
DS1307 Square-Wave output signal 8192hz
DS1307 Square-Wave output signal 8192hz
DS1307 Square-Wave output signal 32768hz
DS1307 Square-Wave output signal 32768hz
#include #include #include "RTC_DS1307.h" RTC_DS1307 rtc; void setup() { Serial.begin(115200); Serial.println(""); Serial.println("START"); Wire.begin(); rtc.SQW( f32768hz ); } void loop() { }

Step 4: Setting the time on DS1307

#include #include #include "RTC_DS1307.h" RTC_DS1307 rtc; void setup() { Serial.begin(115200); Serial.println(""); Serial.println("START"); Wire.begin(); //byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year //Setting the time on DS1307 rtc.SetTime( 00, 40, 13, 1, 06, 03, 17 ); //rtc.SQW( f32768hz ); } void loop() { //Read time from DS1307 and display (You must be connected to the serial port to see results) rtc.DisplayTime(); //Convert time to unix timestamp long uts = rtc.UnixTimestamp(); Serial.println( uts ); delay(1000); }
DS1307 Unix timestamp
DS1307 Unix timestamp

Step 5: Write and read NV SRAM

DS1307 has 56 bytes of NV SRAM for general use. For example, you can store configuration data.
In our case, we write and read String.
Download library RTC_DS1307 for Arduino IDE
#include #include #include "RTC_DS1307.h" RTC_DS1307 rtc; void setup() { Serial.begin(115200); Serial.println(""); Serial.println("START"); Wire.begin(); //Write in NV SRAM rtc.WriteRAMStr(0, "http://geek.adachsoft.com/"); delay(500); //Read from NV SRAM String str = rtc.ReadRAMStr(0); Serial.println("RAM: " + str); } void loop() { }
DS1307 write and read NV SRAM
DS1307 write and read NV SRAM