Adafruit Feather M0 RTC Error

Hey guys so I am working on this project to record sensor data. I keep getting this string of error messages and I am not sure what they mean

#include <RTClib.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>

// test

#define LOG_INTERVAL  1000 // ms

#define SYNC_INTERVAL 1000 // write data every sec
uint32_t syncTime = 0;

#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()
int LickDuration1 = 0;
int LickNumber1 = 0;
int LickDuration2 = 0;
int LickNumber2 = 0;
int LOG_INTERVAL_TIMER = 0;
unsigned long previousMillis = 0;

// the digital pins that connect to the LEDs
#define lick1 1  //Lick 1
#define lick2 2  //Lick 1

RTC_DS1307 RTC; // define the Real Time Clock object

// SD line on pin 10
const int chipSelect = 10;

// the logging file
File logfile;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  while (1);
}

File dataFile;                      // variable for SD
char filename[]  = "00000000.CSV";  // filemame array for datalogger
char logString[] = "000000000000";  // build a string for the event log

DateTime now = RTC.now();
void getFilename()
{
  sprintf(filename, "%04d%02d%02d", now.year(), now.month(), now.day());
}

void logEvent(int sw)
{
  DateTime();
  {
    getFilename();
    File dataFile = SD.open(filename, FILE_WRITE);
    if (dataFile)                                                   // if the file is available, write to it:
    {
      sprintf(logString, "%02d,%02d,%02d,%02d", sw,
              now.hour(), now.minute(), now.second());
      dataFile.println(logString);
      dataFile.close();                                           // close the file after writing
    }
  }
}

void setup(void)
{
  Serial.begin(9600);
  Serial.println();


#if WAIT_TO_START
  Serial.println("Type any character to start");
  while (!Serial.available());
#endif //WAIT_TO_START

  // initialize the SD card
  Serial.print("Initializing SD card...");
  // default chip select pin is set to output
  pinMode(10, OUTPUT);
  pinMode(7, INPUT);

  // check initialization:
  if (!SD.begin(chipSelect)) {
    error("Card failed, or not present");
  }
  Serial.println("card initialized.");

  // create a new file
  char filename[] = "LOGGER00.CSV"; //To do, get this to be datestamp
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i / 10 + '0';
    filename[7] = i % 10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE);
      break;  // leave the loop!
    }
  }

  if (! logfile) {
    error("couldnt create file");
  }

  Serial.print("Logging to: ");
  Serial.println(filename);

  // connect to RTC
  Wire.begin();
  if (!RTC.begin()) {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }

  logfile.println("millis,stamp,datetime,LickNumber1,LickDuration1,LickNumber2,LickDuration2");
#if ECHO_TO_SERIAL
  Serial.println("millis,stamp,datetime,LickNumber1,LickDuration1,LickNumber2,LickDuration2");
#endif //ECHO_TO_SERIAL

  // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);
}

void loop(void)
{
  DateTime now;
  //Reset lick variables and timer
  LOG_INTERVAL_TIMER = 0;
  LickNumber1 = 0;
  LickDuration1 = 0;
  LickNumber2 = 0;
  LickDuration2 = 0;
  unsigned long currentMillis = millis();
  previousMillis = currentMillis;

  while (currentMillis < (previousMillis + LOG_INTERVAL)) {
    currentMillis = millis();

    if (digitalRead(lick1) == LOW) {
      LickDuration1 += 1;
      delay (1);
      if (digitalRead(lick1) == HIGH) {
        LickNumber1 += 1;
      }
    }
    if (digitalRead(lick2) == LOW) {
      LickDuration2 += 1;
      delay (1);
      if (digitalRead(lick2) == HIGH) {
        LickNumber2 += 1;
      }
    }
  }

  // log milliseconds since starting
  uint32_t m = millis();
  logfile.print(m);           // milliseconds since start
  logfile.print(", ");
#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");
#endif

  // fetch the time
  now = RTC.now();
  // log time
  void LogLick();
  logfile.print(now.unixtime()); // seconds since 1/1/1970
  logfile.print(", ");
  logfile.print('"');
  logfile.print(now.year(), DEC);
  logfile.print("/");
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);
  logfile.print('"');
#if ECHO_TO_SERIAL
  Serial.print(now.unixtime()); // seconds since 1/1/1970
  Serial.print(", ");
  Serial.print('"');
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
  Serial.print('"');
#endif //ECHO_TO_SERIAL
  logfile.print(", ");
  logfile.print(LickNumber1);
  logfile.print(", ");
  logfile.print(LickDuration1);
  logfile.print(", ");
  logfile.print(LickNumber2);
  logfile.print(", ");
  logfile.print(LickDuration2);

#if ECHO_TO_SERIAL
  Serial.print(", ");
  Serial.print(LickNumber1);
  Serial.print(", ");
  Serial.print(LickDuration1);
  Serial.print(", ");
  Serial.print(LickNumber2);
  Serial.print(", ");
  Serial.print(LickDuration2);
#endif //ECHO_TO_SERIAL

  logfile.println();
#if ECHO_TO_SERIAL
  Serial.println();
