Have an issue setting time using the setTime() function in the time.h library. See following code:
I am driving a SURE 3208 Led Matrix display using the HT1632.h library functions.
Using the setTime() function -- setTime(4, 11, 15, 19, 1, 2014) -- doesn't set the
time on a DS1307 RTC module. It doesn't set the PC System time either but I didn't expect
it to. The DS1307RTC.h library has a set() function but it expects a EPOCH time which
I am trying to avoid. What time is being set with the time.h setTime() function?
Does anyone know how to set the DS1307 RTC using human readable time vs the EPOCH time code?
[code[font=Courier New][size=8pt][/size]]#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>
#include "font_5x4.h"
#include "font_5x7.h"
#include <HT1632.h>
#include <stdio.h>
#include <Button.h>
#define cs1 8
#define cs2 9
#define wrt 10
#define dat 11
#define High 9
#define Mid 5
#define Low 1
int heartbeat = 2;
bool SetTime = 1; /// 0 = no, 1 = yes
char buff[6];
tmElements_t tm;
void setup()
{
pinMode(heartbeat, OUTPUT);
Serial.begin(9600);
if(SetTime)
{
Serial.println("Setting Time...");
setTime(4, 11, 15, 19, 1, 2014);
}
HT1632.begin(cs1, cs2, wrt, dat);
HT1632.setBrightness(Low);
HT1632.clear();
HT1632.render();
}
void loop()
{
//clear matrix
HT1632.clear();
HT1632.render();
delay(250);
while(1)
{
RTC.read(tm);
sprintf(buff, "%2d%c%02d", tm.Hour, ':', tm.Minute);
displayit(buff,1,0);
digitalWrite(heartbeat, HIGH);
delay(500);
sprintf(buff, "%2d%c%02d", tm.Hour, ' ', tm.Minute);
displayit(buff,1,0);
digitalWrite(heartbeat, LOW);
delay(500);
}
}
void displayit( char msg[], int x_offset, int y_offset)
{
/**************** DO NOT DELETE ****************
drawText SYNTAX:
drawText(
const char text [],
int x,
int y,
const char font [],
const char font_width [],
char font_height,
int font_glyph_step,
char gutter_space)
************************************************/
HT1632.drawText((const char *)&msg[0], x_offset, y_offset, FONT_5X7, FONT_5X7_WIDTH, FONT_5X7_HEIGHT, FONT_5X7_STEP_GLYPH);
HT1632.render();
}
void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.print(" ");
Serial.print(month());
Serial.print("/");
Serial.print(day());
Serial.print("/");
Serial.print(year());
Serial.println();
}
void printDigits(int digits)
{
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}
[/font]
Try to use setSyncProvider to synchronize system time with RTC
Also try to use if(timeNotSet) instead of if(SetTime)
SetTime and setTime - this naming is best way to hell
Library time.h does not set RTC chip and does not read RTC chip. Look here, it is my working solution:
http://forum.arduino.cc/index.php?topic=190221.0
Another issue is that the DS1307 registers use BCD to store their information. You can download the spec sheet from:
Does anyone know how to set the DS1307 RTC using human readable time vs the EPOCH time code?
setTime(12,29,55,27,12,13); //Hour,Minute,Second,Day,Month,Year 12:29:55 27th December 2013
setTime(1388147395); //EPOCH Time to set the clock http://www.epochconverter.com/
I'm able to accomplish what I need by using the RTC.write(tm) function. The setTime(hr, min, sec, mo, day, year)
function does not seem to work with the RTC. Using the NTP protocol is not an option as I wanted need to be
able to set the time offline... RTC.write() is working.... so issue RESOLVED.
Thanks for your quick responses!! XD