Go Down

Topic: Having some error with DS3231 AT24C32 IIC RTC and data logging (Read 69 times) previous topic - next topic

weifengtoh

Hi all, i am following the code shown below. however i am using arduino uno where i connect my SDA SCL to A4 and A5. But i can't seem to find what is wrong with this code. Pls help me. Thanks in advance

Code: [Select]

/*
 *  Arduino Temperature Data Logging
 * 
 *  by Dejan Nedelkovski, www.HowToMechatronics.com
 */
#include <SD.h>
#include <SPI.h>
#include <DS3231.h>
File myFile;
DS3231  rtc(SDA, SCL);
int pinCS = 10; // Pin 10 on Arduino Uno
void setup() {
   
  Serial.begin(9600);
  pinMode(pinCS, OUTPUT);
 
  // SD Card Initialization
  if (SD.begin())
  {
    Serial.println("SD card is ready to use.");
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
  rtc.begin();   
}
void loop() {
  Serial.print(rtc.getTimeStr());
  Serial.print(",");
  Serial.println(int(rtc.getTemp()));
 
  myFile = SD.open("test.txt", FILE_WRITE);
  if (myFile) {   
    myFile.print(rtc.getTimeStr());
    myFile.print(",");   
    myFile.println(int(rtc.getTemp()));
    myFile.close(); // close the file
  }
  // if the file didn't open, print an error:
  else {
    Serial.println("error opening test.txt");
  }
  delay(3000);
}


the error I faced is shown below

Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Uno"

Temperature_data_logging_with_RTC:10:21: error: no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'

 DS3231  rtc(SDA, SCL);

                     ^

In file included from C:\Users\ASUS\Desktop\Temperature_data_logging_with_RTC\Temperature_data_logging_with_RTC.ino:8:0:

C:\Users\ASUS\Documents\Arduino\libraries\DS3231/DS3231.h:64:3: note: candidate: DS3231::DS3231()

   DS3231();

   ^

C:\Users\ASUS\Documents\Arduino\libraries\DS3231/DS3231.h:64:3: note:   candidate expects 0 arguments, 2 provided

C:\Users\ASUS\Documents\Arduino\libraries\DS3231/DS3231.h:60:7: note: candidate: constexpr DS3231::DS3231(const DS3231&)

 class DS3231 {

       ^

C:\Users\ASUS\Documents\Arduino\libraries\DS3231/DS3231.h:60:7: note:   candidate expects 1 argument, 2 provided

C:\Users\ASUS\Documents\Arduino\libraries\DS3231/DS3231.h:60:7: note: candidate: constexpr DS3231::DS3231(DS3231&&)

C:\Users\ASUS\Documents\Arduino\libraries\DS3231/DS3231.h:60:7: note:   candidate expects 1 argument, 2 provided

C:\Users\ASUS\Desktop\Temperature_data_logging_with_RTC\Temperature_data_logging_with_RTC.ino: In function 'void setup()':

Temperature_data_logging_with_RTC:26:7: error: 'class DS3231' has no member named 'begin'

   rtc.begin();   

       ^

C:\Users\ASUS\Desktop\Temperature_data_logging_with_RTC\Temperature_data_logging_with_RTC.ino: In function 'void loop()':

Temperature_data_logging_with_RTC:29:20: error: 'class DS3231' has no member named 'getTimeStr'

   Serial.print(rtc.getTimeStr());

                    ^

Temperature_data_logging_with_RTC:31:26: error: 'class DS3231' has no member named 'getTemp'

   Serial.println(int(rtc.getTemp()));

                          ^

Temperature_data_logging_with_RTC:35:22: error: 'class DS3231' has no member named 'getTimeStr'

     myFile.print(rtc.getTimeStr());

                      ^

Temperature_data_logging_with_RTC:37:28: error: 'class DS3231' has no member named 'getTemp'

     myFile.println(int(rtc.getTemp()));

                            ^

Multiple libraries were found for "SD.h"
 Used: C:\Users\ASUS\Documents\Arduino\libraries\SD
 Not used: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\libraries\SD
exit status 1
no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'

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

cattledog

There are several libraries with the same name DS3231.h and different syntax.
The library you are using does not match the syntax you are using.

There should be library examples that came with with what you are using.

What is the source of the library you are using?

GolamMostafa

Try using
RTClib.h Library and
RTC_DS3231 rtc; //inside RTClib.h, there is a class named RTC_DS3231 from which rtc object is created

weifengtoh

I used the library provided in that website.

http://www.rinkydinkelectronics.com/library.php?id=73

cattledog

The RinkyDink DS3231.h library is not properly installed. It is not available through the library manger of the IDE, so likely something went wrong in your process.

In my experience on this board, people often experience problems using that library.

My preferred library is Jack Christensen's DS3232.h which works with the DS3231 as well. It integrates very well with the Time Library which is often useful and supports the alarm functions. It is also available through the library manager.

RTClib.h as recommended by GolamMostafa is also a good choice.

Go Up