Go Down

Topic: Arduino 1: Problem with Alarm.delay ? (Read 1 time) previous topic - next topic

Jolv

Dec 18, 2011, 10:29 am Last Edit: Dec 18, 2011, 10:02 pm by Jolv Reason: 1
I am trying to upgrade a sketch to Arduino 1, but get compilation errors.
A few of the  lines which seems to create  problems have been extracted and is listed below.
(Obviously no need for Alarm.delay(3000) here, but it examples my problem.)
Can anybody give advice? Thank you.
  -   -   -   -   -   -   -   -   -   -
#include <SoftwareSerial.h>
#include <Time.h>
#include <TimeAlarms.h>

void setup()   {
 Serial.begin(9600);
}
void loop()    {
 Alarm.delay(3000);  // <<  Cause problem (?)
 Serial.print("sec= ");
 Serial.println(second());
// . . .
}

=============================================
The solution, provided by Spycatcher2K, is:

goto >      C:\Program Files\arduino-1.0\hardware\arduino\cores\arduino
Create a file called WProgram.h
and in it type :
#include <Arduino.h>

save and restart your IDE

spycatcher2k

What errors are you getting? Cut and Paste them here
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Jolv

#2
Dec 18, 2011, 12:39 pm Last Edit: Dec 18, 2011, 12:45 pm by Jolv Reason: 1
I get these error messages:
C:\Program Files\arduino-1.0\libraries\Time\Time.cpp:24:23: error: WProgram.h: No such file or directory
C:\Program Files\arduino-1.0\libraries\Time\Time.cpp: In function 'time_t now()':
C:\Program Files\arduino-1.0\libraries\Time\Time.cpp:240: error: 'millis' was not declared in this scope
C:\Program Files\arduino-1.0\libraries\Time\Time.cpp: In function 'void setTime(time_t)':
C:\Program Files\arduino-1.0\libraries\Time\Time.cpp:268: error: 'millis' was not declared in this scope
- - - - - -
It har probably somthing to do with Arduino 1, Release note:
* The WProgram.h file, which provides declarations for the Arduino API,
 has been renamed to Arduino.h. To create a library that will work in
 both Arduino 0022 and Arduino 1.0, you can use an #ifdef that checks
 for the ARDUINO constant, which was 22 and is now 100.  For example:
 ...

It is probably absolutely trivial for an experienced user to find the WProgram.h files and copy them them into the library, but I have not been able to do so even after a lot of searching.

spycatcher2k

#3
Dec 18, 2011, 12:43 pm Last Edit: Dec 18, 2011, 01:38 pm by spycatcher2k Reason: 1
goto >      C:\Program Files\arduino-1.0\hardware\arduino\cores\arduino


Create a file called Arduino.h

and in it type :

#include <WProgram.h>

save and restart your IDE

See if this helps.
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Jolv

Sorry, no success.

I tried to follow your advice, but got a bunch of new errors (perhaps I did a mistake).
I also compaired ...\cores\arduino for .0023 and 1., and found that 1. does not include WProgram.h. I tried to include WProgram.h in ...\cores\arduino for 1., but it did not help.

I suppose I am to unexperienced with this type of programing to handle this problem. Do not understand properly what I am doing. -  After all .0023 does a fine job for me, and I will stick with it for now.

Thank you very much, spycatcher2k, for your advice.

spycatcher2k

I just compiled your code with IDE 1.0 with no errors
When you created the file and contents, did you make sure to match CASE as they are CASE SENSATIVE.
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Jolv

#6
Dec 18, 2011, 07:21 pm Last Edit: Dec 18, 2011, 07:33 pm by Jolv Reason: 1
Thanks again!  I hate to give up, and a solution cannot be very far away since it compiles on your computer. Where do I go wrong?? -  A have reinstalled Arduino-1.0 and new copies Time.h and TimeAlarms.h

In   C:\Program Files\arduino-1.0\hardware\arduino\cores\arduino
it is already a file called Arduino.h,  so I am confused. Should I really make another file with the same name? (In fact I have tried to do that also, but with 0 success).

I have also simplified my sketch down to:

#include <SoftwareSerial.h>
#include <Time.h>
#include <TimeAlarms.h>
void setup()   { }
void loop()    { }

If I comment out #include <TimeAlarms.h> it compiles OK. If I don't  I get these error message:

C:\Program Files\arduino-1.0\libraries\TimeAlarms\TimeAlarms.cpp:25:22: error: WProgram.h: No such file or directory
C:\Program Files\arduino-1.0\libraries\TimeAlarms\TimeAlarms.cpp: In member function 'void TimeAlarmsClass::delay(long unsigned int)':
C:\Program Files\arduino-1.0\libraries\TimeAlarms\TimeAlarms.cpp:256: error: 'millis' was not declared in this scope


spycatcher2k

My Bad !!!!!

Create WProgram.h

#include <Arduino.h>

Got it back to front - So Sorry
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Jolv

#8
Dec 18, 2011, 09:53 pm Last Edit: Dec 19, 2011, 08:34 am by Jolv Reason: 1
Thank you spycatcher2k! Great.    It works!!!

nicocarv

I got the same problem but this solution didn't worked for me.

So instead of creating the file WProgram.h, I edited the file TimeAlarms.cpp (you can find it in the library directory) and then changed the following 

#include <WProgram.h>  by   #include <Arduino.h>

So I finally got (extract of the file)


<<extern "C" {
#include <string.h> // for memset
}

#include <Arduino.h>
#include "TimeAlarms.h"
#include "Time.h"

#define IS_ONESHOT  true   // constants used in arguments to create method
#define IS_REPEAT   false


//**************************************************************
//* Alarm Class Constructor >>

Go Up