Go Down

Topic: Not running sketch from the example! (Read 396 times) previous topic - next topic

sir_kimas

Not running sketch from the example! What could it be?


#include <Wire.h>
#include <Time.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);
}



Error.
Arduino\libraries\DS1307RTC\examples\ReadTest\ReadTest.ino: In function 'void loop()':

ReadTest:14: error: 'tmElements_t' was not declared in this scope

   tmElements_t tm;

   ^

ReadTest:16: error: expected primary-expression before ')' token

   if (RTC.read(tm)) {

                  ^

ReadTest:18: error: expected primary-expression before '.' token

     print2digits(tm.Hour);

                    ^

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

     print2digits(tm.Minute);

                    ^

ReadTest:22: error: expected primary-expression before '.' token

     print2digits(tm.Second);

                    ^

ReadTest:24: error: expected primary-expression before '.' token

     Serial.print(tm.Day);

                    ^

ReadTest:26: error: expected primary-expression before '.' token

     Serial.print(tm.Month);

                    ^

ReadTest:28: error: expected primary-expression before '.' token

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

                                     ^

ReadTest:28: error: 'tmYearToCalendar' was not declared in this scope

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

                                          ^

exit status 1
'tmElements_t' was not declared in this scope



Robin2

#1
Sep 14, 2016, 03:45 pm Last Edit: Sep 14, 2016, 03:46 pm by Robin2
Please modify your post and use the code button </>
Code: [Select]
so your code looks like this and is easy to copy to a text editor. See How to use the Forum

As far as I can see your code has failed to compile. It must compile and upload before you can say whether it runs or not.

On line 16 you have unbalanced brackets. That may be the cause of all the subsequent errors.

On line 14, you may have spelled or typed tmElements_t incorrectly. Programming is case-sensitive

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

OldSteve

#2
Sep 14, 2016, 03:49 pm Last Edit: Sep 14, 2016, 04:02 pm by OldSteve
With later versions of the IDE, you need to:-
Code: [Select]
#include <TimeLib.h>not
Code: [Select]
#include <Time.h>
Edit: Aside from that, your code compiles fine for me as it is.
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

OldSteve

I should have added, the current version of the "Time" library has been changed because of a conflict with the AVR "time.h" header. If you have an earlier version of the "Time" library, also upgrade to the current one, (which contains the "TimeLib.h" header).
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

INTP

Yep. Make it TimeLib.h and you'll be fine.

If you have a module with a battery, you likely don't have the right kind of battery so you'll need to modify the board a little to use normal CR2032s


OldSteve

Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

Go Up