#endif // ECHO_TO_SERIAL

  // write data to disk
  if ((millis() - syncTime) < SYNC_INTERVAL) return;
  syncTime = millis();
}

"Arduino: 1.8.9 (Mac OS X), Board: “Adafruit Feather M0”

In file included from /Users/asanthosh/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69:0,
from /Users/asanthosh/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/samd.h:105,
from /Users/asanthosh/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/sam.h:540,
from /Users/asanthosh/Library/Arduino15/packages/adafruit/hardware/samd/1.3.0/cores/arduino/Arduino.h:48,
from sketch/adafruit_edited.ino.cpp:1:
/Users/asanthosh/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:487:38: error: expected ‘)’ before ‘*’ token
#define RTC ((Rtc )0x40001400UL) /< \brief (RTC) APB Base Address /
^
/Users/asanthosh/Desktop/adafruit_edited/adafruit_edited.ino:26:12: note: in expansion of macro ‘RTC’
RTC_DS1307 RTC; // define the Real Time Clock object
^
/Users/asanthosh/Library/Arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:487:38: error: expected ‘)’ before '
’ token
#define RTC ((Rtc *)0x40001400UL) /
< \brief (RTC) APB Base Address /
^
/Users/asanthosh/Desktop/adafruit_edited/adafruit_edited.ino:26:12: note: in expansion of macro ‘RTC’
RTC_DS1307 RTC; // define the Real Time Clock object
^
adafruit_edited:45:20: error: request for member ‘now’ in ‘1073746944u’, which is of pointer type 'Rtc
’ (maybe you meant to use ‘->’ ?)
DateTime now = RTC.now();
^
/Users/asanthosh/Desktop/adafruit_edited/adafruit_edited.ino: In function ‘void setup()’:
adafruit_edited:111:12: error: request for member ‘begin’ in ‘1073746944u’, which is of pointer type 'Rtc
’ (maybe you meant to use ‘->’ ?)
if (!RTC.begin()) {
^
adafruit_edited:124:27: error: invalid conversion from ‘int’ to ‘eAnalogReference {aka _eAnalogReference}’ [-fpermissive]
analogReference(EXTERNAL);

^
/Users/asanthosh/Desktop/adafruit_edited/adafruit_edited.ino: In function ‘void loop()’:
adafruit_edited:168:13: error: request for member ‘now’ in ‘1073746944u’, which is of pointer type ‘Rtc*’ (maybe you meant to use ‘->’ ?)
now = RTC.now();
^
exit status 1
request for member ‘now’ in ‘1073746944u’, which is of pointer type ‘Rtc*’ (maybe you meant to use ‘->’ ?)

the name RTC is already used in SAMD header files.

change the name of the RTC variable to rtc or use #undef RTC before RTC_DS1307 RTC

Hmm I tried both and Im still getting the same error messages

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"

// test

#define LOG_INTERVAL  1000 // ms

#define SYNC_INTERVAL 1000 // write data every sec
uint32_t syncTime = 0;

#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()
int LickDuration1 = 0;
int LickNumber1 = 0;
int LickDuration2 = 0;
int LickNumber2 = 0;
int LOG_INTERVAL_TIMER = 0;
unsigned long previousMillis = 0;

// the digital pins that connect to the LEDs
#define lick1 1  //Lick 1
#define lick2 2  //Lick 1
RTC_DS1307 rtc; // define the Real Time Clock object

// SD line on pin 10
const int chipSelect = 10;

// the logging file
File logfile;

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
  while (1);
}

File dataFile;                      // variable for SD
char filename[]  = "00000000.CSV";  // filemame array for datalogger
char logString[] = "000000000000";  // build a string for the event log

DateTime now = rtc.now();
void getFilename()
{
  sprintf(filename, "%04d%02d%02d", now.year(), now.month(), now.day());
}

void logEvent(int sw)
{
  DateTime();
  {
    getFilename();
    File dataFile = SD.open(filename, FILE_WRITE);
    if (dataFile)                                                   // if the file is available, write to it:
    {
      sprintf(logString, "%02d,%02d,%02d,%02d", sw,
              now.hour(), now.minute(), now.second());
      dataFile.println(logString);
      dataFile.close();                                           // close the file after writing
    }
  }
}

void setup(void)
{
  Serial.begin(9600);
  Serial.println();


#if WAIT_TO_START
  Serial.println("Type any character to start");
  while (!Serial.available());
#endif //WAIT_TO_START

  // initialize the SD card
  Serial.print("Initializing SD card...");
  // default chip select pin is set to output
  pinMode(10, OUTPUT);
  pinMode(7, INPUT);

  // check initialization:
  if (!SD.begin(chipSelect)) {
    error("Card failed, or not present");
  }
  Serial.println("card initialized.");

  // create a new file
  char filename[] = "LOGGER00.CSV"; //To do, get this to be datestamp
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i / 10 + '0';
    filename[7] = i % 10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE);
      break;  // leave the loop!
    }
  }

  if (! logfile) {
    error("couldnt create file");
  }

  Serial.print("Logging to: ");
  Serial.println(filename);

  // connect to rtc
  Wire.begin();
  if (!rtc.begin()) {
    logfile.println("rtc failed");
#if ECHO_TO_SERIAL
    Serial.println("rtc failed");
#endif  //ECHO_TO_SERIAL
  }

  logfile.println("millis,stamp,datetime,LickNumber1,LickDuration1,LickNumber2,LickDuration2");
