SD card shield / RTC

Hello all!

I’m new here, been playing with Arduino for some time now and mainly using them for sensor inputs! Exciting stuff.

Also using them on some injection machines in my workplace.

So, the question.

I’m using a low cost SD card shield, I’ve resolved having to use older library’s but for some reason I’m now coming across a problem having the RTC reset the time, or even begin to cycle. It’s clock is stuck!

This might be something code wise, but I think it may be library/code relationship rather than the code itself.

I found this link on adafruit for the shields; Older Datalogger Shield Leonardo & Mega Library | Adafruit Data Logger Shield | Adafruit Learning System

I have searched lots and tried various peoples version of a RTC with little success.

If I use the soft RTC example, it picks up the time. But note using the hardware.

Any advice on my code please or any other tips;

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include “RTClib.h”

RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”};

void setup () {

#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif

Serial.begin(9600);

delay(3000); // wait for console opening

if (! rtc.begin()) {
Serial.println(“Couldn’t find RTC”);
while (1);
}

if (rtc.lostPower()) {
Serial.println(“RTC lost power, lets set the time!”);
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(DATE), F(TIME)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}

void loop () {
DateTime now = rtc.now();

Serial.print(now.year(), DEC);
Serial.print(’/’);
Serial.print(now.month(), DEC);
Serial.print(’/’);
Serial.print(now.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(’:’);
Serial.print(now.minute(), DEC);
Serial.print(’:’);
Serial.print(now.second(), DEC);
Serial.println();

Serial.print(" since midnight 1/1/1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println(“d”);

// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now + TimeSpan(7,12,30,6));

Serial.print(" now + 7d + 30s: ");
Serial.print(future.year(), DEC);
Serial.print(’/’);
Serial.print(future.month(), DEC);
Serial.print(’/’);
Serial.print(future.day(), DEC);
Serial.print(’ ‘);
Serial.print(future.hour(), DEC);
Serial.print(’:’);
Serial.print(future.minute(), DEC);
Serial.print(’:’);
Serial.print(future.second(), DEC);
Serial.println();

Serial.println();
delay(3000);
}

Welcome to the forum. Please read the first post on how to post your code (hint: use code tags).

Also, what do you see as output?

How to use this forum Be sure to read notes 7 and 11.

You’ve never told us which module and board you’re using. Please state that and provide links if possible. You mention the Adafruit logger, which uses the DS1307 and then you post code for the DS3231. Just a bit confusing.

This statement is also generates a “”uh, what’s he trying to say” thought:

I'm using a low cost SD card shield, I've resolved having to use older library's

Why does low cost need old libraries? That make no sense whatsoever.

Sorry to not post code tags, this is the current example code I've been using.

This is the current shield I'm using;

The chip states DS1307, but I was only able to use the code for the DS3231.

Again sorry to not make myself clearer with everything,

You shield does not have a DS3231, it has a DS1307.

That would be the first thing to change in your code.

The library for that shield:

Look in the examples directory for the ds1307 specific code.

And the demo code for the datalogger:

mrevolve:
The chip states DS1307, but I was only able to use the code for the DS3231.

Basic code works on both without modification.

Thanks for your help everyone, got it sorted. Great :slight_smile: