I have a deek-robot data logging shield on the Arduino uno. Being new to Arduino (but have done Windows C++ programming as well as some work with PIC microcontrollers) I struggled along to get to grips with the Arduino experience.
Needless to say that I didn't get any bit of documentation with the shield. As far as I can make out it should be compatible with the Adafruit Data Logger Shield.
I checked the first samples for the RTC and SD card and it all seems to work. Now I'm struggling with the RTC. I can set the time and once set it does work ok - unless I cut the power (by pulling the USB from the computer). Whenever I switch the power back on the RTC does not run.
I have included Wire.h and RTClib.h and use the RTC_DS1307
This is the sketch I'm using:
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
#if defined(ARDUINO_ARCH_SAMD)
// for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
#define Serial SerialUSB
#endif
RTC_DS1307 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(57600);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// 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
// rtc.adjust(DateTime(2016, 4, 20, 15, 58, 00));
}
}
void loop () {
DateTime now = rtc.now();
char s_Time[40]="2016/04/20 (Wednesday) 16:39:00";
char s_tmp[20];
sprintf(s_Time,"%4i",now.year());
sprintf(s_tmp,"/%02i/",now.month());
strcat(s_Time,s_tmp);
sprintf(s_tmp,"%02i (",now.day());
strcat(s_Time,s_tmp);
strcat(s_Time,daysOfTheWeek[now.dayOfTheWeek()]);
sprintf(s_tmp,") %02i:",now.hour());
strcat(s_Time,s_tmp);
sprintf(s_tmp,"%02i:",now.minute());
strcat(s_Time,s_tmp);
sprintf(s_tmp,"%02i\n",now.second());
strcat(s_Time,s_tmp);
Serial.print(s_Time);
delay(1000);
}
The output on the serial monitor always gives me the
RTC is NOT running!
2000/01/01 (Saturday) 00:00:00
after power over the USB port was interrupted.
I have checked the coin cell battery and it is connected and supplying voltage (checked on the contact pads on the board).
Any ideas? Or have I missed something in the concept here? Any pointers welcome!