NodeMCU with RTC DS1307

I've Use DS1307RTC.H and TimeLib.h with Arduino Nano DS1307 RTC Module. It's working well. But I want to use RTC module with NodeMCU. But same sketch upload into Nodemcu. It's give this result

ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
vbc204a9b
~ld
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
vbc204a9b
~ld

How can i solve this. Where should be the wrong..?

#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>

void setup() {
Serial.begin(9600);
while (!Serial) ; // wait for serial
delay(200);
Serial.println("DS1307RTC Read Test");
Serial.println("-------------------");
}

void loop() {
tmElements_t tm;

if (RTC.read(tm)) {
Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(1000);
}

void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
}

Find an example of Wire.begin() for your particular NodeMCU board. it should go in setup().

If you are using an old version of the DS1307RTC library which already contains Wire.begin() in the constructor, then comment it out there or get a version of the library which is compatible with the ESP8266 module.

1 Like