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: August 18, 2014, 12:21:08 pm
you can simplify the code to read alarm times by using the Arduino parseInt construct. Something like the following should get you going in the right directon:
Code:
void Interval()
{
  // here if header has been detected
  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
}
2  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: August 14, 2014, 09:27:01 am
Have you installed the DS1307RC library in the libraries directory? Although it can be used  with the Time and TimeAlarms libraries, it is a stand-alone library and needs to be installed in the libraries folder.
3  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: August 13, 2014, 08:23:36 am
Did you get the RTC working with the time library before trying to add the alarms?

If not, start with the example sketches that come with the time library.
running the timeRTC sketch will tell you if you have the RTC connected up and working correctly. You can run the TimeRtcSet example sketch to set the RTC time if that is not already set.

when you have the sketch displaying the correct time, you can add in code to set alarms.. All you should need to add to the example code to get an alarm working is :

  the include statement for the TimeAlarm library
#include <TimeAlarms.h>

  a statement in setup to set an alarm time  ( but use a time close to the current time):
 alarmStart1 = Alarm.alarmRepeat(8, 1, 0, Start1);

  an alarm handler function , for example:
void Start1() {
  Serial.print("alarm time is ... ");
  digitalClockDisplay();
}
4  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: August 01, 2014, 08:32:50 am
When using the time and time alarm libraries, the  purpose of the DS1302  is to set the arduino time library at startup.  After that, all access to time should be using the time library, not the DS1302.  The reason for this was given in an earlier post.

The code to set the time was in my previous post.  I suggest you go back to the code you posted this morning and add into setup the code from my post to set the arduino time. 
5  Using Arduino / Programming Questions / Re: how to set alarm of rtc clock by sending serial command to arduino on: August 01, 2014, 03:21:28 am
Good to hear you are making progress.
 
Although its easier using a DS1307 RTC because the code to set the arduino clock from the RTC is already built into the DS1307RTC library, you can add the code you need to read your RTC into your sketch.

To do this, you need to include the virtuabotixRTC library in your sketch and then in setup call the setTime method:

  setTime(myRTC.hours,myRTC.minutes,myRTC.seconds,myRTC.dayofmonth, myRTC.month, myRTC.year);

You need to read the documentation on your RTC and the Time library to ensure the values are in the correct format but this should get you going.

6  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.
7  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.
8  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. 
9  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.


10  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.
11  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?
12  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.
13  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!
14  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
 
15  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
Pages: [1] 2 3 ... 416