loggingarduino-unosd-cardreal-time-clock

arduino "Compilation error: 'class DateTime' has no member named 'get'"


I have the arduino uno r3 and the adafruit data logger sheild (https://learn.adafruit.com/adafruit-data-logger-shield/using-the-real-time-clock-3).

Below is my code, however when I try to compile I get 'Compilation error: 'class DateTime' has no member named 'get''.

Is there other libraries I should be using? I think it is something with the SD.h library, as I am also getting an error using the logfile.writeError() function

/*
The (UNO) circuit:
Define Uno digital pin 2 as RX - connect to TFMini TX (brown)
Define Uno digital pin 3 as TX - connect to TFMini RX (blue)
GND - TFMini black
5V - TFMini red
*/

#include "SoftwareSerial.h"
#include "TFMini.h"
#include "RTClib.h"
#include "SD.h"
#include <Wire.h>

#define LOG_INTERVAL  1000 // milliseconds between sensor readings
#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()

// Setup software serial port 
SoftwareSerial Serial1(2,3); //define software serial port name as Serial1 and define pin2 as RX and pin3 as TX
TFMini tfmini;

// DATA LOGGER
RTC_DS1307 RTC; // define the Real Time Clock object
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const int chipSelect = 10; // for the data logging shield, we use digital pin 10 for the SD cs line
File logfile; // the logging file

void error(char *str)
// prints out the error to the Serial Monitor, turns on the red error LED
// and then sits in a while(1); loop forever, also known as a halt
{
  Serial.print("error: ");
  Serial.println(str);
  
  // red LED indicates error
  // digitalWrite(redLEDpin, HIGH);
  
  while(1);
}

void setup() 
{
  // Step 1: Initialize hardware serial port (serial debug port)
  Serial.begin(9600); //set bit rate of serial port connecting Arduino with computer
  while (!Serial); // wait for serial port to connect. Needed for native USB port only                                                                
  Serial.println ("Initializing TF03 LiDAR...");

  // Step 2: Initialize the data rate for the SoftwareSerial port (set bit rate of serial port connecting LiDAR with Arduino)
  Serial1.begin(TFMINI_BAUDRATE);

  // Step 3: Initialize the TF Mini sensor
  tfmini.begin(&Serial1);  

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

  // Initialize the SD card
  Serial.print("\nInitializing SD card...");
  pinMode(10, OUTPUT); // make sure that the default chip select pin is set to output, even if you don't use it

  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }

  Serial.println("card initialized.");
  
  // create a new file
  char filename[] = "LOGGER00.CSV";
  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);

  // kick off the RTC by initializing the Wire library and poking the RTC to see if its alive.
  Wire.begin();  
  if (!RTC.begin()) {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }

  // Print the header (first line of the file)
  // helps your spreadsheet or math program identify whats coming up next. 
  // The data is in CSV (comma separated value) format so the header is too: "millis,time" 
  // The first item millis is milliseconds since the Arduino started, 
  // Time is the time and date from the RTC
  // The logfile.print() call is what writes data to our file on the SD card, 
  // it works pretty much the same as the Serial version
  logfile.println("millis,time,distance,strength");    
#if ECHO_TO_SERIAL
  Serial.println("millis,time,distance,strength");
#endif
#if ECHO_TO_SERIAL// attempt to write out the header to the file
   if (logfile.writeError || !logfile.sync()) {
     error("write header");
   }
#endif
 
}

void loop() 
{

  DateTime now; 

  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));

  // 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
  logfile.print(now.get()); // seconds since 2000
  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);
#if ECHO_TO_SERIAL
  Serial.print(now.get()); // seconds since 2000
  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);
#endif //ECHO_TO_SERIAL

  // Take one TF Mini distance measurement
  uint16_t dist = tfmini.getDistance();
  uint16_t strength = tfmini.getRecentSignalStrength();
  // log ditance and signal strength
  logfile.print(", ");    
  logfile.print(dist); // cm
  logfile.print(", ");    
  logfile.println(strength);
#if ECHO_TO_SERIAL
  Serial.print(", ");   
  Serial.print(dist);
  Serial.print(" cm      sigstr: ");
  // Serial.print(", ");    
  Serial.println(strength);
#endif //ECHO_TO_SERIAL

}

Solution

  • The Adafruit tutorial seems to be outdated.
    .get was removed from the library in May 2010.
    And the example on GitHub was changed to use .unixtime() in June 2010.
    And the proper method for "seconds since 2000" is .secondstime().

    So change now.get() to now.secondstime() or just remove it.