Show Posts
Pages: [1] 2 3 ... 416
1  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: July 25, 2014, 09:31:11 am
ash124,  I think this sketch will get you closer:
Code:
/* you need to uncomment or add the following line to TimeAlarms.h
#define USE_SPECIALIST_METHODS  // define this for testing
*/

#include <Time.h>
#include <TimeAlarms.h>
#define PJG_DATA 5
#define INT_SLAVE 'I'
byte hourStart1 = 0;
byte minuteStart1 = 0;
AlarmID_t alarmStart1; //ID for interval Slave 1
void setup()
{
  Serial.begin(9600);
  setTime(8, 0, 0, 16, 7, 14);
  alarmStart1 = Alarm.alarmRepeat(8, 1, 00, Start1); //==start alarm mode interval slave 1
  setTestTime(); // just for testing - advances the clock near to the next alarm time
}

void  loop() {
  if (Serial.available())
  {
    char header = Serial.read();
    if (header == INT_SLAVE)
      Interval();
  }
  Serial.print("Current Date / Time: ");
  time_t t = now();
  digitalClockDisplay(t);
  Alarm.delay(1000);
}


// sets the start time from a Serial message of the format:
// Ih,m\n
// where I is the header, h is the start hour, m is the start minute
// \n is the newline character
void Interval()
{
 
  int hourStart1 = Serial.parseInt();
  int minuteStart1 = Serial.parseInt();
  time_t newStart1 = AlarmHMS (hourStart1, minuteStart1, 0);
  Alarm.free(alarmStart1); // remove the old alarm
  alarmStart1 = Alarm.alarmRepeat( newStart1,Start1); // create the new alarm
  Serial.print("New alarm set for ");
  Serial.print(hourStart1);
  Serial.print(":");
  Serial.println(minuteStart1);
  setTestTime();  // advance the clock to near the next alarm time
}
void Start1() {
  time_t t = now();
  Serial.print("alarm time is ...");
  digitalClockDisplay(t);
  setTestTime();  // advance the clock to near the next alarm time
}

