Reply to topic  [ 80 posts ]  Go to page 1, 2, 3, 4, 5 ... 8  Next
Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU0011) 
Author Message
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 650
Post Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU0011)
Image

Image


Description:

High quality DS1307 using the I2C real time clock chip.
(RTC) 24C32 32K Bit I2C EEPROM memory.
Dimensions: 27 mm x 28 mm x 8.4 mm
This module can be connected with other I2C devices.
Exclusive Arduino library available on this support forum.


Arduino Example Code:
Code:
/* FILE     HCRTC_Example.cpp
   DATE:    23/12/13
   VERSION: 0.2
   AUTHOR:  Andrew Davies

This is an example of how to use the Hobby Components RTC library to read and
write to and from the DS1307 real time clock 24C32 EEPROM. The library is intended
to be used with our RTC clock module (HCMODU0011), but should work fine with any
module that uses a DS1307 device.

You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used directly for the purpose of selling products that
directly compete with Hobby Components Ltd's own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER.
*/


/* Include the wire library */
#include "Wire.h"
/* Include the Hobby Components RTC library */
#include <HCRTC.h>

/* The RTC and EEPROM have fixed addresses of 0x68 and
    0x50 so define these in software */
#define I2CDS1307Add 0x68
#define I2C24C32Add  0x50

/* Example string to write to EEPROM */
char ExampleString[] = "Hobby Components";

/* Used in example as an index pointer */
byte index;

/* Create an instance of HCRTC library */
HCRTC HCRTC;


void setup()
{
  Serial.begin(9600);
 
  /* Use the RTCWrite library function to set the time and date.
     Parameters are: I2C address, year, month, date, hour, minute, second,
     day of week */
  HCRTC.RTCWrite(I2CDS1307Add, 13, 4, 24, 14, 21, 0, 3);
}

void loop()
{
  /************* Example write to EEPROM ***************/ 
 
  /* Initiate a write sequence.
     Parameters are: I2C address, EEPROM start location */
  HCRTC.EEStartWrite(I2C24C32Add, 32000);
 
  for (index = 0; index < sizeof(ExampleString); index++)
  { 
    /* Sequentially write example data to the EEPROM */
    HCRTC.EEWriteByte(ExampleString[index]);
  }
  /* End the write sequence */
  HCRTC.EEEndWrite();
 
  /* Wait for cached data to finish writing */
  delay(10); 
 
 
  /************* Example read from EEPROM ***************/ 
 
  /* Initiate read sequence.
     Parameters are: I2C address, EEPROM start location */
  HCRTC.EEStartRead(I2C24C32Add, 32000);
 

  for (index = 0; index < sizeof(ExampleString); index++)
  {
    /* Sequentially read data from EEPROM and output it to the UART */
    Serial.write(HCRTC.EEReadByte(I2C24C32Add));
  }   
  Serial.println();
   
 
  /* Continuously read the current time and date from the RTC */
  while(true)
  {
    /* Read the current time from the RTC module */
    HCRTC.RTCRead(I2CDS1307Add);
   
    /* Output the information to the UART */
    Serial.print(HCRTC.GetDay());
    Serial.print("/");
    Serial.print(HCRTC.GetMonth());
    Serial.print("/");
    Serial.print(HCRTC.GetYear());
    Serial.print(" ");
   
    Serial.print(HCRTC.GetHour());
    Serial.print(":");
    Serial.print(HCRTC.GetMinute());
    Serial.print(":");
    Serial.print(HCRTC.GetSecond());
    Serial.print(" DOW:");
    Serial.println(HCRTC.GetWeekday());
   
    /* Now output the same thing but using string functions instead: */
    Serial.print(HCRTC.GetDateString());
    Serial.print(" ");
    Serial.println(HCRTC.GetTimeString());
   
    /* Wait a second before reading again */
    delay(1000); 
  }
}



FAQ:

What does the SQ pin do?
The DS1307 has a feature where you can output a square wave to a pin. This can at fixed frequencies of 1Hz, 4KHz, 8KHz, and 32KHz. You have to configure an internal register to do this but when configured correctly the square wave will appear on the SQ pin.

What does the DS pin do?
If you take a look at the pictures in this post you'll notice there a unsoldered 3 pads in the top left corner. These allow you to solder an optional DS1820 temperature sensor. If you do this the DS pin provides access to its data out pin.

How do I connect this module to an Arduino?
The module needs to be connected to your Arduino's I2C interface (SDA & SCL pins). For an Arduino Uno, Nano, or Pro Mini you can connect the module as follows:

RTC.......Arduino(Uno/Nano/ProMini)
GND.....GND
VCC......5V
SDA......A4 (SDA)
SCL.......A5 (SCL)




Arduino Library:
The library can be found within the software section of this forum here


Thu May 09, 2013 8:57 am
Profile

Joined: Fri May 31, 2013 11:38 am
Posts: 1
Post Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00
I have this working fine but one small issue is that I want 2 digits to be displayed. For example the date today is 31/05/13 but the output is 31/5/13. What is the code for always outputting 2 digits?

Thanks
Mark


Fri May 31, 2013 12:20 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:02 pm
Posts: 650
Post Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00
This is because of the way the print function prints out numbers, rather than anything to do with the RTC library. To pad out the number with an extra zero, a quick and simple way would be to just test if the number is less then 10 and if so, print out an extra zero. For example:

Code:
 
if(HCRTC.GetMonth() < 10)
      Serial.print(0);
Serial.println(HCRTC.GetMonth()); 


Sat Jun 01, 2013 9:55 am
Profile

Joined: Wed Aug 07, 2013 5:57 pm
Posts: 3
Post Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00
Hi,

I've recently bought a Tiny RTC DS1307 module from your ebay store and I've a problem since the module loses time when I power off Arduino.
I've tried with the library (HCRTC) and the example sketch that you have provided and every time I disconnect Arduino from power the time is reset to 1/1/2000.

For testing I've uploaded the HCRTC_Example sketch, then I've reuploaded the sketch with line
Code:
HCRTC.RTCWrite(I2CDS1307Add, 13, 4, 24, 14, 21, 0, 3);
commented (otherwise every time I disconnect Arduino time will be set to that parameters).

Until external power is provided to arduino the clock is ok, RTC battery level (measurem from bat pin) is 3V.

Do I miss something or the RTC has some problems?

Thanks

Stefano


Thu Aug 08, 2013 9:10 am
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 643
Post Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00
From the information you have given us you don't appear to be doing anything wrong. It really does sound like the DS13072 is not getting power from the battery. The most likely cause is a bad contact in the battery holder but the fact that you can measure the battery voltage at the BAT pin suggests this is not the case. If possible, with the module not powered, could you carefully measure the voltage at pin 3 (VBAT) of the DS13072? This is the 3rd pin down from the pin marked with a dot.

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Thu Aug 08, 2013 10:27 am
Profile

Joined: Wed Aug 07, 2013 5:57 pm
Posts: 3
Post Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00
Thank you for your answer Andrew.

I measured vbat - gnd voltage with the module disconnected and my multimeter says it is 2.94V (same voltage when module connected). The battery itself is 4.1V. Are these values ok?

I've reduced my set up to only arduino and Tiny RTC module and it starts acting in another weird behaviour: it stops counting when I disconnect 5V power provided by Arduino.

I really don't understand where I'm doing wrong. The pins on the lines P1 and P2 are the same (I've used P1)? I've connected SDA with A4 and SCL with A5.


Thu Aug 08, 2013 3:12 pm
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 643
Post Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00
Sorry, I just realised my question could be misinterpreted... Would you be able to measure the voltage on the pin of the IC itself? Its the IC marked DS13072. The pin you are looking for is pin 3 which is the 3rd one down from the pin with a dot next to it. This may be a little fiddly as the pins are very close together. You will also need to do this with no power applied to the module (including IO connections from your Arduino), but with the battery connected. This will tell us if the chip itself is getting power from the battery. Everything you have said suggests that the device is not getting the battery backup.

I wouldn't get too hung up about what happens when you remove the 5V supply because if we assume that the device is also not getting the 3V from the battery then it's probably just getting enough leakage current from the data pins on the Arduino, but not enough to keep the clock circuitry running. The battery voltages you measure seem sensible to me.

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Thu Aug 08, 2013 4:30 pm
Profile

Joined: Wed Aug 07, 2013 5:57 pm
Posts: 3
Post Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00
Yes, I've already measured it on the IC (in the image I've measured voltage between pins highlighted in red) with the module disconnected from any power source (other than the module battery) obtaining 2.94V.

Image


Fri Aug 09, 2013 8:20 am
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 643
Post Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00
Ok, it sounds like you do have a faulty module. I'm going to pull one out of stock and check that nothing has changed to stop the software from working but this is unlikely. I can't find you on our system from your forum details, could you email us either your order number or account number if you bought it via our website, or your eBay user name if you bought it from our eBay shop. The email address is sales@hobbycomponents.com

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Fri Aug 09, 2013 9:19 am
Profile
Site Admin

Joined: Sun Aug 05, 2012 4:15 pm
Posts: 643
Post Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00
Thanks for confirming your account. I've pulled one out of stock and it works fine with the library so it does look like you have one with a weird fault. I'm going to contact you via email to arrange a replacement or refund.

_________________
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.


Fri Aug 09, 2013 11:35 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 80 posts ]  Go to page 1, 2, 3, 4, 5 ... 8  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Thank you to phpBB.com & phpBB.ro.
Design created by Florea Cosmin Ionut.
© 2011 All contents of this site are © Hobby Components LTD