Go Down

Topic: Time and TimeAlarms Libraries – Ask here for help or suggestions (Read 219405 times) previous topic - next topic

JimboZA

#255
Aug 10, 2014, 10:19 am Last Edit: Aug 10, 2014, 10:29 am by JimboZA Reason: 1
Is there a limit to the number of timers and alarms that can be set in the TimeAlarms library? I'm getting some funnies where some are not honoured, and I'm wondering if there's a limit. (I'm going to do some proper testing before I post code, but thought I'd ask if there's a known limit first. Don't shout at me for not posting code yet  :) )

edit.... the readme says 6 but that can be increased by editing  the constant dtNBR_ALARMS in the header.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

UKHeliBob

You found the answer that I was going to point you at.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

JimboZA


You found the answer that I was going to point you at.



I had read the page on the 'net, but then I thought to my self, "self, maybe the readme has more" and I found it has a faq. I really think that faq should be on the web site!

Nice easy to use library though.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

UKHeliBob

Quote
maybe the readme has more
I don't know what the World is coming to.
Firstly you actually look at the readme and secondly it is actually helpful !

There is some good stuff in the readme including details of the low level functions that provide access to the alarms via the alarm ID which can be useful and the FAQ section really does contain what must be FAQs
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Lundin

#259
Aug 10, 2014, 12:38 pm Last Edit: Aug 10, 2014, 09:17 pm by Lundin Reason: 1
Removed my question, i found another RTC library that works not only with the DeadOn 3234, but also the LC studio SD cardreader (which were the next headache the other library didn't like).. the new foundings also works with Time/TimeAlarm libraries..

KristoZ RTC 3234 lib

Big thumb's up for creating this library Mem.. with the headache gone and problem solved all is good.

All the best
Magnus

Lundin

#260
Aug 16, 2014, 10:34 am Last Edit: Aug 16, 2014, 10:44 am by Lundin Reason: 1
So it happens that i'm back with a somewhat clearer mind..  What i thought worked with my previous solution, didn't actually do anything.
I sync'ed KristoZ library with the Time library with SetSyncProvider().. and as 'Time' were not sync'ed to the DeadOn RTC the time didn't reveal what the RTC were sending.

So, i'll re-thread my question about the sync errror calling SetSyncProvider() with the DS3234 RTC.
Code: [Select]

DS3234_m_trigg_2.ino:103:33: error: cannot convert 'DS3234::getTime' from type 'Time (DS3234::)()' to type 'getExternalTime {aka long unsigned int (*)()}'


Is this possible to remedy? Or is it a to big of a change in the library it's completely off the charts.

Thanks for any info about this.

EDIT: Updated the question with this header code of the DS3234
Code: [Select]

/*
  DS3234.h - Arduino library support for the DS3234 SPI Bus RTC
  Copyright (C)2014 Henning Karlsen. All right reserved
 
  This library has been made to easily interface and use the DS3234 RTC with the
  Arduino and chipKit development boards.
  This library makes use of the built-in hardware SPI port of the microcontroller
  so there are some pin connections that are required (see the manual).

  You can find the latest version of the library at
http://www.henningkarlsen.com/electronics

  If you make any modifications or improvements to the code, I would appreciate
  that you share the code with me so that I might include it in the next release.
  I can be contacted through http://www.henningkarlsen.com/electronics/contact.php

  This library is free software; you can redistribute it and/or
  modify it under the terms of the CC BY-NC-SA 3.0 license.
  Please see the included documents for further information.
*/
#ifndef DS3234_h
#define DS3234_h

#if defined(__AVR__)
#include "Arduino.h"
#include "hardware/avr/HW_AVR_defines.h"
#elif defined(__PIC32MX__)
#include "WProgram.h"
#include "hardware/pic32/HW_PIC32_defines.h"
#define F(str) (str)
#elif defined(__arm__)
#include "Arduino.h"
#include "hardware/arm/HW_ARM_defines.h"
#endif

#define FORMAT_SHORT 1
#define FORMAT_LONG 2

#define FORMAT_LITTLEENDIAN 1
#define FORMAT_BIGENDIAN 2
#define FORMAT_MIDDLEENDIAN 3

#define MONDAY 1
#define TUESDAY 2
#define WEDNESDAY 3
#define THURSDAY 4
#define FRIDAY 5
#define SATURDAY 6
#define SUNDAY 7

class Time
{
public:
uint8_t hour;
uint8_t min;
uint8_t sec;
uint8_t date;
uint8_t mon;
uint16_t year;
uint8_t dow;

Time();
};

class DS3234
{
public:
DS3234(uint8_t ss_pin);
void begin();
Time getTime();
void setTime(uint8_t hour, uint8_t min, uint8_t sec);
void setDate(uint8_t date, uint8_t mon, uint16_t year);
void setDOW(uint8_t dow);

char *getTimeStr(uint8_t format=FORMAT_LONG);
char *getDateStr(uint8_t slformat=FORMAT_LONG, uint8_t eformat=FORMAT_LITTLEENDIAN, char divider='.');
char *getDOWStr(uint8_t format=FORMAT_LONG);
char *getMonthStr(uint8_t format=FORMAT_LONG);

float getTemp();

void poke(uint8_t addr, uint8_t value);
uint8_t peek(uint8_t addr);

private:
uint8_t _ss_pin;
uint8_t _burstArray[8];

uint8_t _readByte();
void _writeByte(uint8_t value);
uint8_t _readRegister(uint8_t reg);
void _writeRegister(uint8_t reg, uint8_t value);
void _burstRead();
uint8_t _decode(uint8_t value);
uint8_t _decodeH(uint8_t value);
uint8_t _decodeY(uint8_t value);
uint8_t _encode(uint8_t vaule);

void _SPIstart(uint8_t rate = SPI_CLOCK_DEFAULT);
void _SPIwrite(byte data);
byte _SPIread(void);

};
#endif


kiuz

Why don't use GitHub to collaborate on same official version? I must use this library and I want to collaborate...

#BUGS
on examples are used Serial.write(MESSAGE,BYTE) and this don't work on Arduino 1.0. ... ;

UKHeliBob

Quote
Serial.write(MESSAGE,BYTE) and this don't work on Arduino 1.0. ...
That is not a bug.  it is a deliberate, documented change introduced with release 1.0

http://blog.arduino.cc/2011/10/04/arduino-1-0/
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Bob808

#263
Sep 08, 2014, 01:26 am Last Edit: Sep 08, 2014, 01:57 am by Bob808 Reason: 1
Hello,
I'm having some trouble with the Alarm library.
I am using an Arduino Uno with a DS1307 module and a relay board. Basically I'm trying to set the time on my arduino from my RTC, and then have it activate two relays for a fan and lights. So I really need to have two alarms set that activate at the exact same time when the time comes.
Right now I'm having some issues as it seems that one alarm goes off , the second doesn't, I have to wait until the first one is done and then the second one kicks in. The thing is that I really need them both to work at the same time, and I can't wait for one or the other as the test delay is 90 seconds at the moment but I would like to be able to let's say set the light for 12 hours and the fan for 1 hour only. Can't have one waiting for the other...
What am I doing wrong?
Also, if you could check the way I set the time of the arduino after RTC. Basically I want this to work even thou the Arduino looses power at any point, and then comes back up continuing it's schedule. If for example the arduino is in the middle of the light alarm that can last anywhere between 10 minutes and 10 hours it looses power I want it to continue it's program. Is it possible with Alarms? Or should I look at another approach? I also have an i2c eeprom for storing the alarms and I will add a LCD with buttons.
At the moment I'm trying to find the best approach for my needs.
Thank you

edit:
And it gets more complicated if I want to have the fan start let's say 3 or 4 times a day for 5 minutes. How do I do to make sure it resumes operation after a power failure?

Code: [Select]
#include <Wire.h>
#include <Time.h>
#include <TimeAlarms.h>
#include <DS1307RTC.h>

int fan = 4;
int light = 7;

void setup () {
   
 Serial.begin(57600);
   Wire.begin();
   
   setSyncProvider(RTC.get);
   
   pinMode(fan, OUTPUT);
   pinMode(light, OUTPUT);
   digitalWrite(fan, HIGH);
   digitalWrite(light, HIGH);
   
   Alarm.alarmRepeat(2, 14, 0, LightsOn);
   Alarm.alarmRepeat(2, 14, 0, FanOn);

 }
 
void loop () {
 
   Alarm.delay(1);
 
}

void LightsOn() {
digitalWrite(light, LOW); // Set Lights On
   Serial.println("Lights On");
 delay(90000);
 LightsOff();  
}



void FanOn() {
digitalWrite(fan, LOW); // Set Fan On
   Serial.println("Fan On");
  delay(90000);
   FanOff();
}


void LightsOff() {
digitalWrite(light, HIGH); // Set Lights Off
  Serial.println("Lights Off");  
}

void FanOff() {
digitalWrite(fan, HIGH); // Set Fan Off
   Serial.println("Fan Off");
}


later edit:
I think I managed to make both alarms start together. I had to remove the delay from each function that the alarm calls, and then make another alarm to call the Off function.
Still I'd love some pointers on how can I manage to make alarms and after a power failure, if they were scheduled to be active (or call a function for a specified amount of time) have them active again. Something like check On and Off alarms and if in between at bootup activate On function if between Off and On alarms activate Off function.

JimboZA

Quote
I think I managed to make both alarms start together. I had to remove the delay from each function that the alarm calls, and then make another alarm to call the Off function.


I was going to suggest exactly that but then saw your edit. Delay() always blocks, so I think the way you have it now, with explicit offs from other alarms, is the right way.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

Bob808

Yes, but with me wanting to add a LCD with keys I don't know if this approach is good. Wanting to program the On/Off cycles externally from LCD and storing the data into an EEPROM I don't know if this is the best way. I am having a tough time with redundancy at power failure.

joe4444

#266
Sep 08, 2014, 10:13 pm Last Edit: Sep 09, 2014, 06:23 pm by joe4444 Reason: 1
Hi all

I have finally gotten a chance to add time to my arduino and started with the DS1302 and managed to stumble along and get time and alarmtime working with it and the DS1302. Thank you for the libraries.
]Today I purchased a DS1307 to tinker with too.

