ESP8266 Wiht DS1307 RTC, NV SRAM and Square-Wave Output Signal

by adachsoft in Circuits > Arduino

7454 Views, 14 Favorites, 0 Comments

ESP8266 Wiht DS1307 RTC, NV SRAM and Square-Wave Output Signal

ESP8266_and_DS1307.jpg
DS1307_desc.jpg

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.
Download library RTC_DS1307 for Arduino IDE

Components

  • ESP8266 12e V3
  • DS1307
  • Few wires

Connect the DS1307 to ESP8266

schematic.png

Setup Frequency on the SQW/OUT Pin

osc_32768hz.png
osc_1hz.png
osc_4096hz.png
osc_8192hz.png

To set the frequency, use this function:

  • rtc.SQW( f1hz );
  • rtc.SQW( f4096hz );
  • rtc.SQW( f8192hz );
  • rtc.SQW( f32768hz );

#include "ESP8266WiFi.h"

#include "Wire.h"

#include "RTC_DS1307.h" RTC_DS1307 rtc; void setup() { Serial.begin(115200); Serial.println(""); Serial.println("START"); Wire.begin(); rtc.SQW( f32768hz ); } void loop() { }

Setting the Time on DS1307

unix_timestamp.png

//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 );

In the loop we will read time from DS1307

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); }

Write and Read NV SRAM

NV_SRAM.png

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.

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() {
}

More interesting examples you can find here