First, I'd like to say I'm quite new to working with electronics and programming; in fact, my specialization in university and graduate school was microbiology, and not anything to do with computers/electronics.
That being said, I have good computer knowledge (building/Windows OS/networking), but have very little actual programming knowledge (did a little bit of Pascal back in the day...)
Needless to say, the Arduino IDE (from what I understand, an extension of C++) is quite intimidating, but I've managed to work my way through some of the more basic examples, and am working on trying to get a more complicated project.
Right now, I'm trying to get a DS1307 breakout board working, but for the life of me, can't seem to get it to work. Hardware wise, I have it connected to an Arduino Mega 2560.
The Vcc is connected to the 5V pin, the ground to ground, SDA to SDA and SCL to SCL. I have tried with and without pull up resistors (connected between 5V-SDA and 5V-SCL).
Using the Adafruit library (GitHub - adafruit/RTClib: A fork of Jeelab's fantastic RTC Arduino library) and the following code, I can get the RTC to work just fine.
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
void setup () {
Serial.begin(9600);
Wire.begin();
RTC.begin();
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(__DATE__, __TIME__));
}
}
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(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
Serial.print(" since 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.unixtime() + 7 * 86400L + 30);
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);
}
However, when I try to use Henning Karlsen's RTC library (Electronics - Henning Karlsen) and the following code:
// DS1307_Serial_Easy (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1307-library to
// quickly send time and date information over a serial link
//
#include <DS1307.h>
// Init the DS1307
DS1307 rtc(20, 21);
void setup()
{
// Set the clock to run-mode
rtc.halt(false);
// Setup Serial connection
Serial.begin(9600);
// The following lines can be commented out to use the values already stored in the DS1307
//rtc.setDOW(SUNDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(3, 10, 2010); // Set the date to October 3th, 2010
}
void loop()
{
// Send Day-of-Week
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// Wait one second before repeating :)
delay (1000);
}
All I get is
xxxxxxxxx 85.85.2165 -- 27:85:85
Anyone have any clue about this?
One might wonder why not just use the Adafruit library and coding, and not Henning Karlsen's, but that is because the other project I am working on is based around his libraries and recoding it would be too big of a hurdle for me right now.