Hello All,
I am working on a program to log IR sensor data to an SD card with a timestamp using a DS3231 RTC, I have finally gotten the code to verify but gives an error stating "Error compiling for board Arduino Mega or Mega2560" as well as:
"In file included from C:\Users\jacob\OneDrive\Documents\Arduino\ReadWritei\ReadWritei.ino:7:0:
C:\Users\jacob\OneDrive\Documents\Arduino\libraries\DS3231/DS3231.h:27:7: error: redefinition of 'class DateTime'
class DateTime {
^~~~~~~~
In file included from C:\Users\jacob\OneDrive\Documents\Arduino\ReadWritei\ReadWritei.ino:4:0:
C:\Users\jacob\OneDrive\Documents\Arduino\libraries\RTClib/RTClib.h:81:7: note: previous definition of 'class DateTime'
class DateTime {
^~~~~~~~
"
I have no clue what is causing this error, and there is not much documentation on any of the libraries I am using, if any of you smart guys and gals can point me in the "Write" direction (couldn't help myself) it would be much obliged, I will post the entirety of my code at the bottom.
Thank you in advanced.
#include <Time.h>
#include <TimeLib.h>
#include <RTClib.h>
#include <Time.h>
#include <TimeLib.h>
#include <DS3231.h> // Include the library
#include <SPI.h>
#include <SD.h>
#define SENSOR 23 // define pint 2 for sensor
#define ACTION 22 // define pin 9 as for ACTION
File myFile;
//RTC_DS3231 rtc;
RTC_DS3231 rtc;
String TimeString() {
DateTime now = rtc.now();
String theyear = String(now.year(), DEC);
String mon = String(now.month(), DEC);
String theday = String(now.day(), DEC);
String thehour = String(now.hour(), DEC);
String themin = String(now.minute(), DEC);
//Put all the time and date strings into one String
String dataString = String( theyear + "/" + mon + "/" + theday + ", " + thehour + ":" + themin);
return dataString;
}
// the setup function runs once when you press reset or power the board
void setup() {
// E18-D80NK Obstacle Sensor Code by Robojax.com 2018022
Serial.begin(9600);// setup Serial Monitor to display information
pinMode(SENSOR, INPUT_PULLUP);// define pin as Input sensor
pinMode(ACTION, OUTPUT);// define pin as OUTPUT for ACTION
rtc.begin();
if (! rtc.begin()) {//verifies RTC begins
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
}
// the loop function runs over and over again until power down or reset
void loop () {
Serial.print ( "Initializing SD card..." );
if (!SD.begin ( 53 )) {//change pin number
Serial.println ( "initialization failed!" );
while (1);
}
Serial.println ( "initialization done." );
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open ( "test.txt", FILE_WRITE );
int L = digitalRead(SENSOR); // read the sensor
if (L == LOW) {
digitalWrite(ACTION, HIGH);
// if the file opened okay, write to it:
if (myFile) {
Serial.print ( "Writing to test.txt..." );
Serial.print (TimeString());
myFile.print("Cat Passed at: ");
myFile.print (TimeString());
// close the file:
myFile.close ();
Serial.println ( "done." );
delay(500);
}
} else {
Serial.println(" === All clear");
digitalWrite(ACTION, LOW); // turn the relay OFF
}
}