Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

DS3231 breakout board problem
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

DS3231 breakout board problem

by gpierson2019 on Thu Feb 20, 2020 3:26 pm

Hi, I'm trying to troubleshoot a problem I have with a DS3231. See attached pics. I have it connected to an UNO and it lost about 3 min overnight from about 9:00 pm to noon the next day. This is the second time it happened. It happened the night before and I thought it was just a fluke so it's happening consistently. On both nights it lost around 2:45 to 3:00 min each night.

So trying to figure it out. Note: I can remove power and the board retains time just fine so my battery is good.

This last night I kept the board powered from the UNO and didn't reboot the UNO nor did I unplug the DS3231 and it still lost power.

I have "adjust time" commented out so it's not a matter of me resetting the time by accident in my code. See code below.

Please advise,
Thanks

Code: Select all | TOGGLE FULL SIZE
#include "RTClib.h"
RTC_DS3231 rtc;

int buttonState = 0;         // variable for reading the pushbutton status
const int buttonPin = 2;     // the number of the pushbutton pin
char days[7][10] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const int ledPin =  13;
int strike_hours[10] = {9,10,11,12,13,14,15,16,17,18};
int number_of_strikes = 0;


void strike_bell() {
  number_of_strikes = 0;
  DateTime now = rtc.now();
  number_of_strikes = number_of_strikes + now.hour();
  if (now.hour() >= 13) {
    number_of_strikes = number_of_strikes - 12;
  }

  for(int y = 0; y < number_of_strikes; y++){
      digitalWrite(ledPin, HIGH);
      delay(100);
      digitalWrite(ledPin, LOW);
      delay(2000);
  }

 
}


void setup () {
  Serial.begin(9600);
  rtc.begin();
  pinMode(ledPin, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
  pinMode(buttonPin, INPUT);  // initialize the pushbutton pin as an input:
  //rtc.adjust(DateTime(2020, 02, 19, 17, 9, 00));
 
}


void loop () {

DateTime now = rtc.now();
for(int x = 0; x < 10; x++) {
  if (now.hour() == strike_hours[x] && now.minute() == 00 && now.second() == 00) {
         strike_bell();   // strike the bell
         delay(1); 
         } else {
         digitalWrite(ledPin, LOW);  // keep LED off:
  }
 
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(" (");
    Serial.print(days[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();
    Serial.print("Temperature: ");
    Serial.print(rtc.getTemperature());
    Serial.println(" C");
    Serial.println();
    delay(100);

buttonState = digitalRead(buttonPin);
    if (buttonState == HIGH) {
        digitalWrite(ledPin, HIGH);
        delay(100);
        digitalWrite(ledPin, LOW);
        delay(1);
             } else {
          digitalWrite(ledPin, LOW); // keep LED low
          delay(1);
  }


}
}
Attachments
IMG_4245.jpg
IMG_4245.jpg (262.39 KiB) Viewed 110 times

gpierson2019
 
Posts: 11
Joined: Sun Jun 02, 2019 9:45 pm

Please be positive and constructive with your questions and comments.