SparkFun Forums 

Where electronics enthusiasts find answers.

Questions &/or issues related to products in the Qwiic category should be posted in this forum. To learn more about Qwiic, consider checking out our pillar page on the Qwiic system.
User avatar
By williamlynn
#204870
Im trying to set time on the qwiic RTV RV-1805.
The example codes work fine when setting to compiler time but when I try to set to specific time, the year does not update properly. For example when I put 2019 into the set time example it prints 2067; it is adding 48 years to the year.
Using the example codes and changing only "commenting out the compiler set time code and uncomment the set your own code". When I run the print time example I get 2066 as the year.
Thanks for you help.
Bill
Code: Select all
/*
  Setting time from the RV-1805 Real Time Clock
  By: Andy England
  SparkFun Electronics
  Date: 2/22/2017
  License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).

  Feel like supporting our work? Buy a board from SparkFun!
  https://www.sparkfun.com/products/14642

  This example shows how to set the time on the RTC to the compiler time or a custom time.

  Hardware Connections:
    Attach the Qwiic Shield to your Arduino/Photon/ESP32 or other
    Plug the RTC into the shield (any port)
    Open the serial monitor at 9600 baud
*/

#include <SparkFun_RV1805.h>

RV1805 rtc;

//The below variables control what the date will be set to
int hund = 50;
int sec = 2;
int minute = 18;
int hour = 7;
int date = 25;
int month = 6;
int year = 2018;
int day = 5;

void setup() {

  Wire.begin();

  Serial.begin(9600);
  Serial.println("Read Time from RTC Example");

  if (rtc.begin() == false) {
    Serial.println("Something went wrong, check wiring");
  }

  //Use the time from the Arduino compiler (build time) to set the RTC
  //Keep in mind that Arduino does not get the new compiler time every time it compiles. to ensure the proper time is loaded, open up a fresh version of the IDE and load the sketch.
  //if (rtc.setToCompilerTime() == false) {
  //  Serial.println("Something went wrong setting the time");
  //}
  
  //Uncomment the below code to set the RTC to your own time
  if (rtc.setTime(hund, sec, minute, hour, date, month, year, day) == false) {
    Serial.println("Something went wrong setting the time");
  }
  
  Serial.println("RTC online!");
}

void loop() {

}/code]
User avatar
By TS-Mark
#204888
Hi Bill,

Thanks for bringing this to our attention! It looks like there was an error in how the library was set up to handle that year input since the RTC is only set up to allow manual inputs for a specific year range. We have updated the library with a fix so try updating it to v1.0.4 either through the Library Manager tool in Arduino or by downloading it from the GitHub Repository and that function should work as expected.

Let us know if you run into any other issues regarding setting a manual time.
User avatar
By williamlynn
#204905
That fixed the year but now can you also fix the time.

If I use 1 thru 19 for the hour, the rtc accepts it. If I use 20 thru 24 the RTC sees it as 0 thru 4.

Appreciate your help
User avatar
By TS-Mark
#204979
Hi again Bill,

Sorry for the late reply here. It looks like that is related to how the control register for the hour input works for 12hr vs. 24hr setups. Basically, that register works for any input up to 20 and after that, will ignore the first decimal value in 21-23. We are going to update the library so the function handles it more gracefully than the quick fix I have for you.

The quick fix is to just set the RTC to 24hr mode when setting the time. Here is what that void setup would look like:
Code: Select all
void setup() {

  Wire.begin();

  Serial.begin(9600);
  Serial.println("Read Time from RTC Example");
  
  if (rtc.begin() == false) {
    Serial.println("Something went wrong, check wiring");
  }

  //Use the time from the Arduino compiler (build time) to set the RTC
  //Keep in mind that Arduino does not get the new compiler time every time it compiles. to ensure the proper time is loaded, open up a fresh version of the IDE and load the sketch.
  /*if (rtc.setToCompilerTime() == false) {
    Serial.println("Something went wrong setting the time");
  }
  */
  rtc.set24Hour();
  //Uncomment the below code to set the RTC to your own time
  if (rtc.setTime(hund, sec, minute, hour, date, month, year, day) == false) {
    Serial.println("Something went wrong setting the time");
  }
  
  Serial.println("RTC online!");
}
If you want to print your time on a 24hr clock, just make sure to include that "rtc.set24Hour();" function in your void setup. Otherwise, it will default to 12hr mode.