I tried out this code (from this website):
#include <DS3231.h>
DS3231 rtc(SDA, SCL);
void setup(){
rtc.begin();
rtc.setDOW(WEDNESDAY);
rtc.setTime(12, 0, 0);
rtc.setDate(1, 1, 2014);
Serial.begin(9600);
rtc.begin();
pinMode(lm35_pin, INPUT);
pinMode(chip_select_pin, OUTPUT);
if (SD.begin()){
Serial.println("Initialization Successful. Ready to use");
}
else{
Serial.println("Initialization failed. Check your pin connections or change your SD card");
return;
}
}
#include <SD.h>
#include <SPI.h>
#include <DS3231.h>
File data_file;
DS3231 rtc(SDA, SCL);
const int lm35_pin = A0;
int temperature;
int chip_select_pin = 10;
void loop() {
temperature = analogRead(lm35_pin);
temperature = (temperature*500)/1023;
data_file = SD.open("test.txt", FILE_WRITE);
if (data_file) {
Serial.print(rtc.getTimeStr());
data_file.print(rtc.getTimeStr());
Serial.print(",");
data_file.print(",");
Serial.println(temperature);
data_file.println(temperature);
data_file.close();
}
else {
Serial.println("error opening your SD card file. Try again");
}
delay(3000);
}
and got these error messages:
Arduino: 1.8.5 (Windows 7), Board: "Arduino/Genuino Uno"
WARNING: Category 'Real-time clock' in library DS3231 is not valid. Setting to 'Uncategorized'
sketch_dec19a:2: error: no matching function for call to 'DS3231::DS3231(const uint8_t&, const uint8_t&)'
DS3231 rtc(SDA, SCL);
^
C:\Users\cnagel\AppData\Local\Temp\arduino_modified_sketch_121604\sketch_dec19a.ino:2:21: note: candidates are:
In file included from C:\Users\cnagel\AppData\Local\Temp\arduino_modified_sketch_121604\sketch_dec19a.ino:1:0:
C:\Users\cnagel\Documents\Arduino\libraries\DS3231/DS3231.h:64:3: note: DS3231::DS3231()
DS3231();
^
C:\Users\cnagel\Documents\Arduino\libraries\DS3231/DS3231.h:64:3: note: candidate expects 0 arguments, 2 provided
C:\Users\cnagel\Documents\Arduino\libraries\DS3231/DS3231.h:60:7: note: constexpr DS3231::DS3231(const DS3231&)
class DS3231 {
^
C:\Users\cnagel\Documents\Arduino\libraries\DS3231/DS3231.h:60:7: note: candidate expects 1 argument, 2 provided
C:\Users\cnagel\Documents\Arduino\libraries\DS3231/DS3231.h:60:7: note: constexpr DS3231::DS3231(DS3231&&)
C:\Users\cnagel\Documents\Arduino\libraries\DS3231/DS3231.h:60:7: note: candidate expects 1 argument, 2 provided
C:\Users\cnagel\AppData\Local\Temp\arduino_modified_sketch_121604\sketch_dec19a.ino: In function 'void setup()':
sketch_dec19a:5: error: 'class DS3231' has no member named 'begin'
rtc.begin();
^
sketch_dec19a:6: error: 'class DS3231' has no member named 'setDOW'
rtc.setDOW(WEDNESDAY);
^
sketch_dec19a:6: error: 'WEDNESDAY' was not declared in this scope
rtc.setDOW(WEDNESDAY);
^
sketch_dec19a:7: error: 'class DS3231' has no member named 'setTime'
rtc.setTime(12, 0, 0);
^
sketch_dec19a:8: error: no matching function for call to 'DS3231::setDate(int, int, int)'
rtc.setDate(1, 1, 2014);
^
C:\Users\cnagel\AppData\Local\Temp\arduino_modified_sketch_121604\sketch_dec19a.ino:8:25: note: candidate is:
In file included from C:\Users\cnagel\AppData\Local\Temp\arduino_modified_sketch_121604\sketch_dec19a.ino:1:0:
C:\Users\cnagel\Documents\Arduino\libraries\DS3231/DS3231.h:94:8: note: void DS3231::setDate(byte)
void setDate(byte Date);
^
C:\Users\cnagel\Documents\Arduino\libraries\DS3231/DS3231.h:94:8: note: candidate expects 1 argument, 3 provided
sketch_dec19a:11: error: 'class DS3231' has no member named 'begin'
rtc.begin();
^
sketch_dec19a:12: error: 'lm35_pin' was not declared in this scope
pinMode(lm35_pin, INPUT);
^
sketch_dec19a:13: error: 'chip_select_pin' was not declared in this scope
pinMode(chip_select_pin, OUTPUT);
^
sketch_dec19a:14: error: 'SD' was not declared in this scope
if (SD.begin()){
^
C:\Users\cnagel\AppData\Local\Temp\arduino_modified_sketch_121604\sketch_dec19a.ino: At global scope:
sketch_dec19a:28: error: redefinition of 'DS3231 rtc'
DS3231 rtc(SDA, SCL);
^
C:\Users\cnagel\AppData\Local\Temp\arduino_modified_sketch_121604\sketch_dec19a.ino:2:9: note: 'DS3231 rtc' previously declared here
DS3231 rtc(SDA, SCL);
^
C:\Users\cnagel\AppData\Local\Temp\arduino_modified_sketch_121604\sketch_dec19a.ino: In function 'void loop()':
sketch_dec19a:39: error: 'class DS3231' has no member named 'getTimeStr'
Serial.print(rtc.getTimeStr());
^
sketch_dec19a:40: error: 'class DS3231' has no member named 'getTimeStr'
data_file.print(rtc.getTimeStr());
^
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.
I'm really new to Arduino, but it seems like most of the problems come from the library. Does anyone know how to fix this? Thank you!
Also, I looked on some other forums and found that someone had a similar problem that was fixed by adding the DS3231 file to the library folder. I had the file in the library folder, and am still having problems.