0
\$\begingroup\$

The RTC module ZS-042 get suddenly reset and show default values (2000/0/0) with no possibility to change it no matter what. The reset can occur after uploading a new sketch (I'm using ESP32) or while running.

Just after I unplug the module from ESP32, reconnect it (SCL, SDA, VCC, GND) and upload new sketch it's back to operate normally.

The reset looks like:

enter image description here

The code:

#include <Wire.h>
#include "RTClib.h"
#include "WiFi.h"

const char* ssid     = "****";
const char* password = "*******";
const char* ntpServer = "pool.ntp.org";

RTC_DS3231 rtc; //class RTC_DS3231 

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", 
"Thursday", "Friday", "Saturday"};

void setup () {

  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.printf("Connecting to %s ", ssid);
  delay(1000);
  Serial.println("");

  configTime(0, 0, ntpServer);
  setenv("TZ", "IST-2IDT,M3.4.4/26,M10.5.0", 1);

  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("CONNECTED!");

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
}

void loop () {
  DateTime now = rtc.now();

  Serial.print(now.year());
  Serial.print('/');
  Serial.print(now.month());
  Serial.print('/');
  Serial.print(now.day());
  Serial.print(" (");
  Serial.print(now.dayOfTheWeek());
  Serial.print(") ");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();

 if (touchRead(15) < 10)    // touch pin 15 to update time & date
 {
  struct tm timeinfo;
  getLocalTime(&timeinfo);
  int day = timeinfo.tm_mday;
  int month = timeinfo.tm_mon + 1;
  int year = timeinfo.tm_year + 1900;
  Serial.println(day);
  Serial.println(month);
  Serial.println(year);
  rtc.adjust(DateTime(year, month, day, timeinfo.tm_hour, timeinfo.tm_min, 
  timeinfo.tm_sec));
  // begin Transmission with address 0x68 (DS3231_ADDRESS)
 }

 Serial.println();
 delay(1000);
 }

I'm using CR2032 3V and connect it to VCC=3.3V of the ESP.

I read that maybe the supply voltage is not sufficient but I'm not sure because usually it's work fine till the sudden reset occur (can occur once in a two weeks or more). I tried to connect VCC=5V without the battery and still the same problem (get reset once in a while).

\$\endgroup\$
2
  • \$\begingroup\$ I'm not sure I understand this line: "I'm using CR2032 3V and connect it to VCC=3.3V of the ESP" Your battery should be inserted in socket of the ZS-042 module, not on Vcc. Otherwise, the RTC should reset. \$\endgroup\$ – Sirac Apr 30 '19 at 9:57
  • \$\begingroup\$ The battery inserted to the socket, and the pins connected to ESP32 are SCL, SDA, VCC, GND. Still i get the strange values of 2000/0/0 without possibility to change it until i unplug the RTC from the ESP32 and reconnect it. \$\endgroup\$ – Electrician May 1 '19 at 15:05
0
\$\begingroup\$

Hi you must put time to eeprom.

// get the offset we stored our data from address zero
uint8_t address = RtcEeprom.GetMemory(0);
if (address != stringAddr)
{
   // Serial.print("address didn't match ");
   // Serial.println(address);
}

{
    // get the size of the data from address 1
    uint8_t count = RtcEeprom.GetMemory(1);
    uint8_t buff[64];

    // get our data from the address with the given size
    uint8_t gotten = RtcEeprom.GetMemory(address, buff, count);

    if (gotten != count ||
        count != sizeof(data) - 1) // remove the extra null terminator strings add
    {
        //Serial.print("something didn't match, count = ");
        //Serial.print(count, DEC);
        //Serial.print(", gotten = ");
        //Serial.print(gotten, DEC);
        //Serial.println();
    }
    //Serial.print("data read (");
    //Serial.print(gotten);
    //Serial.print(") = \"");
    for (uint8_t ch = 0; ch < gotten; ch++)
    {
        //Serial.print((char)buff[ch]);
    }
   
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.