Hi, I hope someone can help me with my problem and can describe how I can solve it but I have to say I am not good in programming.
My goal is to programm my RTC with the compiled time and date. So that I always have the current time and date saved in my rtc after setting it up the first time.
I already got so far that I have the date and time after compiling but I dont know how I can save the string in multiple pieces (variables) that I then can write into the command.
I am using this library but I think there is a problem in the month and year (at least in month because the year is in octal numbers):
#include <Wire.h>
#include <DS1338.h>
const char compile_date[] = __DATE__;
const char compile_time[] = __TIME__;
// A structure to hold the time read from the device
struct rtctime_t time;
// A character array to hold the string representation of the time
char time_str[20];
void setup() {
Wire.begin();
Serial.begin(74880);
while(!Serial);
//Serial.println(compile_date);
//Serial.println(compile_time);
ds1338_clean_osf();
ds1338_disable_sqw();
make_time(&time, 031, 05, 21, 11, 31, 40);
// Set the clock
if (ds1338_write_time(&time))
{
Serial.println("Unable to set the time--an I2C error has occured.");
}
else
{
Serial.println("Clock set successfully!");
}
}
void loop() {
// Attempt to read the time.
if (ds1338_read_time(&time))
{
Serial.println("Unable to read time--an I2C error has occured.");
}
else
{
// The time has been read successfully--print it.
format_time_str(&time, time_str);
Serial.println(time_str);
}
delay(1000);
}
I've just taken a fast flight over the data sheet and saw what I expected. There is nothing octal about the part and there should be nothing octal about using it.
Separate your problem. Saving values or strings or dates or times in variables or EEPROM has nothing to do with what is in them or what that content represents.
Figure out the RTC.
Select some way to store any information to survive power cycling, or whatever your end goal is.
Two completely separate issues. Neither difficult. Forget octal, you are confused or have been mislead.
#include <Wire.h>
#include <DS1338.h>
// A structure to hold the time read from the device
struct rtctime_t time;
// A character array to hold the string representation of the time
char time_str[20];
void setup()
{
// Initialize the I2C bus
Wire.begin();
// Initialize the serial interface
Serial.begin(74880);
while (!Serial)
;
// Once serial has been inialized, print a welcome message
Serial.println("Maxim DS1338 RTC Example");
ds1338_clean_osf();
ds1338_disable_sqw();
// Set the date of the time structure to June 27, 2014 and
// the time to 18:45:00 (6:45:00 pm)
make_time(&time, 017, 10, 27, 18, 28, 06);
// Set the clock
if (ds1338_write_time(&time))
{
Serial.println("Unable to set the time--an I2C error has occured.");
}
else
{
Serial.println("Clock set successfully!");
}
}
void loop()
{
// Attempt to read the time.
if (ds1338_read_time(&time))
{
Serial.println("Unable to read time--an I2C error has occured.");
}
else
{
// The time has been read successfully--print it.
format_time_str(&time, time_str);
Serial.println(time_str);
}
delay(1000);
}
When I use his example then I get the this result:
When he really wanted to save this information in the RTC "June 27, 2014" then it didnt work.