Help me call this function

Hello if anyone can help me solve this problem. Im trying out a new library for a DS3234 on a mega. The library has no examples to use and Im pulling my hair out. The function I want to call is to set the date time.

#include <DS3234.h>
#include <SPI.h>
 int d = 22;
  int mo = 3;
  int y = 22;
  int h = 19;
  int mi = 15;
  int s = 0;


void setup() {
  // put your setup code here, to run once:
  RTC.configure(51,52,50,53);
  SPI.begin();
  Serial.begin(9600);



 RTC.setDateTime();
}

void loop() {
  // put your main code here, to run repeatedly:
RTC.readDateTime();


Serial.print("Time:  ") ; 
 
  if(RTC.time_h()>12){
   Serial.print(RTC.time_h()-12);
   Serial.print(":") ;
     if(RTC.time_m() < 10)
   Serial.print("0");
   Serial.print(RTC.time_m()) ;
   Serial.print(":") ;
  if(RTC.time_s() < 10)
   Serial.print("0");
   Serial.print(RTC.time_s()) ;
   Serial.println(" P.M.");
 }
   
 else if(RTC.time_h()<12){
  Serial.print(RTC.time_h());
  Serial.print(":");
    if(RTC.time_m() < 10)
   Serial.print("0");
   Serial.print(RTC.time_m()) ;
   Serial.print(":") ;
  if(RTC.time_s() < 10)
   Serial.print("0");
   Serial.print(RTC.time_s()) ;
   Serial.println(" A.M.");
   
  }

  Serial.print(RTC.readDateTime());
//  else if(Serial.print(RTC.time_h())){
//   Serial.print(":");
//   if(RTC.time_m() < 10)
//   Serial.print("0");
//   Serial.print(RTC.time_m()) ;
//   Serial.print(":") ;
//   if(RTC.time_s() < 10)
//   Serial.print("0");
//   Serial.print(RTC.time_s()) ;
//   Serial.println(" P.M.");
//}
//   Serial.print("Date:  ") ;
//   Serial.print(RTC.date_m()) ;
//   Serial.print("/") ;
//   Serial.print(RTC.date_d()) ;
//   Serial.print("/") ;
//   Serial.println(RTC.date_y()) ;

   delay(2000);
}  

The error that im getting is

Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Jesse\Documents\Arduino\MyReefController\MyReefController.ino: In function 'void setup()':

MyReefController:19:18: error: no matching function for call to 'DS3234::setDateTime()'

RTC.setDateTime();

              ^

In file included from C:\Users\Jesse\Documents\Arduino\MyReefController\MyReefController.ino:1:0:

C:\Users\Jesse\Documents\Arduino\libraries\DS3234-master/DS3234.h:8:8: note: candidate: void DS3234::setDateTime(int, int, int, int, int, int)

void setDateTime(int d, int mo, int y, int h, int mi, int s);

    ^~~~~~~~~~~

C:\Users\Jesse\Documents\Arduino\libraries\DS3234-master/DS3234.h:8:8: note: candidate expects 6 arguments, 0 provided

exit status 1

no matching function for call to 'DS3234::setDateTime()'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

The Library that Im using is found at
GitHub - OSBSS/DS3234: Used to Sync time in OSBSS dataloggers

Real simple solution im sure but i can not find the answer. Thank you all for help.

That is telling you that you need to supply those arguments to the function.

So:
setDateTime( d, mo, y, h, mi, s);

To set the time using your declared values.

You should only need to set it once, if I'm correct.

Once it is set with a good battery then yes you are correct. My new one has not showed up yet though.

the call
setDateTime( d, mo, y, h, mi, s);

will not compile

Post the new code.

Post the new error.

By changing it to
RTC.setDateTime( d, mo, y, h, mi, s);

it will now compile. However the serial monitor will not print out the correct time and date. If im doing that correctly.

#include <DS3234.h>
#include <SPI.h>
 


void setup() {
  // put your setup code here, to run once:
  RTC.configure(51, 50, 52, 53);
  SPI.begin();
  Serial.begin(9600);
int d = 5;
  int mo = 5;
  int y = 5;
  int h = 5;
  int mi = 5;
  int s = 0;
RTC.setDateTime(d, mo, y, h, mi, s);
}

void loop() {
  // put your main code here, to run repeatedly:
RTC.readDateTime();


//Serial.print("Time:  ") ; 
 
Serial.println(RTC.readDateTime());



   delay(2000);
}

Of which century? Try 2022.

1 Like

Lol. Oops. That was done out of frustration that it keeps returning 45’s and 85’s. None of the values are updating in the code and each time through the loop the seconds stay constant.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.