Trying to use a DS3232 RTC. Just a beguinner, very simple question.

Hi all!

This is my first post to the forum, I have generally ben able to work bits ot looking threw other threads and questions, but this simple little issue has me stumped..

Project end result wanted (not yet): Aquarium light dimmer. fade lights on/off over 2 hour periods.
eg:
start fading in at 7.30am : full brightness by 9.30am
start fade out at 5.30pm : fully off by 7.30pm

So far: already fading LEDs threw a constant current driver, using the PWM from the Uno, but now I would like to get the timing into the sketch.
(I have a main sketch that makes the aquarium lights fade on then off then on then off etc.. continuously - for practice - I just want to learn the RTC in a new sketch to work out its functionality and commands before I integrate it into the main sketch)

So all my question is = when trying to serial print the time from the rtc continuously, I get this error:

Using library Time in folder: C:\Users\daniel\Documents\Arduino\libraries\Time

Using library I2C in folder: C:\Users\daniel\Documents\Arduino\libraries\I2C (legacy)

Using library RTC in folder: C:\Users\daniel\Documents\Arduino\libraries\RTC (legacy)

E:\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IE:\Arduino\hardware\arduino\avr\cores\arduino -IE:\Arduino\hardware\arduino\avr\variants\standard -IC:\Users\daniel\Documents\Arduino\libraries\Time -IC:\Users\daniel\Documents\Arduino\libraries\I2C -IC:\Users\daniel\Documents\Arduino\libraries\RTC C:\Users\daniel\AppData\Local\Temp\build124847697314085918.tmp\practicing_RTC.cpp -o C:\Users\daniel\AppData\Local\Temp\build124847697314085918.tmp\practicing_RTC.cpp.o

In file included from practicing_RTC.ino:1:0:
C:\Users\daniel\Documents\Arduino\libraries\RTC/RTC.h:99:32: error: expected unqualified-id before 'const'
static DayOfWeek dayOfWeek(const RTCDate *date);
^
C:\Users\daniel\Documents\Arduino\libraries\Time/Time.h:79:32: note: in definition of macro 'dayOfWeek'
#define dayOfWeek(time) ((( time / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
^
C:\Users\daniel\Documents\Arduino\libraries\RTC/RTC.h:99:32: error: expected ')' before 'const'
static DayOfWeek dayOfWeek(const RTCDate *date);
^
C:\Users\daniel\Documents\Arduino\libraries\Time/Time.h:79:32: note: in definition of macro 'dayOfWeek'
#define dayOfWeek(time) ((( time / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
^
C:\Users\daniel\Documents\Arduino\libraries\RTC/RTC.h:99:32: error: expected ')' before 'const'
static DayOfWeek dayOfWeek(const RTCDate *date);
^
C:\Users\daniel\Documents\Arduino\libraries\Time/Time.h:79:32: note: in definition of macro 'dayOfWeek'
#define dayOfWeek(time) ((( time / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
^
C:\Users\daniel\Documents\Arduino\libraries\RTC/RTC.h:99:32: error: expected ')' before 'const'
static DayOfWeek dayOfWeek(const RTCDate *date);
^
C:\Users\daniel\Documents\Arduino\libraries\Time/Time.h:79:32: note: in definition of macro 'dayOfWeek'
#define dayOfWeek(time) ((( time / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
^
practicing_RTC.ino: In function 'void loop()':
practicing_RTC.ino:22:17: error: 'time' was not declared in this scope
'time' was not declared in this scope

MY CODE:

#include <Time.h>
#include <SoftI2C.h>
#include <DS3232RTC.h>
SoftI2C i2c(A4, A5); //Assign pins to the I2C bus (SDA, SCL)
DS3232RTC rtc(i2c);

void setup() {
Serial.begin(9600);
RTCTime time; //setup an instance of time

time.hour = 14;
time.minute = 21;
time.second = 00;

rtc.writeTime(&time); // Set the clock

}

void loop() {
rtc.readTime(&time); // read the time

Serial.print("Time: "); // print the time
Serial.print(time.hour, DEC); // THIS IS THE LINE IT HIGHLITS for the error
Serial.print(':');
Serial.print(time.minute, DEC);
Serial.print(':');
Serial.print(time.second, DEC);

Serial.print('\n');
}

Hi LJTorana

Try moving this statement to before setup().

