Can't complile TimeAlarm library without getting error Alarm out of scope

Hello,
I am having problems using the Time and TimeAlarm libraries with my Arduino UNO and a Macintosh power book. I am not a programmer, but I have googled the forums etc to try to find solutions to my problem, to no avail.d

Specifically, when I try to compile the TimeAlarmExample that came along with the TimeAlarm library that I downloaded, I keep getting the error message: ” ‘Alarm’ was not declared in this scope” . I have tried the following:

  1. made sure that the TimeAlarm.cpp and TimeAlarm.h files are in my “Libraries” folder for Arduino, not nested in other folders.
  2. Used textedit to check the cpp file to make sure it is updated to call Arduino.h instead of WProgram.h.
  3. Changed the brackets (ie, <>) around the library calls to quotes (ie, “ “), for example: #include <Time.h> becomes #include “Time.h”
  4. I went into the TimeAlarms cpp file and could not find an “alarm” definition, but I did find AlarmID_t. I tried changing the example sketch to use AlarmID_t instead of alarm, but this did not work either (perhaps I don’t understand the syntax?)
    In what may be a related problem, in trying to run any of the time related example scripts, I notice that the serial monitor gets the message “waiting for sync message”, which makes me think the UNO is NOT getting a synch message from my Mac. This makes me wonder if for some reason neither the time nor timealarms libraries are being loaded and/or recognized correctly.

Can anyone make a suggestion to solve these problems? Following is the example TimeAlarmExample sketch that I am trying to run:

/*
 * TimeAlarmExample.pde
 *
 * This example calls alarm functions at 8:30 am and at 5:45 pm (17:45)
 * and simulates turning lights on at night and off in the morning
 * A weekly timer is set for Saturdays at 8:30:30
 *
 * A timer is called every 15 seconds
 * Another timer is called once only after 10 seconds
 *
 * At startup the time is set to Jan 1 2011  8:29 am
 */
 
#include "Time.h"
#include "TimeAlarms.h"

void setup()
{
  Serial.begin(9600);
  setTime(8,29,0,1,1,11); // set time to Saturday 8:29:00am Jan 1 2011
  // create the alarms 
  Alarm.alarmRepeat(8,30,0, MorningAlarm);  // 8:30am every day
  Alarm.alarmRepeat(17,45,0,EveningAlarm);  // 5:45pm every day 
  Alarm.alarmRepeat(dowSaturday,8,30,30,WeeklyAlarm);  // 8:30:30 every Saturday 

 
  Alarm.timerRepeat(15, Repeats);            // timer for every 15 seconds    
  Alarm.timerOnce(10, OnceOnly);             // called once after 10 seconds 
}

void  loop(){  
  digitalClockDisplay();
  Alarm.delay(1000); // wait one second between clock display
}

// functions to be called when an alarm triggers:
void MorningAlarm(){
  Serial.println("Alarm: - turn lights off");    
}

void EveningAlarm(){
  Serial.println("Alarm: - turn lights on");           
}

void WeeklyAlarm(){
  Serial.println("Alarm: - its Monday Morning");      
}

void ExplicitAlarm(){
  Serial.println("Alarm: - this triggers only at the given date and time");       
}

void Repeats(){
  Serial.println("15 second timer");         
}

void OnceOnly(){
  Serial.println("This timer only triggers once");  
}

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);
}

Thanks.

DadEE:

  1. made sure that the TimeAlarm.cpp and TimeAlarm.h files are in my “Libraries” folder for Arduino, not nested in other folders.
  1. They should be in the "libraries" directory
  2. They should be in a directory in the "libraries" directory named "TimeAlarm"

So it should be

sketchbook
--<other sketches>
--libraries
----TimeAlarm
------TimeAlarm.h
------TimeAlarm.cpp
----<other libraries>

Thank you to WizenedEE for your quick response. Using nested folders seems to have worked and the TimeAlarmsExample sketch seems to work correctly.

I also created a nested folder for the Time library, but when I run the TimeSerialDateStrings example sketch, the Arduino never grabs the time from my Mac. The sketch compiles and loads ok, but the serial monitor just gets the message “waiting for sync message” . I have made two modifications to the example sketch that I saw suggested in the forums:

  1. Changed the brackets (ie, <>) around the library calls to quotes (ie, “ “), for example: #include <Time.h> becomes #include “Time.h”
  2. Replaced the outdated Serial.print(TIME_REQUEST,BYTE); with Serial.write(TIME_REQUEST)
    I see that the “definition” of setSyncProvider is in Time.cpp, but this compiles so I don’t know why the function is not grabbing the system time from my Mac.