My question is around the TimeAlarms library.
I would like to create many alarms for specific dates and times.
In the readme.txt  I found this statement:
Quote
If you want to trigger once at a specified date and time you can use the trigger Once() method:
 Alarm. triggerOnce(time_t value,  explicitAlarm); // value specifies a date and time
(See the makeTime() method in the Time library to convert dates and times into time_t)


My questions are:

Is there a basic example or walk-through as to how to do this?
I have been combing the forums and even been through the 18 pages on this one. The examples included in the library don't show it either.
Have I missed something somewhere ?

Looking forward to any help or info or examples.

Thanks a million

Joe

Docedison

THis might be of use to you for your current issues but I wrote it for a Mega2560.. a year or so back

Doc
--> WA7EMS <--
"The solution of every problem is another problem." -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

PaulS

Quote
My question is around the TimeAlarms library.
I would like to create many alarms for specific dates and times.

Why? You've got a clock. You've got a computer. On any given pass through loop, see if it's time to do something. If so, do it. You can check hundreds of things in microseconds.
The art of getting good answers lies in asking good questions.

joe4444

@ BOB

Thank you kindly I have started maketime()/ breaktime () fucntions.

Wow that's a lot of code you have there :-)

Typical though.. the one thing I am looking for is a simple example (albeit a few lines of code) to create an alarm on a specific date. It's the one example that's missing from the Arduino cookbook and unless I have been speed-reading for the last 3 days there isn't this simple example on the forums or google for that matter (I stand corrected if I have missed something)

@ Pauls
Yip why indeed !
Why would one fly a kite with a key tied to its string in a storm ?
Why did stone-age man want fire ?
A point to ponder indeed.
And yes I neglected to mention, I would like to automatically switch an infrared light on for my puppy.

Is there any where I can find an example which I look at to see how it's done ?
I think this is what is needed:
Code: [Select]
Alarm. triggerOnce(time_t value,  puppyAlarm); // value specifies a date and time
and this
Code: [Select]

time_t puppyAlarm = (14,50,0,9,9,14,puppyEvent) ;

and later one
Code: [Select]
void puppyEvent()
{
Serial.print("hot dog!")
}


IF I'm on the right track here then the part I am struggling with is :
how to get the times entered into the time_t format.?

Pointers and tips welcome

Regards

Joe

Go Up