Trouble with RTC time

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Trouble with RTC time

Postby tfunk10258 » Thu Apr 12, 2012 9:52 pm

I'm having an interesting little problem integrating a chronodot into a project I have, and I'm now looking for a little assistance. I have the time and date set correctly, and when I run the DS1307 example sketch, everything prints out nicely and works just fine. I then added some modified code into my existing project to print the unix time at the end of each line of a csv logfile it creates. However, the unix time it logs only updates every 128 seconds, so it prints the same value 128 times (the project logs data once per second) and then switches to a value 128 seconds higher and so on.

Then, to troubleshoot, I ran the RTC code I wrote on its own, using everything hooked up identically, and printed it to the serial instead of a logfile, and it only updates every 64 seconds.... I'm stumped. Here is the code I ran on its own.

Code: Select all
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

float time;

void setup () {
    Serial.begin(57600);
    Wire.begin();
    RTC.begin();
}

void gettime(void){
  DateTime now = RTC.now();
  time = now.unixtime();
}

void loop () {
  gettime();
  Serial.println(time);
  delay(1000);
}


Any help would be appreciated.

Thanks,

Thomas
tfunk10258
 
Posts: 5
Joined: Mon Mar 05, 2012 1:36 am

Re: Trouble with RTC time

Postby odometer » Fri Apr 13, 2012 1:43 am

Personally, I do not like the "float" datatype. One reason I don't like it is that it has so little precision. This lack of precision is what is causing you trouble here.

One thing you should know about this RTC library is that it ignores the existence of time zones and therefore does not handle Unix Time correctly.

Info on Unix Time here: http://www.epochconverter.com
odometer
 
Posts: 97
Joined: Sun Aug 21, 2011 10:01 pm

Re: Trouble with RTC time

Postby tfunk10258 » Fri Apr 13, 2012 2:01 am

Thanks for your reply. The time zone is unimportant in my application. Are you saying that the value is jumping by powers of 2 because of a lack of resolution in float datatypes? I never thought of that
tfunk10258
 
Posts: 5
Joined: Mon Mar 05, 2012 1:36 am

Re: Trouble with RTC time

Postby adafruit_support_bill » Fri Apr 13, 2012 4:54 am

Floating point gives you the ability to represent a much larger range of numbers than is possible with integers. The tradeoff is the loss of 100% accuracy.

http://www.cprogramming.com/tutorial/floating_point/understanding_floating_point.html
User avatar
adafruit_support_bill
 
Posts: 16642
Joined: Sat Feb 07, 2009 9:11 am


Return to Arduino

Who is online

Users browsing this forum: No registered users and 14 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
Android[6]
 
BeagleBone[23]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]