Can anyone suggest a fix? I would like to be able to grab the full time, day, date info from the Mac, and eventually other info through the serial port (like emails, weather, etc), so I want to understand how to get the Arduino and Mac talking through the serial port.

Thanks.

The meaning of <> quotes in includes is "look in the standard places" - ie the libraries directory and built-in libraries.

The "" quotes in includes means "look in the same directory as this file, and if that fails look in standard places".

The latter means you can have your own .h files that accidentally name-clash with system libraries without having
to rename them.

I see that the “definition” of setSyncProvider is in Time.cpp, but this compiles so I don’t know why the function is not grabbing the system time from my Mac.

What is running on the Mac that is listening to the serial port? Nothing happens by magic.

OK, I thought Arduino was grabbing something standard that's already available on the Mac. I've been through the docs I could find on the different Arduino time related libraries, and did not see anything about what to run on the Mac side of the serial port. Where can I get documentation on how to initiate the Mac side of the serial port? Thanks very much.

The TimeAlarm library comes with a Processing sketch that you need to have running (http://processing.org).

OK, so I’m getting closer but I still can’t set the arduino’s clock time and day and date with my Mac. Can anyone help me understand what I’m doing wrong?

On the Uno, I ran the sketch TimeSerialDateStrings|Arduino 1.0.3, with one slight change. I replaced the function “Serial.print(TIME_REQUEST,BYTE);” with “Serial.write(TIME_REQUEST);” based on what I saw in a forum.

On the Mac, I ran the processing sketch SyncArduinoClock|Processing 2.0b7, also with slight mod. I added “import java.util.*;” because GregorianCalendar was not being recognized. At first the processing sketch drew a window on my Mac, but then I got the following error: “Error inside Serial, 0 “

And following is the detailed error message from trying to compile the processing code:

[start of error message]

Experimental: JNI_OnLoad called.

Stable Library

Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
[0] "/dev/tty.usbmodemfa141"
[1] "/dev/cu.usbmodemfa141"
[2] "/dev/tty.Bluetooth-PDA-Sync"
[3] "/dev/cu.Bluetooth-PDA-Sync"
[4] "/dev/tty.Bluetooth-Modem"
[5] "/dev/cu.Bluetooth-Modem"
Connecting to -> /dev/cu.usbmodemfa141
RXTX Warning: Removing stale lock file. /var/lock/LK.008.011.013
gnu.io.PortInUseException: Unknown Application
at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:354)
at processing.serial.Serial.(Unknown Source)
at processing.serial.Serial.(Unknown Source)
at SyncArduinoClock.setup(SyncArduinoClock.java:45)
at processing.core.PApplet.handleDraw(PApplet.java:2117)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
at processing.core.PApplet.run(PApplet.java:2020)
at java.lang.Thread.run(Thread.java:680)
Exception in thread "Animation Thread" java.lang.RuntimeException: Error inside Serial.()
at processing.serial.Serial.errorMessage(Unknown Source)
at processing.serial.Serial.(Unknown Source)
at processing.serial.Serial.(Unknown Source)
at SyncArduinoClock.setup(SyncArduinoClock.java:45)
at processing.core.PApplet.handleDraw(PApplet.java:2117)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:193)
at processing.core.PApplet.run(PApplet.java:2020)
at java.lang.Thread.run(Thread.java:680)

[end of error message]

Thanks again, Bryan

The Processing sketch creates a list of serial ports that the Arduino might be connected to. You then reference some element in that list. Obviously, that is an invalid element. The list is not that long.

Go back to the last version of Processing that actually works with the Arduino - 1.5.1.

Thanks. I'm still trying to configure processing to communicate with my arduino Uno, and it's been taking days. I did revert to processing 1.5.1 (thanks for the suggestion) and I've found the arduino libraries and added them to processing. Now I'm trying to solve the "infamous" RXTX mismatch problem. There are many, many posts on this on processing and other places, but it's overwhelming and I have not found a simple step by step way to get this working. I do not have experience with Java, jar, binary, etc - can you suggest a very, very simple tutorial for a first Arduino-Mac communication with processing? I'm trying to keep it simple, just trying to blink an LED on my arduino, but I can't get past the configuration issues. Thanks.

There are many, many posts on this on processing and other places, but it's overwhelming and I have not found a simple step by step way to get this working.

Don't just about all of them say not to worry about it? It really isn't a problem 99.999% of the time.

Thanks, that was very helpful. I was focused on the wrong problem to solve, at least for now.

