mini RTOS [sic]

Hi everyone,

First time poster, long time forum-scourer... :slight_smile:

I've been madly searching these forums since receiving my Diecimila a few weeks ago, trying to cobble together some alarm code that I can use to trigger a camera at a given time each day. I was very pleased to find this thread, but I can't seem to work out why I get compile errors when using mem's example code from reply #2 or reply #16. For reply #2, I get:

[EDIT] Never mind, I fixed this first problem..

For reply #16, I get:

In function 'void setup()':
error: 'class dtAlarmsClass' has no member named 'registerTimer' In function 'void loop()':

relating to:

 Wire.begin();
    // you can register time of day Alarms at any time but really shouldn't enable them until the internal clock is set
   if( dtAlarms.registerTimer( &TimeForPhoto ) ) {        
     TimeForPhoto.value = AlarmHMS(12,30,0)    // this is 30 minutes after 12 noon
     TimeForPhoto.onTickHandler = &OnTimeForPhotoTick;
     TimeForPhoto.Mode.isTimeOfDay = true;
     TimeForPhoto.enable(); // the above registers an alarm, labelled 'TimeForPhoto', as one that triggers at the given time
 of day.
  }

I'm able to follow the coding to a certain extent, but this is well above anything I've tried before... I've ordered a Mini-DS1307 board to supply the time, so until that comes I thought I'd work on the alarm code.

Any help would be greatly appreciated - and by the way, congrats on such a friendly, supportive forum!

JB

Hi again...
Fixing my first problem has left me with another; here's the code:

#include <DateTime.h>
#include <DateTimeAlarms.h>

AlarmID_t Alarm9,Alarm12,Timer11;  // id to identify what triggered alarm if callbacks are shared

void setup(){
  Serial.begin(19200);
  Alarm9 = dtAlarms.createAlarm( DateTime.now() + 9, OnAlarm); // trigger 9 seconds from now
  Alarm12 = dtAlarms.createAlarm(AlarmHMS(12,0,0), OnAlarm); // trigger at mid day
  Timer11 = dtAlarms.createTimer( 11, OnTimer); // trigger in 11 seconds
}

void OnAlarm(AlarmID_t Sender){
  // callback for time of day alarms
  if( Sender ==  Alarm9) {
    Serial.print("Alarm9: ");        
    dtAlarms.setValue(Alarm9, DateTime.now() + 9 ); // reset alarm to trigger at the time that is 9 seconds from now
  }
  else  if( Sender ==  Alarm12)
  {
    Serial.print("Alarm12: ");
    dtAlarms.setValue(Alarm12, AlarmHMS(12,0,0)); // reset alarm to trigger at noon
  }    
}

void OnTimer(AlarmID_t Sender){
  // callback for time delay alarm
  Serial.print("Timer11: 11 sec timer: ");    
  dtAlarms.setValue(Timer11, 11 ); // delay another 11 seconds
}

void  loop(){  
  
  dtAlarms.waitUntilThisSecond(0); //  this code blocks waiting for start of the next minute, background alarms are still serviced
  digitalWrite(13, HIGH);
  dtAlarms.delay(2000);  // note we call the alarm delay to service the background alarms
  digitalWrite(13,LOW);  
  dtAlarms.delay(2000); // delay is in milliseconds , all other alarm values are seconds
}

...which gives me the following error:

o: In function loop': undefined reference to dtAlarms'o: In function OnTimer(unsigned char)': o: In function OnAlarm(unsigned char)':
o: In function `setup':

Again, thanks for any thoughts!

Hi JB, the sketch you posted above compiles ok for me on version 0011 and 0012, which version are you using?

If 0012, are you using the latest version of DateTime.h (if not then download the latest DateTime from the library)

Hi mem,

The errors posted are from 0011. I've tried with 0012, but I think I've done something wrong when I instaleld that. On compiling, I get this:

o: In function `loop':
C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:39: undefined reference to `dtAlarms'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:39: undefined reference to `dtAlarms'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:39: undefined reference to `dtAlarmsClass::waitForDigits(unsigned char, dtUnits_t)'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:41: undefined reference to `dtAlarmsClass::delay(unsigned long)'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:43: undefined reference to `dtAlarmsClass::delay(unsigned long)'