RTCTime time; //setup an instance of time

Regards

Ray

Hi,
Thanks for the reply mate!

  • How did you know to move that string to outside the setup loop?
    (was it somethingin the error log that indicated this?)

After progressing threw that error, I got to the next (I have pasted it below).
From reading the error, does it mean I have to setup the days of the week?

Thanks again!

Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Uno"

Using library Time in folder: C:\Users\daniel\Documents\Arduino\libraries\Time

Using library I2C in folder: C:\Users\daniel\Documents\Arduino\libraries\I2C (legacy)

Using library RTC in folder: C:\Users\daniel\Documents\Arduino\libraries\RTC (legacy)

E:\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IE:\Arduino\hardware\arduino\avr\cores\arduino -IE:\Arduino\hardware\arduino\avr\variants\standard -IC:\Users\daniel\Documents\Arduino\libraries\Time -IC:\Users\daniel\Documents\Arduino\libraries\I2C -IC:\Users\daniel\Documents\Arduino\libraries\RTC C:\Users\daniel\AppData\Local\Temp\build7106787529917126813.tmp\practicing_RTC.cpp -o C:\Users\daniel\AppData\Local\Temp\build7106787529917126813.tmp\practicing_RTC.cpp.o

In file included from practicing_RTC.ino:1:0:
C:\Users\daniel\Documents\Arduino\libraries\RTC/RTC.h:99:32: error: expected unqualified-id before 'const'
static DayOfWeek dayOfWeek(const RTCDate *date);
^
C:\Users\daniel\Documents\Arduino\libraries\Time/Time.h:79:32: note: in definition of macro 'dayOfWeek'
#define dayOfWeek(time) ((( time / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
^
C:\Users\daniel\Documents\Arduino\libraries\RTC/RTC.h:99:32: error: expected ')' before 'const'
static DayOfWeek dayOfWeek(const RTCDate *date);
^
C:\Users\daniel\Documents\Arduino\libraries\Time/Time.h:79:32: note: in definition of macro 'dayOfWeek'
#define dayOfWeek(time) ((( time / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
^
C:\Users\daniel\Documents\Arduino\libraries\RTC/RTC.h:99:32: error: expected ')' before 'const'
static DayOfWeek dayOfWeek(const RTCDate *date);
^
C:\Users\daniel\Documents\Arduino\libraries\Time/Time.h:79:32: note: in definition of macro 'dayOfWeek'
#define dayOfWeek(time) ((( time / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
^
C:\Users\daniel\Documents\Arduino\libraries\RTC/RTC.h:99:32: error: expected ')' before 'const'
static DayOfWeek dayOfWeek(const RTCDate *date);
^
C:\Users\daniel\Documents\Arduino\libraries\Time/Time.h:79:32: note: in definition of macro 'dayOfWeek'
#define dayOfWeek(time) ((( time / SECS_PER_DAY + 4) % DAYS_PER_WEEK)+1) // 1 = Sunday
^
Error compiling.

open a new window in the ide and see if you have a example for the rtc. My rtc is different but theres should be a line that tells the clock to begin something like clock.begin(); yours maybe different. There should also be a sample that lets you set the clock.

The first problem about declaring time was indicated by the last error message in your original post and by looking at the code. Declaring it in setup() meant it only existed while setup() executed, and therefore was not available in loop(). Moving it made it global and thus available in all functions.

The other errors suggest that the DS3232 library which you #include may not be properly installed. Does it show up in the list of installed libraries under the Sketch menu item in the Arduino IDE? What version of the IDE are you using?

Something to try: the example programs for the DS3232 library have the included in this order:

#include <DS3232RTC.h>
#include <Time.h>

EDIT Just saw that there are different libraries available with the same file name. Can you post a link to the one you are using?

Just saw that there are different libraries available with the same file name. Can you post a link to the one you are using?

Since your program uses SoftI2C, I'm guessing that you have the Freetronics RTC module and got your libraries from here: Arduino Cryptography Library: Main Page

Once I installed the RTC and I2C libraries, I was able to reproduce the errors you're getting.

The fix appears to be to remove this statement:

#include <Time.h>

I can now compile your program without errors.

What was happening was that something called dayOfWeek was defined in two libraries: Time and RTC (RTC is used by DS3232). This caused a conflict. I assume that the latest version of DS3232 is designed to work just with RTC and no longer needs Time.