Datalogger - write data every second

Hello,

I'm a Arduino newbe. I got my SD datalogger working. It writes the time, date and values from analog inputs to a csv file. Time and date are obtained from an DS1307 RTC module.

The data is written as fast as possible, but I only want it to log at an interval of 1 second. The problem with a delay is that you need to know the program cylce time, so I want to use something like an interrupt.

One way to achieve this, is by using the 1 Hz output of the DS1307. Is this the best way or should I use a pin change interrupt. Or maybe a time driven interrupt?

Hi,

I very often find that in describing a question I describe the answer - you are pretty close - its time, its an interrupt - its a timer interrupt.

Its pretty easy to do using the timer registers or there are a few libraries that will also call a function every 1 second for you.

Duane B.

rcarduino.blogspot.com

Time and date are obtained from an DS1307 RTC module.

And you can't figure out when a new second has ticked over, signifying the need to log again?

Thank you guys! I had the feeling that I was close, but I was also trying to find out if my idea is really an efficient method.

I don't feel for polling the RTC time. This will hold up the microcontroller, which can be a problem in case I want to add more functionality than just a datalogger.

Another question. Is an hardware RTC better than a software clock? How about accuracy? Can a software clock got stuck if another interrupt occurs?

Answer is already in the question - but the real answer is to just build something and see what works.

If you don't have a component you might like to try, build it without first, you might find that you get a perfectly acceptable solution or have fun finding a novel alternative from the parts you do have.

Duane B

rcarduino.blogspot.com

Thank you.

By the way, I think I'm going for the polling after all. This looks like the easiest method.

Arend86:
I don't feel for polling the RTC time. This will hold up the microcontroller, which can be a problem in case I want to add more functionality than just a datalogger.

For what it's worth, polling to see whether it is time to carry out some action is the way I'd recommend, both for this 1Hz output and for the other scheduled actions you're likely to want to add later.

A 1Hz event is not fast enough to justify using an interrupt, and using an interrupt takes you down a route which will not scale up at all when you want to add additional scheduled functions.

Just use the polling technique demonstrated in the 'blink without delay' example sketch. It is up to you whether you want to carry out these timed actions based on the Arduino's internal clock or the RTC, you can poll whichever of them you want.

This approach leads you to a sketch where your main loop is simply polling for each of the possible events it may need to handle (time to do a scheduled activity, serial port input available, button pressed etc) and responding to each event as it happens.