Using Arduino MEGA and RTC_DS3231
I am using the code below :
#include "RTClib.h"
#include <TM1637Display.h>
// Define the connections pins for TM1637 4 digit 7 segment display
#define CLK 3
#define DIO 2
//Initialization of
RTC_DS3231 rtc;
TM1637Display display = TM1637Display(CLK, DIO);
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int displayshow;
void setup () {
Serial.begin(9600);
//Define display's brightness.
display.setBrightness(0x0f);
// Gives a warning if RTC doen not start.
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
//If RTC's battery is over. Print the warning on Serial window.
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was
//compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to
//set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}
void loop () {
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[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();
//Show minutes and seconds on TM1637. Get the minutes, multiply by 100
//and add seconds to appear on display.
displayshow=(now.minute()*100)+now.second();
//This function serves to show displayshow variable with colon on the
//middle. The second argument between parentheses is the colon and the
//false serves to not put zeros on non-used digits.
display.showNumberDecEx(displayshow,0b11100000,false);
//If minute is lower than 10, must put a zero in front of it.
if(now.minute()<10){
//In this function, the first argument is the number that must show,
//the second is the quantity of digits that must change and the third
//is the position on display from 1 to 4.
display.showNumberDec(0,0,1);
//This command must be called again to not disappear when shows the
//aditional zero.
display.showNumberDec(displayshow,0b11100000,false);
}
//Show hours and minutes on TM1637.
/*displayshow=(now.hour()*100)+now.minute();
display.showNumberDecEx(displayshow,0b11100000,false);
//If hour is lower than 10, must be put a zero in front of it.
if(now.hour()<10){
display.showNumberDec(0,0,1);
display.showNumberDec(displayshow,0b11100000,false);
}*/
Serial.println();
delay(1000);
}
On Serial Print the system is displaying a perfect Real Time Clock
But on TM 1637 display unit there is a big uncertainty in the result all the time but not the correct one ever
Sometimes
5:35
or 50:75
and so on and on