Hi everyone,
i tried a lot now, but still can't find the error in this code. The Problem is the setSyncProvide.
Maybe also a overload on Library's. I checked the sodaq Library and Timelib.h, but i couldn't find a solution.
I want to sync the rtc time with the internal time to use it with the timealarms.
The timealarm tiggers a relay.
Without the rtc modul it works very well. (Just using the settime in setup)
I am still a beginner, so i hope you guys can help me out here.
Thanks in advance!
Tobi
// Library for RTC-Modul
#include <Wire.h>
#include "Sodaq_DS3231.h"
// Library for the Time Alarm functions
#include <TimeLib.h>
#include <TimeAlarms.h>
const int signal = 11;
char weekDay[][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
void setup()
{
Serial.begin(9600); // set up Serial library at 9600 bps
Wire.begin();
rtc.begin();
setSyncProvider(rtc.now);
rtc.now();
Alarm.alarmRepeat(07, 30, 0, MorningAlarm);
pinMode(signal_coffee, OUTPUT);
digitalWrite(signal_coffee, HIGH);
}
uint32_t old_ts;
void loop() {
digitalClockDisplay();
Alarm.delay(1000); // wait one second between clock display
DateTime now = rtc.now(); //get the current date-time
uint32_t ts = now.getEpoch();
if (old_ts == 0 || old_ts != ts) {
old_ts = ts;
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.date(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print(' ');
//Serial.print(weekDay[now.dayOfWeek()]); Does not work with this line.
// It'S sample code and works in the original
Serial.println();
Serial.print("Seconds since Unix Epoch: ");
Serial.print(ts, DEC);
Serial.println();
}
}
// functions to be called when an alarm triggers:
void MorningAlarm(){
Serial.println("Coffee Machine is on");
digitalWrite(signal, HIGH);
delay(1000);
digitalWrite(signal, LOW);
delay(1000);
digitalWrite(signal, HIGH);
}
void digitalClockDisplay()
{
// digital clock display of the time
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits)
{
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits);
}