Problem with MorningAlarm

Hello all,

i´m from germany and i had my last english lesson 35 y ago, but i try to explain a problem i have with a sketch to make a led blink:

since a few days i´m working with my new Arduino ( Mega 256 ) and i have tried out several simple sketches and they run well. But the following timeAlarm-Sketch does not work . The following code should turn on a led at 08:11:05 h at Pin 13 for 5 seconds. the sketch can be compiled and uploaded wothout problems.

After the program starts the clock is set to 08:11:00 h . time and date are shown correctly on the display ( 16 x 2 display )
The led is not turn on after 5 seconds. At pin 13 there are not 5 v after 5 seconds.

What is wrong?

Thanks for your help

safran

// Den Code habe ich hauptsächlich von (C)2010 Henning Karlsen
//
// web: Electronics - Henning Karlsen
// Die Code-Schnipsel für den Alarm habe ich mir im Net zusammengesucht
// A quick demo of how to use my DS1302-library to make a quick
// clock using a DS1302 and a 16x2 LCD.

#include <LiquidCrystal.h>
#include <DS1302.h>
#include <Time.h>
#include <TimeAlarms.h>

// Init the DS1302
DS1302 rtc(6,7,8);
int LED_Pin = 13;
// Init the LCD
LiquidCrystal lcd(12,11,5,4,3,2);

void setup()
{
// Set the clock to run-mode, and disable the write protection

rtc.halt(false);
rtc.writeProtect(false);
Serial.begin(9600);
// Setup LCD to 16x2 characters
lcd.begin(16, 2);

// The following lines can be commented out to use the values already stored in the DS1302
rtc.setDOW(SATURDAY); // Set Day-of-Week to Saturday
rtc.setTime(8, 11, 0); // Set the time to 08:11:00 (24hr format)
rtc.setDate(20, 4, 2013); // Set the date to April 20th, 2013

pinMode(LED_Pin, OUTPUT);
Alarm.alarmRepeat(8, 11, 5, MorningAlarm);
}

void loop()
{
lcd.setCursor(0, 0);
lcd.print(rtc.getDOWStr(FORMAT_SHORT));
lcd.setCursor(6, 0);
lcd.print(rtc.getDateStr());
Serial.println(rtc.getTimeStr());
// Display abbreviated Day-of-Week in the lower left corner
lcd.setCursor(0, 1);

lcd.print(rtc.getTimeStr());
// Display date in the lower right corner

delay (1000);

}
//bei Aufruf des Alarms soll eine LED an Pin 13 für 5 Sekunden eingeschaltet werden
void MorningAlarm(){
digitalWrite(LED_Pin, HIGH);
delay(5000);
digitalWrite(LED_Pin, LOW);
}

You can't call delay() in a sketch involving TimeAlarms. You must use Alarm.delay() instead. The alarm class currently has no idea that time is passing.

Thanks, Paul

i try it out

safran

hello again,

i just changed the two items ( delay (1000) and delay(5000) ) in my sketch into Alarm.delay.... . Compilation and Upload worked well, but these changes don´t fix the problem :frowning: .

So i have to look for more help.

safran

Post your new code.

One thing I see you doing which is strange is setting the day of the week before setting time and date. Given a date, the time class can figure of the day of the week, so it is not necessary to set that.

There is an example provided with TimeAlarms. Have you tried the example?

Sorry, Paul,

I did not try the example, but this is the first i will do now.

safran

Hello, Paul

meanwhile i tried the example from the timealarm-library. it works, but there is no rtc included and i want to use a rtc. The strange setting of the day i took over from the sketch written bei Henning Karlsen, who wrote the DS1302-Library also.

I just don´t know the synchronization-method to synchronize the arduino time to the rtc.time in case of using the DS 1302 ( using the DS 1307 there is always used the method setSyncProvider(RTC.get), but that doesn´t work with the DS 1302.

best regards

safran

Which DS1302 library are you using? I found this one:

That contains a Time class that might be causing (some of) your problems, interfering with the Time class in the Time library (used, of course, by the TimeAlarms library).

I just don´t know the synchronization-method to synchronize the arduino time to the rtc.time in case of using the DS 1302 ( using the DS 1307 there is always used the method setSyncProvider(RTC.get), but that doesn´t work with the DS 1302.

You can write your own function that returns the same information that the DS1307::get() method does.

Hi, Paul,

i´m using this DS1302 Library from: Electronics - Henning Karlsen. In his manual ( page 3 )Henning Karlsen writes: Get current data from the DS 1302 with the function:

t=rtc.getTime();

I will try it with this term.

safran

Hi Safran,

Maybe a bit late, but I am now experiencing the same problem, did yo manage to resolve it ??
I am declaring

Time t;
t=rtc.getTime();

if you have cracked it can you please share how.

Thank you

Sorry, Tomcar_M,

but i changed the rtc, now i use the rtc 1307. there is much more code to find online and now my sketch works well.

greetings

safran