# \[Solved\] How to fix ESP8266 crash when connected to RTC DS1302?

**URL:** <https://forum.arduino.cc/t/solved-how-to-fix-esp8266-crash-when-connected-to-rtc-ds1302/636959>\
**Category:** General Guidance\
**Created:** [February 15, 2020, 9:22pm UTC](https://forum.arduino.cc/t/solved-how-to-fix-esp8266-crash-when-connected-to-rtc-ds1302/636959 "2020-02-15T21:22:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DryRun](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dryrun/32/238796_2.png) [@DryRun](https://forum.arduino.cc/u/DryRun)\
**Post date:** [February 15, 2020, 9:22pm UTC](https://forum.arduino.cc/t/solved-how-to-fix-esp8266-crash-when-connected-to-rtc-ds1302/636959/1 "2020-02-15T21:22:47Z")

</div>

Hello,

I have managed to set up and have the code working when the RTC DS1302 module is connected to an Arduino UNO, but i want to improve the project with Wi-Fi so i am trying to replace the UNO with a NodeMCU 1.0 ESP-12E but the same code crashes the ESP8266. The sketch turns on a relay for 40s every hour. I think that maybe it's a problem with the RTC library that i'm using or maybe i need to add some extra library?

![ds1302-real-time-clock-module-connections-600x315.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/a/b/a/aba8dbd11bce610b02db62d3010ba6e6e8c2fdb6.jpeg)

Here is my complete sketch which works fine for the UNO:

```cpp
#include <virtuabotixRTC.h> // DS1302 RTC module library

// Creation of the Real Time Clock Object
virtuabotixRTC myRTC(5, 6, 7);  // Wiring of the RTC (CLK,DAT,RST)

int setMinutes = 0, setSeconds = 0; // set minutes and seconds for pump activation
long pumpRelayTime = 40000; //set pump operation time in ms. int datatype can only hold max value 32767.
const int pumpRelay = 8;  // set pump relay pin

unsigned long interval = 2000;  // print RTC time every 2s
unsigned long time_now = 0;

void setup() {
  Serial.begin(9600); // open serial port and set the baud rate
  Serial.println("Automated pump relay control with RTC (Fixed Reset)");
  Serial.println(" **************************************************");
  pinMode(pumpRelay, OUTPUT); // set digital pin pumpRelay as an output
  
  // Set the current date, and time in the following format:
  // seconds, minutes, hours, day of the week, day of the month, month, year
  myRTC.setDS1302Time(50, 59, 19, 5, 26, 1, 2020); // uncomment line, upload to reset RTC and then comment, upload.
  
  myRTC.updateTime(); // update of variables for time or accessing the individual elements.
  
  // Start printing elements as individuals                                                                 
  Serial.print("Running from preset RTC Date / Time: ");                                                                  
  Serial.print(myRTC.dayofmonth);                                                                         
  Serial.print("/");                                                                                      
  Serial.print(myRTC.month);                                                                              
  Serial.print("/");                                                                                      
  Serial.print(myRTC.year);
  Serial.print(" ");                                                                                      
  Serial.print(myRTC.hours);                          
  Serial.print(":");                                                                                      
  Serial.print(myRTC.minutes);                                                                            
  Serial.print(":");                                                                                      
  Serial.println(myRTC.seconds); 
}

void loop() {
  myRTC.updateTime(); // update of variables for time or accessing the individual elements.                                                                                 

  // Start printing RTC time elements as individuals                                                                   
  if (millis() - time_now >= interval)  // non-blocking method. prints RTC time every 2 seconds.
  {
    time_now = millis();
    Serial.print("RTC Time: ");                                                                                                                                                    
    Serial.print(myRTC.hours);                                                                              
    Serial.print(":");                                                                                      
    Serial.print(myRTC.minutes);                                                                            
    Serial.print(":");                                                                                      
    Serial.println(myRTC.seconds);
  }
  if (myRTC.minutes == setMinutes && myRTC.seconds == setSeconds)
  {
    Serial.print("Pump activated at: ");
    Serial.print(myRTC.hours);  // display the current hour from RTC module                                                                              
    Serial.print(":");                                                                                      
    Serial.print(myRTC.minutes);  // display the current minutes from RTC module                                                                              
    Serial.print(":");                                                                                           
    Serial.println(myRTC.seconds);  // display the seconds from RTC module  
                                                                                   
    digitalWrite(pumpRelay, HIGH);  //turns on the pump relay
        
    Serial.println(" ***Pump relay turned ON***");
    Serial.print("Pump operation time: ");
    Serial.print(pumpRelayTime / 1000); // calculate time of operation in seconds      
    Serial.println(" seconds");
    delay(pumpRelayTime); // pump relay operation time
    digitalWrite(pumpRelay, LOW); // turn off the pump relay
    Serial.println(" ***Pump relay turned OFF***");                                                                                                                    
  }
}

```

![Node-MCU-ESP-12E-Pin-Out-Diagram2.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/4/b/e/4be2ec39e7dbf6c9b7b622ec63c0592aae3beff9.jpeg)

For the NodeMCU, in the Arduino IDE, the same code compiled and uploaded with no errors. The only changes are the GPIO pins. Maybe i should use different pins?

```cpp
virtuabotixRTC myRTC(10, 13, 15);  // Wiring of the RTC (CLK,DAT,RST)
const int pumpRelay = 9;  // set pump relay pin

```

But when i open the Serial Monitor, i get this repeating error:

```cpp
21:33:24.465 -> 
21:33:24.465 ->  ets Jan  8 2013,rst cause:4, boot mode:(3,2)
21:33:24.512 -> 
21:33:24.512 -> wdt reset
21:33:24.512 -> load 0x4010f000, len 1392, room 16 
21:33:24.512 -> tail 0
21:33:24.512 -> chksum 0xd0
21:33:24.512 -> csum 0xd0
21:33:24.512 -> v3d128e5c
21:33:24.512 -> ~ld
21:33:24.559 ->

```

![ds1302-real-time-clock-module-connections-600x315.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/a/b/a/aba8dbd11bce610b02db62d3010ba6e6e8c2fdb6.jpeg)

![Node-MCU-ESP-12E-Pin-Out-Diagram2.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/4/b/e/4be2ec39e7dbf6c9b7b622ec63c0592aae3beff9.jpeg)

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [February 15, 2020, 9:37pm UTC](https://forum.arduino.cc/t/solved-how-to-fix-esp8266-crash-when-connected-to-rtc-ds1302/636959/2 "2020-02-15T21:37:14Z")

</div>

Possibly there is a collision, or smiliar, between pins, timers, interrupts,.... when using NodeMCU 1.0 ESP-12E. Libraries… yes, possible.

What about continue using the well working UNO and add a Wifi device to the UNO?

---

<div class="post-metadata">

**Author:** ![DryRun](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dryrun/32/238796_2.png) [@DryRun](https://forum.arduino.cc/u/DryRun)\
**Post date:** [February 15, 2020, 9:41pm UTC](https://forum.arduino.cc/t/solved-how-to-fix-esp8266-crash-when-connected-to-rtc-ds1302/636959/3 "2020-02-15T21:41:20Z")

</div>

> Railroader:  
> Possibly there is a collision, or smiliar, between pins, timers, interrupts,.... when using NodeMCU 1.0 ESP-12E. Libraries… yes, possible.
> 
> What about continue using the well working UNO and add a Wifi device to the UNO?

I want to replace the UNO with the ESP8266 as i don't want to 'lose' my currently only one Arduino UNO into this project which will be a permanent or long-term setup. The NodeMCU should be perfectly capable of running this project on its own and it has built-in Wi-Fi which makes the final setup more compact with less parts and decreases the overall cost of the project. I can't understand why the code doesn't work. Hopefully someone with some more experience with the ESP8266 can enlighten me. ☹

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [February 15, 2020, 9:45pm UTC](https://forum.arduino.cc/t/solved-how-to-fix-esp8266-crash-when-connected-to-rtc-ds1302/636959/4 "2020-02-15T21:45:53Z")

</div>

There are surely several skilled helpers knowing a lot more that can find out. Buying a second UNO clone does not cost much so that is like an emergncy exit in my opinion.

---

<div class="post-metadata">

**Author:** ![DryRun](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dryrun/32/238796_2.png) [@DryRun](https://forum.arduino.cc/u/DryRun)\
**Post date:** [February 15, 2020, 10:08pm UTC](https://forum.arduino.cc/t/solved-how-to-fix-esp8266-crash-when-connected-to-rtc-ds1302/636959/5 "2020-02-15T22:08:32Z")

</div>

So, i changed the pin configuration to the following based on another DS1302 library that i downloaded from the Arduino IDE Library Manager and it is no longer crashing but then i could not set the time on the RTC, so i connected the VCC and GND pins of the RTC to the NodeMCU and now everything seems to work properly:

```cpp
virtuabotixRTC myRTC(5, 4, 2);  // Wiring of the RTC (CLK,DAT,RST)
const int pumpRelay = 14;  // set pump relay pin

```

Here is the Serial Monitor output:

```cpp
22:05:29.037 -> Automated pump relay control with RTC (Fixed Reset)
22:05:29.105 -> **************************************************
22:05:29.138 -> Running from preset RTC Date / Time: 26/1/2020 19:59:50
22:05:30.957 -> RTC Time: 19:59:51
22:05:32.983 -> RTC Time: 19:59:53
22:05:34.967 -> RTC Time: 19:59:55
22:05:36.957 -> RTC Time: 19:59:57
22:05:38.975 -> RTC Time: 19:59:59
22:05:39.042 -> Pump activated at: 20:0:0
22:05:39.075 -> ***Pump relay turned ON***
22:05:39.075 -> Pump operation time: 40 seconds
22:06:19.022 -> ***Pump relay turned OFF***
22:06:19.055 -> RTC Time: 20:0:40
22:06:21.053 -> RTC Time: 20:0:42
22:06:23.028 -> RTC Time: 20:0:44
22:06:25.033 -> RTC Time: 20:0:46
22:06:27.039 -> RTC Time: 20:0:48

```

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [February 15, 2020, 10:12pm UTC](https://forum.arduino.cc/t/solved-how-to-fix-esp8266-crash-when-connected-to-rtc-ds1302/636959/6 "2020-02-15T22:12:12Z")

</div>

How do You pwr the UNO and what devices get their pwr from the UNO? A diagram showing the powering of all Your stuff could be good to see.

---

<div class="post-metadata">

**Author:** ![sandandstars](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@sandandstars](https://forum.arduino.cc/u/sandandstars)\
**Post date:** [February 22, 2020, 10:18am UTC](https://forum.arduino.cc/t/solved-how-to-fix-esp8266-crash-when-connected-to-rtc-ds1302/636959/7 "2020-02-22T10:18:50Z")

</div>

When using the DS1302 library with ESP8266 you need to specify the GPIO numbers, not the digital pin numbers. So: DS1302 RTC(14, 12, 13);

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 7:09pm UTC](https://forum.arduino.cc/t/solved-how-to-fix-esp8266-crash-when-connected-to-rtc-ds1302/636959/8 "2021-05-05T19:09:00Z")

</div>