o: In function `OnTimer(unsigned char)':
C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:34: undefined reference to `dtAlarms'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:34: undefined reference to `dtAlarms'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:34: undefined reference to `dtAlarmsClass::setValue(unsigned char, unsigned long)'


o: In function `OnAlarm(unsigned char)':
C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:22: undefined reference to `dtAlarms'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:22: undefined reference to `dtAlarms'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:22: undefined reference to `dtAlarmsClass::setValue(unsigned char, unsigned long)'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:27: undefined reference to `dtAlarms'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:27: undefined reference to `dtAlarms'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:27: undefined reference to `dtAlarmsClass::setValue(unsigned char, unsigned long)'


o: In function `setup':
C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:13: undefined reference to `dtAlarms'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:13: undefined reference to `dtAlarms'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:13: undefined reference to `dtAlarmsClass::createAlarm(unsigned long, void (*)(unsigned char), unsigned char)'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:14: undefined reference to `dtAlarmsClass::createAlarm(unsigned long, void (*)(unsigned char), unsigned char)'


C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp/Temporary_6757_4834.cpp:15: undefined reference to `dtAlarmsClass::createTimer(unsigned long, void (*)(unsigned char), unsigned char)'


Couldn't determine program size: C:\Documents and Settings\john\My Documents\arduino-0012\hardware/tools/avr/bin/avr-size: 'C:\DOCUME~1\john\LOCALS~1\Temp\build61366.tmp\DateTimeAlarmsSketch.hex': No such file

I've got a feeling that this is going to be an embarassingly easy thing to fix but I can't put my finger on it.

dtAlarms is an object that is made when DateTimeAlarms.cpp is compiled and is defined in DateTimeAlarms.h

Try deleting DateTimeAlarms.o and recompile your sketch and check to see if the .o file is created.

Did you change the DateTimeAlarms.h file? If so, try replacing your copy with the DateTimeAlarms.h code in the thread.

I was pretty sure that I'd replaced the DateTimeAlarms.h file, but I decided to do a clean install of v0012 in a seperate location anyway. I have a DateTimeAlarms library, but it's only got the DateTimeAlarms.h file; I don't seem to have the DateTimeAlarms.cpp or DateTimeAlarms.o file anywhere, and can't locate it on the forums or main site.

I'm guessing that if someone can point me to that file, my problems may just disappear...

Thanks again!

JB the files are posted in the begining of this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1217881285

try it in 0011 and see if that fixes your problem. the files need a small mod for 0012 and these were posted today in that thread

The mod for 0012 is to move #include <wiring.h> from DateTimeAlarms.h and put it into DateTimeAlarms.cpp

OK, so now we get to the bit that's confused me every time I've read this thread: hotcarrier wrote -

mem,
Did you mean TimerAlarms.h ?

... to which you replied -

Yes, DateTimeAlarms.h

:-? Sorry if I've missed something here, but the thread you directed me to has 'TimerAlarms' files in it, not 'DateTimeAlarms'. I tried renaming them, and replacing any 'TimerAlarm' references with 'DateTimeAlarms' references but that didn't work. Also tried it in 0011 with similar results. I AM getting a different error now though:

In file included from C:\arduino-0012\hardware\cores\arduino/WProgram.h:4,


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected unqualified-id before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected `)' before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:80: error: expected `)' before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:111: error: expected `)' before 'int'


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected identifier before '(' token


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected `)' before '(' token


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected ',' or '...' before '(' token


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:144: error: expected initializer before ')' token


c:/arduino-0012/hardware/tools/avr/lib/gcc/../../avr/include/stdlib.h:176: error: '__compar_fn_t' has not been declared


In file included from C:\arduino-0012\hardware\cores\arduino/WProgram.h:6,


 In function 'void setup()':

What am I missing?!? I feel like such a newb... ::slight_smile:

Sorry, just picked up on your comment about MOVING #include <wiring.h> from one file to the other... much better, but still have this last little error:

In function 'void setup()':
error: 'class dtAlarmsClass' has no member named 'createAlarm'

Which is a lot nicer than what I had before...

Again, sorry for not reading your post correctly!! [smiley=embarassed.gif]

JB, the sketch you posted compiles on my PC without any errors in 0012 with the <wiring.h> moved from the .h file to the .cpp file.

Have you tried to use the .h and .cpp file I posted today in the other thread?

If you are still stuck, send me a Personal Message with your email address and I will email you the files you need to put in the DateTimeAlrams directory.

Hi mem,

As we'd say in Australia - you beauty, all sorted! :smiley:

I've read so many threads where you've helped others, on matters MUCH more complicated than mine. It's a rare thing for someone to be able to provide assistance so happily and helpfully to beginners and 'experts' alike; your parents would be proud! :slight_smile:

Thanks for your help, and I'm sure I'll have more questions as my project matures. FYI, the project goes something like this:

  • A remote automated camera system to take photos of key wetlands once or twice a day
  • Using a Canon Powershot A720 consumer camera, with modified firmware (see CHDK Wiki | Fandom for more info - I'm sure there are people here who would be interested in what the CHDK community has achieved)
  • Thermistor to monitor enclosure temperature, and operate fans when required
  • DS1307 mini-board (DS1307 Real Time Clock Mini Board) for RTC
  • Arduino to control fans, camera power & solenoid to turn camera on at specific times
    Believe it or not, this is all part of a WORK project, so I get to spend my time playing with Arduino & all sorts of other fun bits & pieces; I'm LIVING the tinkering philosophy! :sunglasses:

Thanks again for your help, that sketch has compiled happily under 0012. Tomorrow I'll start working on how to integrate this with the rest of the code I've pulled together - hopefully my DS1307 board isn't far away!

Hi JB, happy to help, and its a particular pleasure when I hear about interesting projects like yours. I am intrigued about the ways people use stuff that I have posted, I would be interested in hearing how you have implemented the alarms in your application,

When you get a chance, why not post some more information in the exhibition area.

Have fun!

Hi again...

I'm having some trouble compiling the following code (from reply #16) and hoped that someone could help me out...

#include <DateTime.h>
#include <DateTimeAlarms.h>

AlarmClass Timer1;
AlarmClass Timer2;
AlarmClass Timer3;

void setup(){
  // you can register time of day Alarms at any time but really shouldn't enable them until the internal clock is set

   if( dtAlarms.registerTimer( &Timer1 ) ) {        
     Timer1.value = DateTime.now() + 11;   // fire at the time of day 11 seconds from now
     Timer1.Mode.isTimeOfDay = true; // the value given above is a time of day
     Timer1.onTickHandler = &OnTimer1Tick;
     Timer1.enable();  
  }

   if( dtAlarms.registerTimer( &Timer2 ) ) {        
     Timer2.value = AlarmHMS(12,30,0)    // this is 30 minutes after 12 noon
     Timer2.onTickHandler = &OnTimer2Tick;
     Timer2.Mode.isTimeOfDay = true;
     Timer2.enable();  
  }
   if( dtAlarms.registerTimer( &Timer3 ) ) {        
     Timer3.Mode.isTimeOfDay = false; // the timer value is treated as a delay in seconds, not absolute time
     Timer3.value =  13;   // delay in seconds from the time this alarm is enabled
     Timer3.onTickHandler = &OnTimer1Tick;
     Timer3.enable();  
  }

}

 void OnTimer1Tick(void *Sender){

  if( Sender ==  &Timer1)
      Serial.print("Timer1 event: ");
   else  if( Sender ==  &Timer3)
      Serial.print("Timer3 event: ");
  timeDisplay();    
 }


void OnTimer2Tick(void *Sender){
    Serial.print("Timer2 event: ");  
}

On trying to compile this code I get the following error:

In function 'void setup()':
error: 'class dtAlarmsClass' has no member named 'registerTimer' In function 'void OnTimer1Tick(void*)':

I'm using 0012, and have the latest DateTimeAlarm cpp and h files. I've got my DS1307 mini-board attached & sending me the time (in a seperate sketch), but now I need to create alarms to fire at specific times every day.

Hi JB, The library was changed a while ago to simplify the creation of alarms. The code from post#16 used the old method. The code you posted earlier did use the latest version, sorry that this long thread got you confused. I must find some time to post this in the playground so the latest information is easier to find.

Anyway, here is the sketch posted above updated to compile with the latest version of the library code:

#include <DateTime.h>
#include <DateTimeAlarms.h>

AlarmID_t Timer1, Timer2, Timer3;

void setup(){

   Timer1 = dtAlarms.createTimer(DateTime.now()+ 11, OnTimer1Tick);
/* the expression above replaces the code commented out below   
   if( dtAlarms.registerTimer( &Timer1 ) ) {
     Timer1.value = DateTime.now() + 11;   // fire at the time of day 11 seconds from now
     Timer1.Mode.isTimeOfDay = true; // the value given above is a time of day
     Timer1.onTickHandler = &OnTimer1Tick;
     Timer1.enable();
  }
*/

   Timer2 = dtAlarms.createTimer(AlarmHMS(12,30,0), OnTimer2Tick); 
/*
   if( dtAlarms.registerTimer( &Timer2 ) ) {
     Timer2.value = AlarmHMS(12,30,0)    // this is 30 minutes after 12 noon
     Timer2.onTickHandler = &OnTimer2Tick;
     Timer2.Mode.isTimeOfDay = true;
     Timer2.enable();
  }
*/

  Timer3 = dtAlarms.createAlarm(13, OnTimer1Tick); 
/*
   if( dtAlarms.registerTimer( &Timer3 ) ) {
     Timer3.Mode.isTimeOfDay = false; // the timer value is treated as a delay in seconds, not absolute time
     Timer3.value =  13;   // delay in seconds from the time this alarm is enabled
     Timer3.onTickHandler = &OnTimer1Tick;
     Timer3.enable();
  }
*/

}

 void OnTimer1Tick(AlarmID_t Sender){

  if( Sender ==  Timer1 )
      Serial.print("Timer1 event: ");
   else  if( Sender == Timer3 )
      Serial.print("Timer3 event: ");
 }


void OnTimer2Tick(AlarmID_t Sender){
    Serial.print("Timer2 event: ");
}

void loop(){
  
}

Sorry for not replying sooner, I've been away from home for the weekend... Thanks for this code, it's compiled happily as promised. I'm now basically at the point where I can assemble the separate code fragments I've 'collected' together & have my system up & running! :slight_smile:

I'll be having a test-build of a complete system soon (I've got other priorities over the next few weeks), so when I've finished that I'll definitely post it in the exhibition area.

Thanks again for your help mem (and all other forum members who have unknowingly helped my understanding of the Arduino environment!), and I'll pop a note in this thread when I put something in the exhibition area.

Cheers,

JB.

Back for more help...

Is there an alarm which I can set to go off at a specific time of day? I thought that the dtAlarms.createTimer(AlarmHMS(12,30,0), OnTimer2Tick); command was referring to an hour, minute & second of the day (obtained from the RTC), not time since the sketch started running, then repeating after the same H/M/S. I need to be able to have my program trigger a camera at 2 or 3 different times during the day, setting up the times in the sketch.

Thanks again,

JB

Hi JB,

dtAlarms.createTimer(AlarmHMS(12,30,0), OnTimer2Tick);

is a timer, it will call OnTimer2Tick 12 and a half hours after it is set using the above code.

If you want an alarm that triggers at 12:30 and say 3:30 every day you want this code:

dtAlarms.createAlarm(AlarmHMS(12,30,0), OnTimer2Tick);
dtAlarms.createAlarm(AlarmHMS(15,30,0), OnTimer2Tick);

Hi mem,

Thanks for that, I'll give that a try next week. While working on it today I came up with this little line:

 if (hour == 14) { if (minute == 07) { if (second == 00) { TakePhoto();}}}
 if (hour == 14) { if (minute == 07) { if (second == 30) { TakePhoto();}}}
 if (hour == 14) { if (minute == 10) { if (second == 00) { TakePhoto();}}}

referencing to the DS1307 real-time clock. Seemed to work just fine, and means I don't need to worry about the OnTimerTick functions. I do need to consider the fact that, in the future, other people (who may not be particularly computer literate) need to be able to easily modify these alarms. I'll put both solutions to my not-so-PC-literate workmate & see which one he likes best! :slight_smile:

Cheers, JB.

Hi, we have ported FreeRTOS past year (2009), you can look at these links:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1256745982/0

The versión 0.1 Alpha (for the 0017 IDE) is available here:

http://www.multiplo.org/duinos/wiki/index.php?title=Main_Page

And there is a v0.2 Alpha which runs in 0018 at:

http://novell.chel.ru/get.php?file=DuinOS_v0.2_Alpha

We did not make the v0.2, but are working in the v0.3.

It runs acceptable on the 328s, and better on the megas (and in our own 644 based boards). The 168 may be too small.

Regards,
Julián

Back to top