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?
Here is my complete sketch which works fine for the UNO:
#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 ***");
}
}
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?
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:
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 ->