Problems adding RTC code to weather shield sketch

Hi,

I have a Sparkfun weather shield and using their standard sketch (attached).

This is the shield:

https://learn.sparkfun.com/tutorials/weather-shield-hookup-guide

The problem with this sketch is that there is no RTC, so i bought a separate unit and simply want to add the RTClib DS1307 code. Seems simple enough, but when i see the output, all i get is -1 for the date and time.

I have the RTC connected on analog pins 4 and 5.

Also, the data collects every second. I’d like to send data out every 5 minutes. But for the life of me i cant see in the code where it determines the output data frequency.

Any guidance greatly appreciated.

Weather_Shield.ino (12.9 KB)

The problem with this sketch is that there is no RTC, so i bought a separate unit and simply want to add the RTClib DS1307 code. Seems simple enough, but when i see the output, all i get is -1 for the date and time.

Have you run the examples that come with the RTC library, without the weather shield attached? Do they work?

The weather station shield also uses I2C to communicate with the Arduino. There may be conflicts with addresses or with the weather shield device’s use of the I2C bus.

Try searching for, and running the I2C scanner, just to make sure that all the hardware is connected correctly, and using the right addresses.

Also, the data collects every second. I’d like to send data out every 5 minutes. But for the life of me i cant see in the code where it determines the output data frequency.

Omitting the extraneous stuff that loop is doing (like collecting data from the sensors), it looks like this:

void loop()
{
  //Keep track of which minute it is
  if(millis() - lastSecond >= 1000)
  {
    digitalWrite(STAT1, HIGH); //Blink stat LED
    
    lastSecond += 1000;

    //Report all readings every second
    printWeather();

    digitalWrite(STAT1, LOW); //Turn off stat LED
  }

  delay(100);
}

It’s hard to understand why you can’t see how often data is output.

It’s hard to understand what that stupid delay() is for. Who cares that loop() iterates 42 bazillion times before it is time to do something, vs 0.42 bazillion times?

Have you run the examples that come with the RTC library, without the weather shield attached? Do they work?

Yes, it works fine.

I since started from scratch again and sure enough its up a running. I must have had a line error previously.

    lastSecond += 1000

    //Report all readings every second
    printWeather();

I looked at this, but changing the 1000 will stuff up the averages. What would be the correct way to delay the output so the averages calculate correctly. For example:

lastMinute += 5;

I looked at this, but changing the 1000 will stuff up the averages. What would be the correct way to delay the output so the averages calculate correctly. For example:

Suppose I said that you needed to feed the dog every hour, and the cat once a day. Could you figure out a way to not feed the cat every hour? Of course. It is not necessary to feed the cat every time you feed the dog.

Similarly, it is not necessary to output data every time you collect it. Collect the data in one if block. Output the data in another if block.

Or, collect the data and output it in the same block, but only output the data every 3000th time you collect it.

Ok, i see what you're saying. This would work quite well so i can retain the averages but just spit out the data every 5 minutes or so.

As a side note, this is running of a solar panel and battery. Is there any powersaving to be made if the data collection frequency varies (not the output frequency).

In summary, i will do this to output to the serial every 5 mins, but let the data collect every 30 seconds.

//Keep track of which minute it is
  if(millis() - lastSecond >= 30000) //THIS IS THE DATA GRAB
  {
    digitalWrite(STAT1, HIGH); //Blink stat LED
    
    lastSecond += 300000; //THIS IS THE OUTPUT

Have i interpreted this correctly

Is there any powersaving to be made if the data collection frequency varies (not the output frequency).

I can't imagine how, since the wind speed and rain gauges are interrupt driven. The Arduino has to stay awake to deal with them, or wake up to deal with them.

Have i interpreted this correctly

Yes, but you are starting with a dumb sketch. There should NOT be a constant for the interval between readings and another constant to define when to act again. There should be ONE constant, so you only need to change one value.

Even better, though, would be to record the last time a reading happened, and then determine if now minus then was greater than, or equal to, the interval between readings.

Ok, i have it all working now. Its logging nicely every 5 mins, however, i get java errors occuring in the Arduino software.

Binary sketch size: 12,940 bytes (of a 32,256 byte maximum)
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
	at java.awt.image.DataBufferInt.<init>(DataBufferInt.java:41)
	at java.awt.image.Raster.createPackedRaster(Raster.java:458)
	at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1015)
	at sun.awt.image.SunVolatileImage.getBackupImage(SunVolatileImage.java:225)
	at sun.awt.image.VolatileSurfaceManager.getBackupSurface(VolatileSurfaceManager.java:252)
	at sun.awt.image.VolatileSurfaceManager.initialize(VolatileSurfaceManager.java:108)
	at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:72)
	at sun.awt.image.SunVolatileImage.<init>(SunVolatileImage.java:101)
	at java.awt.GraphicsConfiguration.createCompatibleVolatileImage(GraphicsConfiguration.java:284)
	at java.awt.GraphicsConfiguration.createCompatibleVolatileImage(GraphicsConfiguration.java:185)
	at javax.swing.RepaintManager.getVolatileOffscreenBuffer(RepaintManager.java:1011)
	at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1391)
	at javax.swing.RepaintManager.paint(RepaintManager.java:1220)
	at javax.swing.JComponent.paint(JComponent.java:1015)
	at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:21)
	at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
	at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
	at java.awt.Container.paint(Container.java:1780)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
	at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:714)
	at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:694)
	at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:128)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Its a memory error. I only seem to have it with the sketch i modified and it never happened before (sketch attached). So it must be something i did for the 5 minute data.

Can i flush the memory or is it a software issue rather than the operation of the arduino?

Weather_Shield_burts.ino (14.7 KB)

Its a memory error.

That has nothing to do with the sketch running on the Arduino.

Can i flush the memory

Yes. Be sure to use saline solution, and dry thoroughly afterwards.

or is it a software issue rather than the operation of the arduino?

It's a problem with the IDE or the Serial Monitor application.