Pages: 1 [2]   Go Down
Author Topic: clock with multiple alarms  (Read 3529 times)
0 Members and 1 Guest are viewing this topic.
Indonesia
Offline Offline
Newbie
*
Karma: 0
Posts: 39
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am not clear on what is not working,

my problems are :
1. I want to set the value of start alarm, stop alarm, and interval alarm from serial message,
    but when I finished sending the serial data, the alarms won't start, stop or RINGING at the time that I've set.
    example :
    I send serial message : I185118530001185218540002 ( this data only contains hour and minute values)
    So,
    ROOM 1 :
    Alarm with ID "alarmStart1" is set to 18:51:00 (second value is set from the sketch, is not set from serial message)
    Alarm with ID "alarmStop1" is set to 18:53:30 (second value is set from the sketch, is not set from serial message)
    Alarm with ID "alarmTimer1" is set to ring every 1 minutes (0001==>HHMM)

    ROOM 2 :
    Alarm with ID "alarmStart2" is set to 18:52:10 (second value is set from the sketch, is not set from serial message)
    Alarm with ID "alarmStop1" is set to 18:54:30 (second value is set from the sketch, is not set from serial message)
    Alarm with ID "alarmTimer1" is set to ring every 2 minutes (0002==>HHMM)

    my goals are : (and this is what I said not working)
   alarm ROOM 1 will ring at 18:52:00 and 18:53:00
   alarm ROOM 2 will only ring at 18:54:10
   
   
