I have an arduino Mega card , and is connected to a Deek-Robot SD/RTC datalogging shield(V1.0). I am powering this off the USB port. I've been able to get the SD read/write/access to work just fine. But after trying many dfferent sketches/libraries to set the Real Time clock I am stumped. The shield uses a DS1307 chip in it, with a battery (it is plugged in, and has voltage).
I've noticed that when plugging the boards together not ALL the shields pins, connect to the Arduino Mega's pins (i.e. Shields SDA & SCL not connected to MEGA. On the opposite side the Shields IO & Ref pins don't connect. When I run "TimeRTCSet" sketch to set the clock I get the following output...
Unable to sync with the RTC
0:00:00 0 0 1970
0:00:01 1 1 1970
0:00:02 1 1 1970
0:00:03 1 1 1970
0:00:04 1 1 1970
When I run the "Set Time" sketch from the "DS1307RTC" library I get these results...
RTC is NOT running!
2165/165/165 165:165:85
since midnight 1/1/1970 = 2028820689s = 23481d
now + 7d + 30s: 2034/4/23 17:18:392165/165/165 165:165:85
since midnight 1/1/1970 = 2028820689s = 23481d
now + 7d + 30s: 2034/4/23 17:18:39
I understand the time needs to be set before can use this, but none of the sketch's I've tried seem to be able to SET the time here.
On the MEGA card the SDA is pin 20, and SCL is pin 21. On the shield there are the two pins that didn't conect via header between the two boards. I tried running jumpers from the Shield to the MEGA to see if that would make any difference.... it didn't.
Another sketch "Set Time" in "DS1307RTC" libary gave me the following results...
DS1307 Communication Error :-{
Please check your circuitry
I've attached that code here...
Code: [Select]
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>const char *monthName[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};tmElements_t tm;
void setup() {
bool parse=false;
bool config=false;// get the date and time the compiler was run
if (getDate(DATE) && getTime(TIME)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
delay(200);
if (parse && config) {
Serial.print("DS1307 configured Time=");
Serial.print(TIME);
Serial.print(", Date=");
Serial.println(DATE);
} else if (parse) {
Serial.println("DS1307 Communication Error :-{");
Serial.println("Please check your circuitry");
} else {
Serial.print("Could not parse info from the compiler, Time="");
Serial.print(TIME);
Serial.print("", Date="");
Serial.print(DATE);
Serial.println(""");
}
}void loop() {
}bool getTime(const char *str)
{
int Hour, Min, Sec;if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
tm.Hour = Hour;
tm.Minute = Min;
tm.Second = Sec;
return true;
}bool getDate(const char *str)
{
char Month[12];
int Day, Year;
uint8_t monthIndex;if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
for (monthIndex = 0; monthIndex < 12; monthIndex++) {
if (strcmp(Month, monthName[monthIndex]) == 0) break;
}
if (monthIndex >= 12) return false;
tm.Day = Day;
tm.Month = monthIndex + 1;
tm.Year = CalendarYrToTm(Year);
return true;
}
i try all these lib to UNO and it is working 100%....
Any Geniuses that can help me here?