Is The Realtime Clock Locking Up My Program? If so how do I solve it?

Hey everyone, I am having a very strange issue with the realtime clock in Arduino that I cannot seem to solve. Basically, I have a program that logs data from a terrarium kit and saves each session to an SD card as a file named after the time the program started. 0

The problem with the program is that the code hangs on the statement before the setup section: “DateTime now =” The realtime clock appears to be functioning correctly with the example program which makes this issue even more strange. I am unsure if this is purely a software or hardware issue. From scouring the internet, I have found people with a similar problem to mine where the RTC will freeze up the i2c bus on the Arduino. However, I am unsure whether this is the issue plaguing me. If this is indeed the issue plaguing my program, unsure of how to work around it. I found an online solution here, however my program freezes upon launch so this would not work for me.

So far, I have tried:
-Replacing the coin-cell battery in the realtime clock (I am using 3 volt batteries)
-Replacing the datalogger shield with a new one
-Replacing the Arduino with a new one
-Checking to make sure that the jumpers were correctly soldered to the datalogger shield (Adafruit support checked mine through images and said they looked good)

I am running this program on IDE Version 1.6.9 with a program with the newer Adafruit datalogger shield on the Arduino Mega.

Any help would be greatly appreciated

Code: [code]//The libraries we need for our terrarium kit//Download and install them - (Too long to post)

Did you write the sketch or just edit it? Doesn’t look great.

Try attached which may fix the RTC issue, though I see some others.

AmetuerArduinoEnthusiast.ino (8.25 KB)

That sketch uses RTClib.h. I don’t see where there it has # include <Wire.h>.
Try adding that before RTClib.h.

//The libraries we need for our terrarium kit
//Download and install them all at this link:
#include <OneWire.h> //Import OneWire library
#include <DallasTemperature.h> //Import DallasTemperature library
#include <Adafruit_Sensor.h> //Import Adafruit Sensor library
#include <DHT.h> //Import first part of the DHT library
#include <TimerOne.h> //Import TimerOne library
#include <SPI.h>
#include <SD.h>  //this refers to an old SD library needed specifically for
#include <Wire.h> //add the Wire library
#include "RTClib.h"  //this is from the rtc example folder code