I don't believe I am accessing the RTC DS1307 but rather addressing the UNO and reading its "own clock".
I say this because I can "setTime" (in setup) and display the time correctly for hours, BUT, if I reset the UNO the time resorts back to my original "setTime" value.
I chose DS1302RTC.h because I believe that I can manipulate time elements individually.
I don't think the RTC has made any contribution to my sketch!
I have included relevant code segments:
/*
* These are snippets from my (LONG) sketch, I have only included the relevant RTC sections.
*/
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>
// ----------------------------------------------------------------------------
void setup(void) {
delay(500);
// Manual RTC set
// uncomment to setTime & RTC.set(now() for first time download - hrs and mins only!
// format is: setTime(hour(),minute(),second(),day(),month(), year());
setTime(8,17,1,1,1, 1); // only interested in HH MM
RTC.set(now()); // sending the onboard time to the RTC
// !!! this updates my TFTLCD display correctly with 08:17
if (time_t timeNow = now())
{ tft.println(" RTC success!");}
else
{tft.setTextColor(RED);
tft.println(" RTC failed!");}
// !!! never fails?
// ----------------------------------------------------------------------------
void loop(void)
{
CheckButtons(); // check time adjust buttons every 500mS
if (LoopTick > 0) // test 1 minute timer
{LoopTick --;}
if (LoopTick == 0)
{ TFTupdate(); // update display every minute
LoopTick = 120;
}
delay(500); // 120 x 500mS = 1 minute
}
// !!! No apparent problem
// ----------------------------------------------------------------------------
// Update display every minute
void TFTupdate()
{
time_t timeNow = now();
tft.fillScreen(BLACK);
tft.setCursor(0, 50);
tft.setFont(&FreeSansBold18pt7b);
tft.setTextSize(2);
tft.print(" ") ;
if (hour(timeNow) < 10)
{tft.print(" ");} // leading space for hours
tft.print(hour(timeNow), DEC);
tft.print(":") ;
if (minute(timeNow) < 10)
{tft.print("0");} // leading 0 for minutes
tft.print(minute(timeNow), DEC);
}
// !!! Display updates correctly
// ----------------------------------------------------------------------------
void CheckButtons()
{
time_t timeNow = now();
uint8_t NewHr = hour(timeNow);
uint8_t NewMn = minute(timeNow);
if (digitalRead(But_Hrs) == LOW) // read Hour adj
{ NewHr ++;
setTime(NewHr, minute(), 1, 1, 1, 1);
RTC.set(now());
LoopTick = 1; // 0,5 secs to restore display
}
if (digitalRead(But_Mins) == LOW) // read Min adj
{ NewMn ++;
setTime(hour(), NewMn, 1, 1, 1, 1);
RTC.set(now());
LoopTick = 1; // 0,5 secs to restore display
}
}
// !!! Display updates correctly
I have searched far and wide and often find examples which can't even compile!
e.g. DS1302RTC.h/example/setTime.ino fails on 'tmElements_t' does not name a type.
Some examples switch between Time.h and TimeLib.h for one reason or the other.
My wife has threatened to trade me in if I lose any more hair! If you recognize my problem, please assist.