void digitalClockDisplay(time_t t)
{
  // digital clock display of the time
  Serial.print(hour(t));
  printDigits(minute(t));
  printDigits(second(t));
  Serial.println();
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void setTestTime()
{
  // temp function for testing
    time_t t = Alarm.getNextTrigger(); 
    if( t > now() + 10) {
      setTime(t -5); // set time to 5 seconds before next trigger     
      Serial.println("... advancing clock ...");
    }     
}

I have simplified the code to read the alarm time from serial, if that is not the format you want then you can modify the Interval code to suit.

I have added a function to advance the clock to a time close to the next alarm time to make testing faster. You should remove the calls to setTestTime when you have your functionality working as you want and are ready to add the RTC code back in.  You may you need to uncomment or add the following line to TimeAlarms.h to get this to compile:

Code:
#define USE_SPECIALIST_METHODS  // define this for testing

If you want to cancel the old alarm time when a new alarm is set then you need to free the alarm. See the Interval code for an example.

I hope this gives you enough information to enable you to continue making progress.
2  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: July 24, 2014, 12:48:52 pm
Good to hear you are making progress.

Before we address your alarm question,  you should change the sketch so all references to time are using the time libary instead of the RTC.  This is because the TimeAlarms ignores the RTC once it has been set so if the Arduino time drifts from the RTC time (which it will) then the time the alarm is triggered will slowly drift from the time you display. 

You can fix this by replacing th ecod eto dislay the RTC time with the digitalClockDisplay function form the TimeAlarmExample sketch (you also need the printDigits function from that example).

Once you have that code in you sketch, you can call the digitalClockDisplay function from Start1 to show the actual alarm time.

When you have that working, post the output from the serial monitor that show the times the alarms are triggered.
3  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: July 23, 2014, 07:42:40 am
Quote
but one thing i am not getting in this is that how should i give this time i-e T1357041600 or other time

There are a number of ways to set the time using the time library. The one you need to use with your RTC is mentioned in my previous post:
Quote
   set the time by calling the setTime function in the time library with the values obtained with your RTC, see:
    setTime(hr,min,sec, day, month, yr);

To get this code to work,  remove the   setSyncProvider function call and add in code to read the time elements from you RTC and then  use them to call setTime. 
4  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: July 22, 2014, 07:51:41 am
now i have a code to set the alarm but dont know why its not working .here is my code

 what should be sent actually from my cell phone so the alarm should be set to 8:30:00 like
myhour=08;
myminute=30;
mysecond=00;
 Alarm.alarmRepeat(myhour,myminute,mysecond, morningalarm);

Yes, that would set the alarm. However, the alarms will only function when used with the companion Time library.

The example sketch for using an RTC with the Time library does not work with the RTC you have.  However, you can set the time by calling the setTime function in the time library with the values obtained with your RTC, see:
   setTime(hr,min,sec, day, month, yr);

To get the time library working with  your RTC, try modifying the TimeSerial example sketch by replacing the call to
   setSyncProvider( requestSync);  //set function to call when sync required
with code to call setTime with the time elements from your RTC.  When you have that working you can add in the alarm code.


5  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: July 19, 2014, 07:16:52 am
If you are looking for someone to write the code for you then perhaps someone reading this thread will oblige.  If you are seeking to create the application yourself, then the step-by-step approach suggested earlier is a good way to learn and make progress.
6  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: July 19, 2014, 04:21:32 am
Did you try a simple version based on the TimeAlarm example with code to set the alarm time from the serial monitor?
7  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: July 19, 2014, 04:06:55 am
Some variables in the code to read the RTC are conflicting with names used by the Time and TimeAlarms library.  If you are new to writing arduino code then I suggest you simplify things and build up the functionality piece by piece to help you understand how the code works.   My previous post has suggestions for the steps you can take to get things going.
8  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: July 19, 2014, 01:28:23 am
Did you look at the TimeAlarmExample sketch?

I suggest you run that sketch to see how the alarms are set and activated. Then you can add code to receive alarm times from the serial monitor. When you have that working, you can replace serial monitor input with bluetooth.  When you have that working, you can add in the RTC.

have fun!
9  Using Arduino / Programming Questions / Re: time and date library on: June 02, 2014, 07:12:43 am
I want to display date and time on 16*4 lcd . i download DateTime.h library. but code was not complied. reply please
The  DateTime library in the playground is obsolete and was replaced by newer code four years ago. There is a note on the web page for the old DateTime code that provides the link to the latest version:   http://playground.arduino.cc/Code/Time.

A little time searching in this forum or with google should turn up a number of examples of LCD clocks built using the Time library.
here is one example: http://blog.workingsi.com/2011/02/arduino-lcd-countdown-clock.html
 
10  Community / Exhibition / Gallery / Re: Library for time zone conversions and automatic DST adjustments on: May 24, 2014, 06:04:21 am
The only real bummer is that Michael changed some of the tm elements
to be 1 based vs 0 based when he created his Arduino Time library.
And that can't be change now without likely breaking lots of existing code.

--- bill


I just became aware of this post and wanted to add context to the reason for the change.
My original time library did follow Unix convention with days and months zero based (see: http://playground.arduino.cc/Code/dateTime)

Back in December 2009, There was discussion in the developers mailing list about including these time functions in the Arduino core. In that thread, David Mellis made the point that that an Arduino time API should be closer to Processing (where the days and months start from 1). His reasoning was that people moving from Processing to Arduino were less likely to understand and deal with API differences than those coming from a Unix background.  In the absence of any objections from the developer community at the time, the API was altered to be closer to Processing and the rest is history.

It is not always an  easy task to create APIs that fully satisfy beginners and boffins, and when compromises need to be made, in the Arduino world, it is right that beginners get preferential consideration.

Michael
11  Development / Other Software Development / Re: Update to TimeAlarms Library - thread for discussing beta testing on: March 17, 2014, 09:04:07 am
I'm also quite late, but it seems there is a bug with repeating timers at midnight.

If I set this: Alarm.alarmRepeat(0,0,0, FUNC_STUFF);

The Alarm is always disabled and I cannot enable it.

The library considers midnight to be at the end of the day, try:
Alarm.alarmRepeat(24,0,0, FUNC_STUFF);
12  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: March 17, 2014, 08:02:54 am

I tried some thing like this.. but on my lcd display i recieve only the current time and a "on"  when  the switch is not pressed it shows current time then after 1s delay a "on".
when i press the button switch for some times the current time stays on the display untill i release the switch. it doesnt changes the display to "on" when the switch is not pressed. when i release the switch old routine comes back.

i couldnt get the duration.


You are close but there are some errors in your code. You are using buttonState instead of buttonPin in your digitalRead function. Also, you have declared two event variables, one at the beginning of loop and the other in the code that handles the state where the digitalRead is high.  Move the time_t event declaration to the top of the sketch where your other global variables are declared and remove  time_t from the line where you set event= now() . You can read the arduino reference pages on declaring variables and variable scope for more on this issue.

The issues you are having are not related to the time libraries so I suggest that start a  new thread to discuss  your project and post a link here so I and others can follow.
13  Development / Other Software Development / Re: Update to TimeAlarms Library - thread for discussing beta testing on: March 17, 2014, 04:04:05 am
… I wish you could combine Jack Christensen TimeZone with your Time libraries.

I have not seen that library but will have a look. If that library currently works with the time library, would there be any functional benefit in combining them?

I have been having problems with multiple copies of your Time libraries across the web.

The time.cpp file has version information in the header along with a brief description of the changes. My latest version has edits dated 24 March 2012.

Having a standard way to determine a library version and capabilities is one of a number of improvements being discussed for Arduino libraries by the Arduino developer community.
14  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: March 16, 2014, 01:15:52 pm
Basically I am a beginner to arduino. It has been a interesting process for me,
Can you tell me how can I get the duration between a button switch on and off.?
Special thanks for your quick response.

There are many ways to do this but if an Arduino pin can monitor the state of the machine then one approach is to capture the time of the event of a pin going high or low using the code posted earlier. Subtracting the time between these events gives you the on and off times. Accumulating the on time and off times should give you the information that you need.

I suggest you experiment with a simple sketch that reads an input connected to a switch and totals the times between the high and low transitions and prints the current switch state, time since previous change of switch state, and total accumulated times in each state to the serial port. 
15  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: March 15, 2014, 02:38:20 am
Hi Samly_dixon, Its not clear on what you want to do and I did not see the code that you are trying to get working. Can you say more about exactly what you want to test with the if statement when a button is pressed.
I noticed that you have created functions to return the current hours, minutes and seconds. These functions already exist as follows:   seconds(), minutes() , hours().
You have a function named duration that has the following comment:
   //function to find the variance b/w start time n stop time
But it is not clear which argument is the start time and which is the stop time. It would be clearer if you used descriptive names for your variables instead of: ms, mp,hd, md etc.

To find the difference between two times, use the time_t returned from the now()function. For example:
Code:
time_t event = now();
// … some time later
long duration = now() – event; // the duration since the event in seconds
Pages: [1] 2 3 ... 416