DS3231 clock, time on battery

Everything works when plugged into power, time does not continue when unplugged and, hopefully battery should be continuing the time. When I plug it back in later it just continues from where it left off in the time. Suggestions?
(And yes, it is a fresh battery)
I am using:

//Marios Ideas
//DS3231 Tutorial
//Using DS3232.h library
//Formating date and time with custom functions

#include <Wire.h>
#include <DS3231.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

int pause=1000;

DS3231 clock;
RTCDateTime dt;

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels


#define OLED_RESET     -1// Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
Serial.begin(9600);
    clock.begin();
  // Set sketch compiling time
    clock.setDateTime(__DATE__, __TIME__);
 
   // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  display.display(); //display initial Adafruit logo
    delay(2000); 

  // Clear the buffer
  display.clearDisplay(); 
  display.display();

}

String DayOfTheWeek(uint8_t Day){
  String DayText;
  if (Day==1)  DayText="Monday";
  if (Day==2)  DayText="Tuesday";
  if (Day==3)  DayText="Wednesday";
  if (Day==4)  DayText="Thursday";
  if (Day==5)  DayText="Friday";
  if (Day==6)  DayText="Saturday";
  if (Day==7)  DayText="Sunday";
  return DayText;
}



String DayMonthYear(uint8_t Day,uint8_t Month,uint16_t Year){
  String DayMonthYearText;
  if (Month==1)  DayMonthYearText="JAN ";
  if (Month==2)  DayMonthYearText="FEB ";
  if (Month==3)  DayMonthYearText="MAR ";
  if (Month==4)  DayMonthYearText="APR ";
  if (Month==5)  DayMonthYearText="MAY ";
  if (Month==6)  DayMonthYearText="JUN ";
  if (Month==7)  DayMonthYearText="JUL ";
  if (Month==8)  DayMonthYearText="AUG ";
  if (Month==9)  DayMonthYearText="SEP ";
  if (Month==10)  DayMonthYearText="OCT ";
  if (Month==11)  DayMonthYearText="NOV ";
  if (Month==12)  DayMonthYearText="DEC ";

  DayMonthYearText=DayMonthYearText+Day;
  if (Day==1)DayMonthYearText=DayMonthYearText+"st ";
  if (Day==2)DayMonthYearText=DayMonthYearText+"nd ";
  if (Day>2)DayMonthYearText=DayMonthYearText+"th ";

  DayMonthYearText=DayMonthYearText+Year;
  
  return DayMonthYearText;
}

String AddLeadingZero(uint8_t x){
  String AddLeadingZeroText;
  if(x<10) AddLeadingZeroText="0"; 
  else AddLeadingZeroText=""; 
  AddLeadingZeroText=AddLeadingZeroText+x;
  return AddLeadingZeroText;
}

String CurrentTime(uint8_t H, uint8_t I ){
  String CurrentTimeText="";
  CurrentTimeText=CurrentTimeText + AddLeadingZero(H) +":"+AddLeadingZero(I);
  return CurrentTimeText;
}

void loop() {
  dt = clock.getDateTime();

  display.fillRect(0,0,128,16,SSD1306_WHITE);
  display.fillRect(0,17,128,16,SSD1306_BLACK);
  display.fillRect(0,31,128,33,SSD1306_WHITE);

    display.setCursor(1,1); 
    display.setTextSize(2);
    display.setTextColor(SSD1306_BLACK); 
    display.println(DayOfTheWeek(dt.dayOfWeek));

  display.setCursor(1,18); 
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE); 
  display.println(DayMonthYear(dt.day,dt.month,dt.year));

    display.setCursor(3,35); 
    display.setTextSize(3);  
    display.setTextColor(SSD1306_BLACK); 
    display.println(CurrentTime(dt.hour,dt.minute));

  display.setCursor(100,35); 
  display.setTextSize(2);
  display.setTextColor(SSD1306_BLACK); 
  display.println(AddLeadingZero(dt.second));

  clock.forceConversion();
  display.setCursor(85,18); 
  display.setTextSize(1);
display.setTextColor(SSD1306_WHITE); 
display.print(clock.readTemperature());
display.setCursor(117,16); 
display.print("o");


  display.display();
  delay(1000);
}

Remove this line clock.setDateTime(__DATE__, __TIME__); ?

Hmmm... OK, I started over. Ran the sketch with the clock.set line to get the current time set. Then immediately loaded the sketch again without that line. Time still OK. Then disconnected from computer (power), waited a few minutes and plugged it into a normal 5 volt power source. Now it shows Jan 1st 2000 and time starting at 00.00.00.
So, I put it back the way it was, loaded sketch, and it displays everything correctly. Disconnected from computer, waited a few minutes to see if it will still keep time via the battery (as it should), then plugged into a 5 volt power source. The time just continues from where it left off when I disconnected from the computer! Not the correct time.

Can you post an annotated schematic showing how you actually connected it, be sure to include all connections, power, ground, power sources.

Yes I can but I think I may have found something else to try first , removing either the diode or resistor (or both) on the DS3231 charging circuit inasmuch as the battery is a non-rechargeable one. I'll let you know if that solves anything.



Fuzzy frizzys are not schematics, the language of electronics.

Sorry, with my pea brain it's the best I can do.

Removed diode fm DS3231 but made no difference, Sigh. Then also removed the resistor, still no difference.
I'll have to make a little video showing and explaining the problem/issues.

Get a new battery. You might have damaged it before you did the surgery.

I did test the battery with my multimeter and it appears fine but certainly wouldn't hurt to try a new one. Thanks.

Is it a CR2032 battery?
Does the LED on the DS3231 module light up?

LED on the DS3231 lights up when connected to power. Does not light up when disconnected from power and just, hopefully, on battery maintaining time. CR2032.
I'm making a video today- will send link when ready.

No hurry.
Did you happen to buy the module from AZ-Delivery?

Amazon, https://www.amazon.com/dp/B07Q7NZTQS?psc=1&ref=ppx_yo2ov_dt_b_product_details
So I do have a spare.

Don't take this as an insult but are you sure you have the battery in the right way?

Certainly not insulted, all help/ideas/suggestions welcome. Yes, positive side up. Just like in all the vids I've watched. It will be covered in the vid I'm working on.

I found the problem!
Forget the Vid

The battery pin is NOT soldered!

50

2 Likes

I noticed that a few days ago and soldered it.

Are you sure it's a good solder joint?
Have you checked continuity?
The other battery connector solder joint doesn't look all that good.
Why don't you re-solder both connections.

1 Like