#if ECHO_TO_SERIAL
  Serial.println("millis,stamp,datetime,LickNumber1,LickDuration1,LickNumber2,LickDuration2");
#endif //ECHO_TO_SERIAL

  // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);
}

void loop(void)
{
  DateTime now;
  //Reset lick variables and timer
  LOG_INTERVAL_TIMER = 0;
  LickNumber1 = 0;
  LickDuration1 = 0;
  LickNumber2 = 0;
  LickDuration2 = 0;
  unsigned long currentMillis = millis();
  previousMillis = currentMillis;

  while (currentMillis < (previousMillis + LOG_INTERVAL)) {
    currentMillis = millis();

    if (digitalRead(lick1) == LOW) {
      LickDuration1 += 1;
      delay (1);
      if (digitalRead(lick1) == HIGH) {
        LickNumber1 += 1;
      }
    }
    if (digitalRead(lick2) == LOW) {
      LickDuration2 += 1;
      delay (1);
      if (digitalRead(lick2) == HIGH) {
        LickNumber2 += 1;
      }
    }
  }

  // log milliseconds since starting
  uint32_t m = millis();
  logfile.print(m);           // milliseconds since start
  logfile.print(", ");
#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(", ");
#endif

  // fetch the time
  now = rtc.now();
  // log time
  void LogLick();
  logfile.print(now.unixtime()); // seconds since 1/1/1970
  logfile.print(", ");
  logfile.print('"');
  logfile.print(now.year(), DEC);
  logfile.print("/");
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);
  logfile.print('"');
#if ECHO_TO_SERIAL
  Serial.print(now.unixtime()); // seconds since 1/1/1970
  Serial.print(", ");
  Serial.print('"');
  Serial.print(now.year(), DEC);
  Serial.print("/");
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
  Serial.print('"');
#endif //ECHO_TO_SERIAL
  logfile.print(", ");
  logfile.print(LickNumber1);
  logfile.print(", ");
  logfile.print(LickDuration1);
  logfile.print(", ");
  logfile.print(LickNumber2);
  logfile.print(", ");
  logfile.print(LickDuration2);

#if ECHO_TO_SERIAL
  Serial.print(", ");
  Serial.print(LickNumber1);
  Serial.print(", ");
  Serial.print(LickDuration1);
  Serial.print(", ");
  Serial.print(LickNumber2);
  Serial.print(", ");
  Serial.print(LickDuration2);
#endif //ECHO_TO_SERIAL

  logfile.println();
#if ECHO_TO_SERIAL
  Serial.println();
#endif // ECHO_TO_SERIAL

  // write data to disk
  if ((millis() - syncTime) < SYNC_INTERVAL) return;
  syncTime = millis();
}

new error:
/Users/asanthosh/Desktop/adafruit_edited/adafruit_edited.ino: In function ‘void setup()’:
adafruit_edited:123:27: error: invalid conversion from ‘int’ to ‘eAnalogReference {aka _eAnalogReference}’ [-fpermissive]
analogReference(EXTERNAL);
^
In file included from /Users/asanthosh/Library/Arduino15/packages/adafruit/hardware/samd/1.3.0/cores/arduino/Arduino.h:91:0,
from sketch/adafruit_edited.ino.cpp:1:
/Users/asanthosh/Library/Arduino15/packages/adafruit/hardware/samd/1.3.0/cores/arduino/wiring_analog.h:54:13: error: initializing argument 1 of ‘void analogReference(eAnalogReference)’ [-fpermissive]
extern void analogReference( eAnalogReference ulMode ) ;
^
exit status 1
invalid conversion from ‘int’ to ‘eAnalogReference {aka _eAnalogReference}’ [-fpermissive]

analogReference is AVR specific command

https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/

I changed it then got this error:

Users/asanthosh/Desktop/adafruit_edited/adafruit_edited.ino: In function 'void setup()':
adafruit_edited:123:26: error: invalid conversion from 'int' to 'eAnalogReference {aka _eAnalogReference}' [-fpermissive]
analogReference(DEFAULT);
^
In file included from /Users/asanthosh/Library/Arduino15/packages/adafruit/hardware/samd/1.3.0/cores/arduino/Arduino.h:91:0,
from sketch/adafruit_edited.ino.cpp:1:
/Users/asanthosh/Library/Arduino15/packages/adafruit/hardware/samd/1.3.0/cores/arduino/wiring_analog.h:54:13: error: initializing argument 1 of 'void analogReference(eAnalogReference)' [-fpermissive]
extern void analogReference( eAnalogReference ulMode ) ;
^
exit status 1
invalid conversion from 'int' to 'eAnalogReference {aka _eAnalogReference}' [-fpermissive]

for SAMD it is AR_DEFAULT. but simply remove the line, if you want the default

Thank you it seems to be working now