RTC module- calculate time between two connections

Good morning,

I am using a Tiny RTC module DS1307+ an Arduino mega 2560.

I have a question conrcerning how to use the RTC module for my application.

I would like to calculate the time that passes between the first connection and the n-connection of my system.

Basically, I would like to write the date of first connection as a permanent date to the EEPROM of arduino. It will be the reference date and then make a comparison between this date an the date of the n-connection. Thus, I can get the info about the number of days between the two connections.

Do you have any suggestion or usefull links for libraries to send to me?

Do you have any suggestion or usefull links for libraries to send to me?

For what purpose? You have only a few things to do.

  1. Determine if any given connection is the first one. If EEPROM has never been used to store anything, then all addresses will contain 255, so you can presume that 255 read from some address means that this is the first connection.

  2. Store the time of the first connection to EEPROM. This requires getting the date and time from the RTC, and storing something meaningful in 4 to 7 addresses in EEPROM, depending on that you want to store.

  3. If this isn't the first connection, read the current date and time from the RTC and the saved date and time data, and determine the interval between them. Can't see why this is important, but it isn't difficult if you store/retrieve the proper data (as in the unix time as unsigned long).

What parts do you need help with/a library for?

Basically, I would like to write the date of first connection as a permanent date to the EEPROM of arduino. It will be the reference date and then make a comparison between this date an the date of the n-connection. Thus, I can get the info about the number of days between the two connections.

Please, clarify the meanings of first connection, n-connection, and two connections. Are they like these?

1. First connection: You have switch-1(SW1) connected at Pin-2 of UNO.
2. n-connection?
3. Two (Second) connection: You have switch-2(SW2) connected at Pin-8 of UNO.
4. MCU will be polling SW1 for close condition, and then the date and time (after reading from RTC) will be stored onto the on-board EEPROM of MCU.

5. MCU will be polling SW2 (second connection) for close condition, and then the new date and time will be collected from the RTC.

BTW: Please edit the title to make spelling correction of connwctions

Thank you for the suggestions.

PaulS, you confirm to me the feasability of the project...I am newbie of arduino...

PaulS:
For what purpose? You have only a few things to do.

I am controlling a gas sensor with Arduino. It has a small constant leakage every day. I am waiting the final version without this problem, but in the meantime I have to use it. So I need to determine the amount of this leakage and the only way is the calculation of the days from the first connection.

PaulS:
2) Store the time of the first connection to EEPROM. This requires getting the date and time from the RTC, and storing something meaningful in 4 to 7 addresses in EEPROM, depending on that you want to store.

Why from address 4 to 7 in the EEPROM?

PaulS:
3) If this isn't the first connection, read the current date and time from the RTC and the saved date and time data, and determine the interval between them. Can't see why this is important, but it isn't difficult if you store/retrieve the proper data (as in the unix time as unsigned long).

What parts do you need help with/a library for?

To store the proper data I have to use unix time or unsigned long?

I was referring to the RTC library...

Why from address 4 to 7 in the EEPROM?

I didn't say to use addresses from 4 to 7. I said you need to store somewhere between 4 and 7 bytes. The unix time is an unsigned long, so it is 4 bytes. Hour, minute, second, day, and month are bytes. Year is an int. 5 bytes + 2 bytes is ... Hang on, I need to take a shoe off ... 7 bytes.

To store the proper data I have to use unix time or unsigned long?

The unix time value IS an unsigned long. That is one way to store the data. The other is to store the year, month, day, hour, minute, and second values. Calculating the interval between two unix times is trivial. Calculating the interval between two sets of year, month, day, hour, minute and second values is not.