Pages: 1 ... 11 12 [13] 14 15 ... 23   Go Down
Author Topic: Time and TimeAlarms Libraries – Ask here for help or suggestions  (Read 76196 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19361
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Recent posts about the DS1302 moved to http://forum.arduino.cc//index.php?topic=192580.0
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am working with DS1307, and I noticed that if the module is not connected, the library return time value instead of reporting error. I think this should be corrected. I noticed this with weak battery in the DS1307 module, then I played with disconnecting module at all. I am programmer and am able to correct this bug myself, but I think better way is 1) not having modified versions of "standard" libraries and 2) fixing this would be good for entire community. Several ways of fixing is for example: Check device on the I2C bus, writing some "magic" bytes when setting time to the DS1307 memory and then checking them, and most paranoid, perhaps checking all bits in the time information which _should_ be 0, if they really _are_ 0.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi ladinek,

I would be happy to add this feature to the library after it is well tested with the various chips compatible  with DS1307 that the library currently works with.
I suggest you create a new thread for your DS1307 enhancements when you are ready to post some code, and add a link to that thread here.

Michael Margolis
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Thanks a lot, I had the same problem. It seems to be proper solution.

Thanks again
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One more question, I have noticed you declare member functions of the DS1307 class as _static_, I tried to add one private variable and had problems compiling. So I googled a lot, and static class member function is not the same as the static function in "classic" C. It has something to do with "this". In other libraries member function are not declared as static. Can you explain reasons for this?
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19361
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Static class variables do not "belong" to instances of the class but the class itself. Typically you might use a static variable to count how many class members have been instantiated.

Quote
I tried to add one private variable and had problems compiling.

Perhaps show the code and the error.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

In the class definition in DS1307RTC.h I added variable present:
Code:
  private:
static uint8_t dec2bcd(uint8_t num);
    static uint8_t bcd2dec(uint8_t num);
uint8_t present;
Then in constructor I try to access this variable:
Code:
DS1307RTC::DS1307RTC()
{
  Wire.begin();
  Wire.beginTransmission(DS1307_CTRL_ID);
  Wire.write((uint8_t)0x00);
  if (Wire.endTransmission() == 0) present = 1;
  else present = 0;
}
Attemting to compile, I get errors like this:
Code:
D:\arduino-1.0.5\libraries\DS1307RTC/DS1307RTC.cpp:35: undefined reference to `DS1307RTC::present'
I tried declare variable present as either static or not, same result.
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19361
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Now show all the code so I can reproduce it.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I solved it. Problem is, that you cannot access non-static member variable from static function. What I tried to do is add member variable present, which is true or false depending of success in communication with module. And if you declare static member variable, you must alse _define_ it, so I added
Code:
uint8_t DS1307RTC::present = 0;
just before contructor of the RTC object at the end of ds1307rtc.cpp.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is my modification of the library. I added member flag present, and set its value to true (1) or false (0) depending on success or failure in communication with the hardware. I modified the library as little as possible, you can compare my modification with original version. I modified only the read access to hardware. The RTC.get() function returns 0 (i.e. 1.1.1970) if the hardware is not present. It even correctly set timeStatus, if you for instance connect the DS1307 and then disconnect it, time continues to run, but the variable is set to timeNeedsSync after sync interval expires.

* DS1307RTC.zip (2.83 KB - downloaded 17 times.)
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19361
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I solved it. Problem is, that you cannot access non-static member variable from static function.

Of course. Non-static variables belong to each instance, but a static function belongs to the class (not an instance).
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Newbie
*
Karma: 0
Posts: 12
Old programmer, new to Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wrote two simple functions for getting the time from the Internet.

The first one is an NTP date function. Unlike the NTP functions I have seen out there, this one does not require allocating either a transmit or a receive buffer, neither statically nor on the stack. It does not require any ancillary library either.

The second one is an HTTP date function. This one builds on a simple concept: just make an invalid HTTP 1.1 request to a web server out there, and parse its answer looking for the Date: header. This function is very small too and has the advantage of requiring very little code and memory space if you already use the EthernetClient or WiFiClient class in your sketch.
« Last Edit: December 04, 2013, 02:04:19 am by fpoto » Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everybody, I could use some help with TimeAlarms.

I'm building a clock that uses a GPS Shield to constantly reset the time through the setTime() function in the arduino main loop, like this:

  if (age < 500) {
        // set the Time to the latest GPS reading
        setTime(Hour, Minute, Second, Day, Month, Year);
        adjustTime(offset * SECS_PER_HOUR);

This is to ensure that GPS data isn't stale, and that the clock's time is always getting updated by gps.  the age is a function of the TinyGPS++ library.

This is unlike most examples that I've seen that uses setTime() once in the setup of the sketch.  I'm trying to set alarms through timeAlarms library and cannot get any alarms to trigger.  I've got a feeling it is because I'm using setTime() in my loop as opposed to setup.  

Could anybody shed some light on what is going on?  Thanks in advance.
« Last Edit: December 11, 2013, 10:00:16 pm by russo_mic » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 654
Posts: 50931
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is to ensure that GPS data isn't stale,
Resetting what time the Arduino thinks it is will have no impact on the time that the GPS knows that it is, and will have no impact on the freshness (or staleness) of the GPS data.

Quote
I've got a feeling it is because I'm using setTime() in my loop as opposed to setup. 
Perhaps you should consider printing age. It looks to me like you are resetting the time FAR more often than you need to. If something does happen, and you get an old reading, you don't reset the time. And that makes no sense.

I think that the real problem is that you are trying to address the wrong issue.
Logged

Offline Offline
Newbie
*
Karma: 1
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply.  However, I already thought of this, and did an experiment and had it check only every 10 minutes, and still no alarms would trigger.   The only time my alarms trigger is if setTime() is in my setup. 

This is the way I made the clock portion of the code because in the GPS example in Time library this is how it is done.
Logged

Pages: 1 ... 11 12 [13] 14 15 ... 23   Go Up
Jump to: