DS1307RTC tmElements_t tm errors

I am having problems reading and setting the time on DS3231 rtc using DS1307RTC which was working but now giving the error message ‘tmElements_t tm was not declared in this scope’. I have installed the latest DS1307RTC,Time, and TimeLib sketches, and have been onto the forum looking for answers but to no avail, having tried what other have suggested to fix the problem. Included is the error message that was generated when the program was compiled. This problem has caused many a sleepless night looking for an answer. Many thanks for any help that can be given.

Arduino: 1.8.7 (Windows 10), Board: "Arduino Nano, ATmega328P"

IC:\\Users\\John\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.2\\libraries\\Wire\\src" "-IC:\\Users\\John\\Documents\\Arduino\\libraries\\TimeLib-master" "-IC:\\Users\\John\\Documents\\Arduino\\libraries\\DS1307RTC-master" "C:\\Users\\John\\AppData\\Local\\Temp\\arduino_build_666812\\sketch\\ReadTest.ino.cpp" -o "C:\\Users\\John\\AppData\\Local\\Temp\\arduino_build_666812\\sketch\\ReadTest.ino.cpp.o"
In file included from C:\Users\John\AppData\Local\Temp\arduino_modified_sketch_408790\ReadTest.ino:4:0:

C:\Users\John\Documents\Arduino\libraries\DS1307RTC-master/DS1307RTC.h:19:22: error: 'tmElements_t' has not been declared

     static bool read(tmElements_t &tm);

                      ^~~~~~~~~~~~

C:\Users\John\Documents\Arduino\libraries\DS1307RTC-master/DS1307RTC.h:20:23: error: 'tmElements_t' has not been declared

     static bool write(tmElements_t &tm);

                       ^~~~~~~~~~~~

C:\Users\John\AppData\Local\Temp\arduino_modified_sketch_408790\ReadTest.ino: In function 'void loop()':

ReadTest:15:3: error: 'tmElements_t' was not declared in this scope

   tmElements_t tm;

   ^~~~~~~~~~~~

ReadTest:17:18: error: expected primary-expression before ')' token

   if (RTC.read(tm)) {

                  ^

ReadTest:19:20: error: expected primary-expression before '.' token

     print2digits(tm.Hour);

                    ^

ReadTest:21:20: error: expected primary-expression before '.' token

     print2digits(tm.Minute);

                    ^

ReadTest:23:20: error: expected primary-expression before '.' token

     print2digits(tm.Second);

                    ^

ReadTest:25:20: error: expected primary-expression before '.' token

     Serial.print(tm.Day);

                    ^

ReadTest:27:20: error: expected primary-expression before '.' token

     Serial.print(tm.Month);

                    ^

ReadTest:29:37: error: expected primary-expression before '.' token

     Serial.print(tmYearToCalendar(tm.Year));

                                     ^

ReadTest:29:18: error: 'tmYearToCalendar' was not declared in this scope

     Serial.print(tmYearToCalendar(tm.Year));

                  ^~~~~~~~~~~~~~~~

Multiple libraries were found for "TimeLib.h"
 Used: C:\Users\John\Documents\Arduino\libraries\TimeLib-master
 Not used: C:\Users\John\Documents\Arduino\libraries\Time-master
Using library Wire at version 1.0 in folder: C:\Users\John\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\libraries\Wire 
Using library TimeLib-master at version 2.1.0 in folder: C:\Users\John\Documents\Arduino\libraries\TimeLib-master 
Using library DS1307RTC-master at version 1.4.1 in folder: C:\Users\John\Documents\Arduino\libraries\DS1307RTC-master 
exit status 1
'tmElements_t' was not declared in this scope

Please post the code that causes the error

Code

#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>

void setup() {
  Serial.begin(9600);
  while (!Serial) ; // wait for serial
  delay(200);
  Serial.println("DS1307RTC Read Test");
  Serial.println("-------------------");
}

void loop() {
  tmElements_t tm;

  if (RTC.read(tm)) {
    Serial.print("Ok, Time = ");
    print2digits(tm.Hour);
    Serial.write(':');
    print2digits(tm.Minute);
    Serial.write(':');
    print2digits(tm.Second);
    Serial.print(", Date (D/M/Y) = ");
    Serial.print(tm.Day);
    Serial.write('/');
    Serial.print(tm.Month);
    Serial.write('/');
    Serial.print(tmYearToCalendar(tm.Year));
    Serial.println();
  } else {
    if (RTC.chipPresent()) {
      Serial.println("The DS1307 is stopped.  Please run the SetTime");
      Serial.println("example to initialize the time and begin running.");
      Serial.println();
    } else {
      Serial.println("DS1307 read error!  Please check the circuitry.");
      Serial.println();
    }
    delay(9000);
  }
  delay(1000);
}

void print2digits(int number) {
  if (number >= 0 && number < 10) {
    Serial.write('0');
  }
  Serial.print(number);
}

used was DS1307RTC both the Read Test and Set Time

Please post a link to where you downloaded the DS1307RTC library from.

The error code supplied was from the ‘Read Test’ this is the sketch within DS1307RTC.

Code was from GitHub Paul Stoffregen/DS1307RTC.

Here’s the problem:

baseump:

Multiple libraries were found for "TimeLib.h"

Used: C:\Users\John\Documents\Arduino\libraries\TimeLib-master
Not used: C:\Users\John\Documents\Arduino\libraries\Time-master

The DS1307RTC is written to use the Time library, but you have this other TimeLib library installed that’s getting used instead. If you delete C:\Users\John\Documents\Arduino\libraries\TimeLib-master the error will be fixed.

A post on the forum said that TimeLib was to be used instead of Time. If you look at the sketch it uses TimeLib not Time, has Time been upgraded to add TimeLib to Time.

baseump: A post on the forum said that TimeLib was to be used instead of Time.

Almost certainly the post said that TimeLib*.h* was to be used instead of Time*.h* TimeLib.h is the filename. The library name is Time: https://github.com/PaulStoffregen/Time/blob/master/TimeLib.h

The library you have installed named TimeLib is something completely different, I'm not really sure what it is, but it won't work with the DS1307RTC library.

baseump: has Time been upgraded to add TimeLib to Time.

A file named TimeLib.h was added to the Time library: https://github.com/PaulStoffregen/Time/commit/26cd0c85095d5dbfffded0831abb2f7abaad0469#diff-39b21c10fc453d4e59444bec0b936f4e This was necessary because a file named time.h was added to the toolchain and on filename case-insensitive operating systems like Windows the #include directive for Time.h was ending up using time.h from the toolchain instead of the intended Time.h from the Time library. So it was necessary to add a uniquely named file to the Time library to avoid any ambiguity over which file was being referenced.

Anyway, you can keep doubting what I say, or you can just give it a try and get on with your project. The choice is yours.

SOLVED. Thank you for your answers and help, I deleted TimeLib and now I can update my RTC's.

You're welcome. I'm glad to hear it's working now. Enjoy! Per