So I’ve finally been able to get Processing to pull the system time from the Mac (Hooray!), but I can’t prove that it’s getting to the Arduino because I can’t seem to run Arduino, processing, and the Arduino serial monitor at the same time. For some reason, I think the Arduino, processing , and the Arduino serial monitor are all competing for tty.usbmodemfa141, instead of sharing it. How do I get them to all use 141 without conflicting?

Sometimes I get the message in processing "error inside serial.0".
To solve this, sometimes I can reload the Arduino and reload processing, in that order. When this works, then I do see the correct time in the monitor window at the bottom of the processing window, but I can’t get the Arduino serial monitor to open up to prove the data is getting to the Arduino, and I get this message:
“Serial port ‘/dev/tty.usbmodemfa141’ already in use. Try quitting any programs that may be using it.”
For some reason, I think the Arduino, processing , and the serial monitor are all competing for tty.usbmodemfa141, instead of sharing it.
Can you suggest a next step or point me to an appropriate resource? Thanks again for all your help - Bryan

because I can’t seem to run Arduino, processing, and the Arduino serial monitor at the same time.

There is no "seem to" about it. You can't run all three at once, because the serial port only has two ends.

Processing can, however, read serial data, and print to its monitor area...

For some reason, I think the Arduino, processing , and the Arduino serial monitor are all competing for tty.usbmodemfa141, instead of sharing it. How do I get them to all use 141 without conflicting?

They are. You can't. See above, though.

Thanks. I'm still working on this. Seems to be regressing - I can no longer figure out an order to compile the arduino and the processing without getting serial port related errors, and I can't seem to get the time print any longer in the processing monitor below the sketch . And when I do get something to show up on the Arduino serial monitor, it's gibberish, not time or words, which makes me think that WHEN something is passed from processing to Arduino, it's not simple ASCII letters, it's either out of the ASCII range or shifted within the range. So I'm scanning the forums looking for fixes, and trying some additional serial related sketches, and here's how I've broken down what I need to learn/test:

  1. be able to grab the Mac system time and print to serial monitor in the processing window (this step does not require Arduino serial interface yet). I had this working before and I'm trying to recreate it.
  2. be able to pass system time (or a test phrase) from Processing to Arduino and print to Arduino serial monitor (this will require solving both the problem of "one serial port for processing, arduino, and arduino serial monitor", and the problem of "gibberish appears on the Arduino serial monitor").
  3. be able to pass an analog input or some prestored test phrase from Arduino to Processing and print to processing serial monitor, just to show that I can do this both ways.
  4. be able to print the mac system time to an LCD attached to the Arduino (that was the whole point of this effort, I'm try to build an Ardunino/LCD clock that grabs time, weather, email, sports scores etc off the internet via the Mac).
    Do you have any other suggestions on how to break this down more simply, or for other good places for learning the basics? I've been scanning this forum and the processing forum, and looked at tutorials (like Element 14) and a beginner book (Programming Arduino Getting Started with Sketches by Simon Monk). I don't know C or Mac programming, but I'm learning the syntax as I go. Thanks again for all the help, and I'll give you an update as soon as I make some progress on the steps above.

You should really forget that the Serial Monitor application even exists. You can NOT use it and Processing at the same time. DO NOT EVEN TRY!

And when I do get something to show up on the Arduino serial monitor, it's gibberish, not time or words, which makes me think that WHEN something is passed from processing to Arduino, it's not simple ASCII letters

It isn't.

  1. be able to grab the Mac system time and print to serial monitor in the processing window (this step does not require Arduino serial interface yet). I had this working before and I'm trying to recreate it.

The "time" that is passed to the serial port is the number of seconds since January 1, 1970, not a string like "07:10:12". Is that number going to tell you anything?

  1. be able to pass system time (or a test phrase) from Processing to Arduino and print to Arduino serial monitor (this will require solving both the problem of "one serial port for processing, arduino, and arduino serial monitor", and the problem of "gibberish appears on the Arduino serial monitor").

You can't. Get over it.

You CAN make Processing READ serial data, and emulate what the Serial Monitor application is doing.

  1. be able to pass an analog input or some prestored test phrase from Arduino to Processing and print to processing serial monitor, just to show that I can do this both ways.

What have you tried? Besides complaining?

  1. be able to print the mac system time to an LCD attached to the Arduino (that was the whole point of this effort, I'm try to build an Ardunino/LCD clock that grabs time, weather, email, sports scores etc off the internet via the Mac).

You should realize by now that the "time" isn't a string, and that you will need to convert the number of seconds sine January 1, 1970 into a meaningful number of hours, minutes, seconds since a different reference time (midnight last night, typically). There are ways to do this, if you google Unix time.

There is even a method in the Time library, setTime() that takes the Unix time. Then, you can use hour(), minute(), and second() to get the "current" time.