2. If I send serial message (I185118530001185218540002) when serial monitor shows "18:50:46".
   alarm for ROOM 1 will ring at 18:51:47, 18:52:47, 18:53:47, 18:54:47, ... (won't stop)
   alarm for ROOM 2 will ring at 18:52:47, 18:54:47, ... (won't stop)
   
Quote
how are you checking to make sure that the time you are setting are correct?
I saw your post (here) about how to read alarm.
this is my code for interval(), showAlarmTime(), and digitalClockDisplay1()[different with digitalClockDisplay()] Functions
Code:
void Interval()
{
  unsigned long startTime = millis();
  while(Serial.available() < 24)
  {
    if(millis() - startTime > 1000)
    {
       Serial.println("got header but timed out waiting for 24 bytes");
       return;
    }
  }   

   //===========for ROOM 1===========
   hourStart1 = getIntFromAscii(2);
   minuteStart1 = getIntFromAscii(2);
   hourStop1 = getIntFromAscii(2);
   minuteStop1 = getIntFromAscii(2);
   hourInterval1 = getIntFromAscii(2);
   minuteInterval1 = getIntFromAscii(2);
   
   //===========for ROOM 2===========
   hourStart2 = getIntFromAscii(2);
   minuteStart2 = getIntFromAscii(2);
   hourStop2 = getIntFromAscii(2);
   minuteStop2 = getIntFromAscii(2);
   hourInterval2 = getIntFromAscii(2);
   minuteInterval2 = getIntFromAscii(2);
   
   //================================================================room 1
   time_t newStart1 = AlarmHMS (hourStart1, minuteStart1, 0);
   Alarm.write (alarmStart1, newStart1);
   time_t newStop1   = AlarmHMS (hourStop1, minuteStop1, 30);
   Alarm.write (alarmStop1, newStop1);
   time_t newInterval1 = AlarmHMS (hourInterval1, minuteInterval1, 0);
   Alarm.write (alarmTimer1, newInterval1);
   
   //================================================================room 2
   time_t newStart2 = AlarmHMS (hourStart2, minuteStart2, 10);
   Alarm.write (alarmStart2, newStart2);
   time_t newStop2   = AlarmHMS (hourStop2, minuteStop2, 30);
   Alarm.write (alarmStop2, newStop2);
   time_t newInterval2 = AlarmHMS (hourInterval2, minuteInterval2, 0);
   Alarm.write (alarmTimer2, newInterval2);
   
   //check alarm data ROOM 1
   Serial.println(hourStart1, DEC);
   Serial.println(minuteStart1, DEC);
   Serial.println(hourStop1, DEC);
   Serial.println(minuteStop1, DEC);
   Serial.println(hourInterval1, DEC);
   Serial.println(minuteInterval1, DEC);
   
   //check alarm data ROOM 2
   Serial.println(hourStart2, DEC);
   Serial.println(minuteStart2, DEC);
   Serial.println(hourStop2, DEC);
   Serial.println(minuteStop2, DEC);
   Serial.println(hourInterval2, DEC);
   Serial.println(minuteInterval2, DEC);
   
   showAlarmTime(alarmStart1);
   showAlarmTime(alarmStop1);
   showAlarmTime(alarmTimer1);
   showAlarmTime(alarmStart2);
   showAlarmTime(alarmStop2);
   showAlarmTime(alarmTimer2);
}

void showAlarmTime(AlarmID_t id)
{
  time_t alarmTime = Alarm.read(id);
  if(alarmTime!= 0)
  {
    if( alarmTime <= SECS_PER_DAY) 
       Serial.print(" repeat alarm with ID ");
    else 
        Serial.print(" once only alarm with ID  ");
    Serial.print(id, DEC);   
    Serial.print(" set for ");
    digitalClockDisplay1(alarmTime);
  } 
}


void digitalClockDisplay1(time_t t)
{
  // digital clock display of the time
  Serial.print(hour(t));
  printDigits(minute(t));
  printDigits(second(t));
  Serial.println();
}

Quote
If you change the setup values to the times you are sending in your message, does the sketch work as expected?
Yes, i've tried it.
« Last Edit: July 25, 2011, 10:01:49 am by copet_pitik » Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it will be easier to identify what is wrong if you break your functions down into smaller units.

For example, separate your interval function gets serial data and sets the alarms. if you separate them you can test each part on its own.

here is a new function that sets alarms:
Code:
void setAlarm( int alarmNumber, int start, int stop, int interval)
{
  if(alarmNumber == 1)
  {   
     Alarm.write (alarmStart1, start);
     Alarm.write (alarmStop1, stop);
     Alarm.write (alarmTimer1, interval);   
   }
   else if(alarmNumber == 1)
  {   
     Alarm.write (alarmStart2, start);
     Alarm.write (alarmStop2, stop);
     Alarm.write (alarmTimer2, interval);   
   }
   
   Serial.print("Seting alarm ");
   Serial.println(alarmNumber);
   Serial.print("Start:  ");
   digitalClockDisplay(start);
   Serial.print("Stop:  ");
   digitalClockDisplay(stop);
   Serial.print("Interval :  ");
   digitalClockDisplay(interval);
}


here is the old interval function renamed to getNewAlarmTimes, this calls the function above to actually set the alarm
Code:
void getNewAlarmTimesl()

  unsigned long startTime = millis();
  while(Serial.available() < 24)
  {
    if(millis() - startTime > 1000)
    {
       Serial.println("got header but timed out waiting for 24 bytes");
       return;
    }
  }   

   //===========for ROOM 1===========
   hourStart1 = getIntFromAscii(2);
   minuteStart1 = getIntFromAscii(2);
   hourStop1 = getIntFromAscii(2);
   minuteStop1 = getIntFromAscii(2);
   hourInterval1 = getIntFromAscii(2);
   minuteInterval1 = getIntFromAscii(2);
   
   //===========for ROOM 2===========
   hourStart2 = getIntFromAscii(2);
   minuteStart2 = getIntFromAscii(2);
   hourStop2 = getIntFromAscii(2);
   minuteStop2 = getIntFromAscii(2);
   hourInterval2 = getIntFromAscii(2);
   minuteInterval2 = getIntFromAscii(2);
   
   //================================================================room 1
   time_t newStart,newStop,newInterval; 

   newStart = AlarmHMS (hourStart1, minuteStart1, 0);
   newStop  = AlarmHMS (hourStop1, minuteStop1, 30);
   newInterval = AlarmHMS (hourInterval1, minuteInterval1, 0);
   setAlarm(1, newStart, newStop, newInterval);
   
   //================================================================room 2
   
   newStart = AlarmHMS (hourStart2, minuteStart2, 0);
   newStop  = AlarmHMS (hourStop2, minuteStop2, 30);
   newInterval = AlarmHMS (hourInterval2, minuteInterval2, 0);
   setAlarm(2, newStart, newStop, newInterval);     
}

if your digitalClockDIsplay function does not take a paramater, use this one:
Code:
void digitalClockDisplay(time_t t)
{
  // digital clock display of the time
  Serial.print(hour(t));
  printDigits(minute(t));
  printDigits(second(t));
  Serial.println();
}

Let me know If the printed alarm times are as expected but the alarms are not starting or stopping correctly, if not we can write a test sketch that uses setLarm to set some hard coded times and see if we can get that working.

Logged

Indonesia
Offline Offline
Newbie
*
Karma: 0
Posts: 39
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

still got the problems,mem..same problem.
I don't know the problems is on my code, algorithm, or me  smiley-roll-blue
but, when I tried our code in post #16,
when I send serial data that the hour < 9 (ex: I083008320001083108330002) the alarm is set, but the won't ring at the time that I set.
      If I send serial data that the hour >= 9 (ex: I174117430001174217440002) the alarms is misbehaving : the alarm is not set as the data that I sent
      and not ring at the time that I set.

then, i check each alarm ID and find something misbehaving..I don't really know why.
this is what i got:

serial data input : I083008320001083108330002
output:
Code:

 time is synced! 
8:29:41 //I send T to read all alarm IDs
 repeat alarm with ID 0 set for 20:27:00 // the alarm with ID 0-5 is set from setup() Function
 repeat alarm with ID 1 set for 20:29:30
 repeat alarm with ID 2 set for 0:01:00
 repeat alarm with ID 3 set for 20:28:10
 repeat alarm with ID 4 set for 20:30:30
 repeat alarm with ID 5 set for 0:02:00
8:29:42
8:29:43
8:29:44
8:29:45
8:29:46
8:29:47
8:29:48
8:29:49
8:29:50
8:29:51 //I send this data I083008320001083108330002
Seting alarm 1
Start:  8:30:00 //just as I expected
Stop:  8:32:30 //just as I expected
Interval :  0:01:00 //just as I expected
30600 //Serial.print on Function getNewAlarmTimesl()  for variable "newStart" : hour = 8, minute = 30 [(8*3600)+(30*60)=30600] 
30750 //Serial.print on Function getNewAlarmTimesl() for variable "newStop"  : hour = 8, minute = 32
60 //Serial.print on Function getNewAlarmTimesl() for variable "newInterval" : hour = 0, minute = 1
Seting alarm 2
Start:  8:31:00 //just as I expected
Stop:  8:33:30 //just as I expected
Interval :  0:02:00 //just as I expected
30660
30810
120
8:29:52
8:29:53
8:29:54
8:29:55
8:29:56
8:29:57 //I send T to make sure that the alarms
 repeat alarm with ID 0 set for 8:30:00
 repeat alarm with ID 1 set for 8:32:30 // alarms with ID 0-5 as I expected
 repeat alarm with ID 2 set for 0:01:00
 repeat alarm with ID 3 set for 8:31:00
 repeat alarm with ID 4 set for 8:33:30
 repeat alarm with ID 5 set for 0:02:00
8:29:58
8:29:59
8:30:00



serial data input : I174117430001174217440002
output:

Code:
time is synced! 
8:29:41
8:29:42 //I send T to read all alarm IDs
 repeat alarm with ID 0 set for 20:27:00 // the alarm with ID 0-5 is set from setup() Function
 repeat alarm with ID 1 set for 20:29:30
 repeat alarm with ID 2 set for 0:01:00
 repeat alarm with ID 3 set for 20:28:10
 repeat alarm with ID 4 set for 20:30:30
 repeat alarm with ID 5 set for 0:02:00
8:29:43
8:29:44
8:29:45
8:29:46
8:29:47
8:29:48
8:29:49
8:29:50
8:29:51 //I send this data I174117430001174217440002
Seting alarm 1
Start:  5:57:00 //Expected value at : 17:41:00
Stop:  5:59:30 //Expected value at : 17:43:30
Interval :  0:01:00 //just as I expected
63660 //Serial.print on Function getNewAlarmTimesl()  for variable "newStart" : hour = 17, minute = 41 [(17*3600)+(41*60)=63660] 
63810 //Serial.print on Function getNewAlarmTimesl()  for variable "newStart" : hour = 17, minute = 43
60 //Serial.print on Function getNewAlarmTimesl()  for variable "newStart" : hour = 0, minute = 1
Seting alarm 2
Start:  5:58:00 //Expected value at : 17:42:00
Stop:  6:00:30 //Expected value at : 17:434:30
Interval :  0:02:00 //just as I expected
63720
63870
120
8:29:52
8:29:53
8:29:54
8:29:55
8:29:56
8:29:57
8:29:58
8:29:59
8:30:00
8:30:01 //I send T to make sure that the alarms
 once only alarm with ID  0 set for 5:57:00 //it should be repeat alarm. and have different value with data that I sent
 once only alarm with ID  1 set for 5:59:30 //it should be repeat alarm. and have different value with data that I sent
 repeat alarm with ID 2 set for 0:01:00
 once only alarm with ID  3 set for 5:58:00 //it should be repeat alarm. and have different value with data that I sent
 once only alarm with ID  4 set for 6:00:30 //it should be repeat alarm. and have different value with data that I sent
 repeat alarm with ID 5 set for 0:02:00
8:30:02
8:30:03

I don't really know how to explain this problems,
but I attach my sketch and my serial output data.
this sketch only contains Time and TimeAlarm library.

* twoIntervalAlarms.pde (6.54 KB - downloaded 14 times.)
* Serial Monitor datas 1.txt (1.72 KB - downloaded 8 times.)
* Serial Monitor datas 2.txt (2.06 KB - downloaded 5 times.)
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

From you post it looks like you be setting alarm times that are not correct which would indicate a problem with your serial decoding

Quote
Start:  5:57:00      //Expected value at : 17:41:00
Stop:  5:59:30      //Expected value at : 17:43:30

if you wanted to send an alarm start time of 17:41 but actually got 5:57 then you need to focus on the serial message handling.

I suggest you write a test sketch that has no Alarm functionality - just interpret the values you get for start, stop and interval from the serial message see if they make sense.
This will help you determine if the problem caused by giving TimerAlarm incorrect value or if the correct values are being set but the alarm library is not handling them as you expect.




Logged

Indonesia
Offline Offline
Newbie
*
Karma: 0
Posts: 39
ayooo,,,DAB!!!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this problems is handled, just call setup again.. smiley-roll-blue
the serial data is okay..now, it just work don't wanna be the perfect one..not enough time to figure it out..
if i have another questions, I hope get another helps, especially from you, mem. smiley
thanks for all the discussions..
Logged

Pages: 1 [2]   Go Up
Jump to: