Need help with a simple sketch for the RTC

Our range of tiny modules are designed to make it easy for you to quickly add functionality to your projects. [Module List]
Post Reply
tas99
Posts: 6
Joined: Sat Feb 16, 2013 11:53 pm

Need help with a simple sketch for the RTC

Post by tas99 » Tue Feb 19, 2013 12:31 am

As you can see from my earlier question I’m pretty new to this platform and especially writing Sketches that work.

I’m still trying to use the information in the RTC Quickstart Guide but that’s proving to be frustrating at best. It assumes I know a lot more than I do. That’s understandable because I doubt it’s aimed at someone like me. Anyway, I need some help.

It may be asking a lot but is there someone who can write a SIMPLE and complete Sketch using the retrieve date and time commands shown in the Quickstart guide that will read time and date from the RTC and write it to the serial monitor. With that I think I can build on it to get it to do what I want.

When I do it I get a lot of errors. Mainly things like “Development_Sketch:12: error: expected initializer before '.' token”. Maybe someone can tell me what that error means. I looked around and didn’t find much that I could understand.

Thanks in advance (I hope)

Tom

tas99
Posts: 6
Joined: Sat Feb 16, 2013 11:53 pm

Re: Need help with a simple sketch for the RTC

Post by tas99 » Tue Feb 19, 2013 4:48 pm

tronixstuff,

I really appreciate the code you supplied but it's far above what I'm looking for.

In the Quickstart Guide they reference the fo;;owing and it's those functions I'd like to see incorporated into a simple sketch.

Again, thanks for the response and hope you can help with this simplified request.

Tom

From the Quickstart Guide:

First, retrieve the time data from the RTC with

rtc.readTime(&time);

then you can work with the time parameters by using the byte variables

time.hour
time.minute
time.second

So to display the time in the serial monitor, you now use the following lines

Serial.print("Time: ");
Serial.print(time.hour, DEC);
Serial.print(':');
Serial.print(time.minute, DEC);
Serial.print(':');
Serial.print(time.second, DEC);

tas99
Posts: 6
Joined: Sat Feb 16, 2013 11:53 pm

Re: Need help with a simple sketch for the RTC

Post by tas99 » Wed Feb 20, 2013 3:01 am

tronixstuff,

Thanks. That was exactly what I was looking for and helps me see where I made all my mistakes.

The question I have is is there any advantage in using the SoftI2C versus the direct I2C commands. It seems the I2C is far ore complicated but it might offer more options.

I don't know if anyone from Freetronics reads these posts but I would have to say that offering a complete Sketch as you have with a few comments would be far more helpful than the segmented comments they have in the Quickstart guide.

Just curious,

Tom

tas99
Posts: 6
Joined: Sat Feb 16, 2013 11:53 pm

Re: Need help with a simple sketch for the RTC

Post by tas99 » Wed Feb 20, 2013 6:31 pm

John,

You're probably right in saying that the Quickstart Guide assumes some previous knowledge and in my case that was lacking. I like the link to your tutorial site and I will be using much of what's there as I progress through this project.

In the meantime I have a couple of questions.

In both Sketches you print the values of minutes and seconds as 0 if the value is less than 10. Why is that?

Second, This statement (SoftI2C i2c(A4, A5); ) assigns SDA and SCL to pins 4 and 5 respectively. Can they be assigned to other pins? The QuickStart Guide says I can if I'm using the SoftI2C library but I just want to make sure. If so, can it be any analog pins?

Thanks for all the help.

Tom

caltschul
Posts: 3
Joined: Sun Jun 16, 2013 10:17 pm

Re: Need help with a simple sketch for the RTC

Post by caltschul » Mon Jun 17, 2013 1:19 am

Hi Tronixstuff

I am struggling with trying to get the RTC to display on the DMD. I need to put the digital time alongside some other information including the temperature. I am tearing my hair out (now you know why I am bald!) as I can't get anything to work. Initially I tried the DS3231, but that library wouldn't work, then I used the library DS3232, that worked, but don't know how to write the digits to the screen instead of the written form of the numbers scrolling across the screen (from the sketch that says "the time is now three forty") any help would be greatly appreciated, I am relatively inexperienced with Arduino (and I'm teaching kids how to use it)

Post Reply