Adafruit - THE MUSICAL - is here! Get a musical tour of Becky's favorite tools around the Adafruit factory (video) and subscribe!

Issues with TimeAlarms.h
Moderators: adafruit_support_bill, adafruit

Issues with TimeAlarms.h

by Aemornion on Fri Feb 01, 2013 8:42 pm

Hello everyone,
This is my first post.

I am attempting to make a controller for my aquarium, and a big part of this is dosing fertilizers. I have an RTC and and LCD screen functional. And i am now attempting to add timer functionality through use of the Time.h and TimeAlarms.h libraries.

I can not for the life of me get it to work, the alarms never trigger.

If i run the example in the TimeAlarms.h library and then add the RTC libraries and set the time using the RTC etc, The alarms work.
But back in my program, not the case.
Well what if i copy parts of the example program right into myprogram, nope still nothing.

I am currently using the timerRepeat(,) function to print to serial every 2 seconds.
This works in the example program.

My other issue, is that i cant seem to get it to print to my lcd from within the alarm, when using lcd.print it says "lcd was not declared in this scope". seems to work fine everywhere else =\


So after much banging my head against the keyboard I came her, I have tried everything and am hopeful you guys will be able to pinpoint my error.


Code: Select all | TOGGLE FULL SIZE
/////Arduino Aquarium Control/////
#include <Wire.h>
#include <OneWire.h>
#include <LiquidCrystal.h>
#include <DallasTemperature.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>  // a basic DS1307 library that returns time as a time_t




void setup()  {
  Serial.begin(9600);

  temperatureSetup();
  clockSetUp();
  LCDdisplaySetup();
 
  Alarm.timerRepeat(2, Test);            // timer for every 15 seconds   

}

void loop()
{
  clockOutput();
  temperatureRead();
  LCDdisplay();
  delay(1000);
}

////////Alarm/////////////////
void Test(){
  Serial.println("15 second timer");
  //lcd.print("15 second timer");       
}
///////End Alarm//////////////


///////Clock//////////////////
void clockSetUp(){
  setSyncProvider(RTC.get);   // the function to get the time from the RTC
  if(timeStatus()!= timeSet)
  {
    Serial.println("Unable to sync with the RTC");
  }
  else{
    Serial.println("RTC has set the system time");
  }
}

void clockOutput(){
  // digital clock display of the time
  Serial.print(dayStr(weekday()));   //converts day number into day name
  Serial.print(" "); 
  Serial.print(monthStr(month()));   //converts month number into month name
  Serial.print(" ");
  Serial.print(day());
  Serial.print(" ");
  Serial.print(year());
  Serial.print(" ");
  Serial.print(" ");
  Serial.print(hourFormat12());
  SerialPrintDigits(minute());
  SerialPrintDigits(second());
  Serial.print(" ");
  Serial.print(" ");
  Serial.print(day());
  Serial.print("/");
  Serial.print(month());
  Serial.print("/");
  Serial.print(year());
  Serial.println();
}

void SerialPrintDigits(int SerialDigits){
  // utility function for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(SerialDigits < 10)
    Serial.print('0');
  Serial.print(SerialDigits);
}

///////End Clock////////////////////////


///////LCD OUTPUTS/////////////////////
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void LCDdisplaySetup(){
  lcd.begin(20, 4);
}


void  LCDdisplay(){
  lcd.setCursor(0, 0);
  lcd.print(dayStr(weekday()));
  lcd.setCursor(10, 0);
  lcd.print(monthShortStr(month()));
  lcd.print(" ");
  lcd.print(day());

  lcd.setCursor(0, 1);
  //lcd.print(hourFormat12());
  lcd.print(hour());
  lcd.print(":");
  lcdPrintDigits(minute());
  lcd.print(":");
  lcdPrintDigits(second());
  lcd.setCursor(9, 1);
  lcdPrintDigits(day());
  lcd.print("/");
  lcdPrintDigits(month());
  lcd.print("/");
  lcd.print(year()-2000);
}

void lcdPrintDigits(int lcdDigits){
  // utility function for digital clock display: prints preceding colon and leading 0

  if(lcdDigits < 10)
    lcd.print('0');
  lcd.print(lcdDigits);
}
///////End LCD OUTPUTS/////////////////

///////Reading Temperature/////////////
#define ONE_WIRE_BUS 13

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

DeviceAddress Temp1 = {
  0x28, 0x81, 0x4E, 0x47, 0x04, 0x00, 0x00, 0x70 };
DeviceAddress Temp2 = {
  0x28, 0xEE, 0x1C, 0x47, 0x04, 0x00, 0x00, 0x81 };
DeviceAddress Temp3 = {
  0x28, 0x9A, 0x31, 0x47, 0x04, 0x00, 0x00, 0xD1 };



void temperatureSetup(){
  sensors.begin();

  sensors.setResolution(Temp1, 10);
  sensors.setResolution(Temp2, 10);
  sensors.setResolution(Temp3, 10);
}


void temperatureRead(){
  sensors.requestTemperatures();

  float temp1F = sensors.getTempF(Temp1);
  float temp2F = sensors.getTempF(Temp2);
  float temp3F = sensors.getTempF(Temp3);

  Serial.print("\n\r");
  Serial.print("T1/T2/T3");
  Serial.print("\n\r");
  Serial.print(temp1F);
  Serial.print("/");
  Serial.print(temp2F);
  Serial.print("/");
  Serial.print(temp3F);
  Serial.print("\n\r");


  lcd.setCursor(0, 2);
  lcd.print("T1/T2/T3");
  lcd.setCursor(0, 3);
  lcd.print(temp1F);
  lcd.print("/");
  lcd.print(temp2F);
  lcd.print("/");
  lcd.print(temp3F);
}
///////End Reading Temperature/////////////
Aemornion
 
Posts: 2
Joined: Sun Jan 13, 2013 1:59 am

Re: Issues with TimeAlarms.h

by Aemornion on Sat Feb 02, 2013 12:02 am

So after posting this question, i kept on digging online, and then found a little iotia of information which helped me, Thus I am going to answer my own question, so if others have similar problems they can have less bashing of their heads against the keyboard.

I had two issues,
1) I did not include Alarm.delay(), this is needed to give the program time to check to see if the alarms had been triggered.
I was able to use alarm.delay(0) as to not add actual delay.

2) my lcd problem stemmed from how i decided to arrange everything.
I tried to compartmentalize everything into chunks, bad idea as i was trying to call the lcd commands but they were buried.
Moving the lcd.begin(#,#) and liquidcrystal lcd(#,#,#,#,#,#) into and above my void setup(){} respectively, fixed the problem.

Cheers
Aemornion
 
Posts: 2
Joined: Sun Jan 13, 2013 1:59 am