1307 rtc and sd, how do you timestamp?

I want to time stamp events that occur dependent upon a variety of inputs how feasible is this?

I keep having issues such as:

request for member 'year' in 'now' is of non-class type 'time_t() {aka long unsigned int()}'

I saw a github for logging sensor readings using a command:

logfile.print(now.second(), DEC);

I thought I could use this to display all my different time and date information but my compiler did not understand yet I have provided the same libraries as the one with the example.

it says logfile was not declared in this scope.

Can someone please help I am not the most experienced with programming.

You better post your code, instead of explaining problems which have to be fixed somewhere else.
If you use classes, also provide links to the libraries or class declarations.

In above case the reason of the error is a missing or wrong declaration, in your global variables. You can not simply add lines of code from various projects, without declaring and initializing the objects used by these statements. For each class, you have to

  • add the class header: #include <someClass.h>
  • then create an object: someClass myObject();
  • eventually initialize it in setup(): myObject.begin();
    before you can reference myObject somwhere down in your code.

I got it working and it created a file and logged dates.

Now I am in a position where it is not creating the file.

This is the function:

void logtime()
char filename = “LOGGER00.CSV”;
logfile = SD.open(filename, FILE_WRITE);

if (! logfile)
Serial.println(“couldnt create file”);

Serial.print("Logging to: ");

DateTime now = RTC.now();
// log time
logfile.print(now.year(), DEC);
logfile.print(now.month(), DEC);
logfile.print(now.day(), DEC);
logfile.print(" “);
logfile.print(now.hour(), DEC);
logfile.print(now.minute(), DEC);
logfile.print(now.second(), DEC);
Serial.println(“Data Logged”);

it keeps returning couldn’t create file.

These are in the code

#include <Time.h>
#include <TimeLib.h>
#include <Wire.h>
#include “RTClib.h”
#include <SPI.h>
#include <SD.h>
File logfile;

const int chipSelect = 4;

There is a bunch of other stuff going on so I won’t send the entire program.

Essentially it goes to a point where it is monitoring the frequency of signals sent to a digital pin and they select different cases. The case calls the logtime function you can see above. The function is not creating the file, it was previously but unsure what is different now.

It might possibly be because you are not declaring the file properly and Arduino cannot read your mind. Neither can we and, since that is normally in the setup and you are keeping that secret, I guess we will never know.

Its all working now, sorry I would share more but I am not allowed.