Using a RTC to take readings

Hello All.

I'm a noob programmer for adruino. I was able to get my i2c RTC working, commuicating, and printing with a Serial.print().

What I am trying to do with my RTC is take reading from a analog temp sensor, an i2c pressure sensor, an analog wind speed sensor, and an i2c compass module. (More or less its a home built weather station.)

I want the reading to happen every 5 min. I dont know if I am even heading in the right direction. Currently I have:

if(now.minute() == 5,10,15,20,...,55,00)
{
     // RTD Day Of the Week 
    if(dispDOW == 0)
      Serial.print("SUN: ");
    if(dispDOW == 1)
      Serial.print("MON: ");
...
...
              // Temp Display in Deg F
      Serial.print("  Temp:  "); // Temp will be in a format of 
      Serial.println(degF);         // ##.#
    
        Serial.println(MPH);
       
}

Any thoughts?!

This part is wrong:

if(now.minute() == 5,10,15,20,...,55,00)

You want more like:

if(now.minute() % 5 == 0)

That divides by 5, gets the remainder, and if it is zero, then 5 minutes are up.

However a word of caution. When the time is (say) 10:05, then the "5 minutes are up" will happen thousands of times (until it becomes 10:06). You also need to check if the time has changed (eg. if the minute now is different from the minute a moment ago).

I think there may be a conceptual thing here but it may be just a matter of language. You don't use the RTC to gather the data, that is the Arduino's job and the RTC tells it when to do it.

You apparently have the RTC (nearly!) sorted. All you need is to get some code together to read a sensor, than add code for another sensor etc. Once done, then bring the RTC into play. You will probably find that you don't really need the RTC to do this sort of thing but it is still the best way to go as it increases the versatility and viability of your project.

Would adding the use of my now.second() take care of thousands of readings?

if(now.minute() /5 ==0 && now.second() ==0)

Modulus is not the same as divide, you know.

No, now.second() won't really help. It will execute your main loop thousands of times, probably, in one second.

You want something like:

if (now.minute () != previousMinute)
  {
  previousMinute = now.minute ();
  if (now.minute () % 5 == 0)
    {
    // do something
    }
  }

For your purposes, I'd suggest that you don't need the RTC to control the five minute interval at all, you can just use the good old blink without delay method to have millis do that. If you actually want to timestamp your data, just ask the RTC what time it is whenever millis tells you it's time to read your sensors.

wildbill:
...just ask the RTC what time it is whenever millis tells you it's time to read your sensors.

// something like below
if (millis() % 6000 == 0)
{
Serial.print (weather data)
}

That worked out perfectly! it only displays the time temp and so on once! and it prints it every 5 min!!

Thank you all for your great ideas! I learned a lot!

// something like below

if (millis() % 6000 == 0)
{
Serial.print (weather data)
}

Caution though, millis() might jump a few units while you are processing. In other words, you might miss exactly the 6000 point.

Better to have a "lastDisplayTime" variable, and compare until it has passed the required time. eg.

if (millis() - lastDisplayTime >= 300000)   // 5 minutes up?
  {
  // display stuff
 
  lastDisplayTime = millis ();  // when we updated
  }