Hi All,
I've been trying to follow the tutorial for the DS1308 RTC on DS1307 RTC tutorial. I've been having problems with compiling the code in the tutorial. Could somebody shed some light? Here's a pic of my screen:
Hi All,
I've been trying to follow the tutorial for the DS1308 RTC on DS1307 RTC tutorial. I've been having problems with compiling the code in the tutorial. Could somebody shed some light? Here's a pic of my screen:
I think it can't find the RTClib.h file.. But its right there in the libraries folder.. why?
It's much easier for us if you copy and paste the code as text. That will be a couple of hundred bytes compared to a huge image of your screen.
Also can you copy and paste the errors? I can only see part of them in the screenshot.
Hi Thanks for your reply!
So I closed arduino program and opened it again. Now it can find the file, but a new bunch of errors pop up. Please see the attached file..
Also here's the code I'm trying to compile:
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 RTC;
void setup () {
Serial.begin(57600);
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);
}
errors.txt (8.25 KB)
Looks like your RTClib.h file is corrupted in some way. How did you install it exactly?
Weird, I just downloaded it from ladyada's site. Ill try again when I get home. Thanks again for your help
I look at that library but didn't like it much. I pulled together many features from other libraries and wrote my own. I have attached a copy of it.
I added methods for reading and writing the on-board memory as well as use the Square-Wave output.
Move of the time functions I use are from the 'Time" library.
DS1307.zip (4.59 KB)
Perhaps someone could put a small little script on how to use Randall's library to simply assign the time to a variable? I don't know how to use libraries. (I thought you just had to "include" them in your code for it to be called on)..
Thanks again everyone ![]()
I suggest RandallR would need to do that for you. I don't see the need to download another RTC library.
Just another alternative, this one has worked well for me:
http://www.arduino.cc/playground/Code/Time
Unzip DS1307.Zip into your "Libraries" directory.
Add "#include <DS1307.h>" to you sketch.
To get the time:
...
tmElements_t tm;
DS1307::getTime(tm);
...
To read some memory:
...
char szBuffer[10];
DS1307::ReadMem(0, szBuffer, sizeof(szBuffer)); // Address is offset to the first byte of RAM.
...
To Write some memory:
...
DS1307::WriteMem(0, "This clock belongs to me"); // Address is offset to the first byte of RAM.
DS1307::WriteMem(0, szBuffer, 5);
...
I tried to comment my code but if you have questions, ask.