Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU0011)

Real Time Clock modules for microcontrollers
Post Reply
admin
Site Admin
Posts: 865
Joined: Sun Aug 05, 2012 4:02 pm

Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU0011)

Post by admin » Thu May 09, 2013 8:57 am

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:
  1. /* FILE     HCRTC_Example.cpp
  2.    DATE:    23/12/13
  3.    VERSION: 0.2
  4.    AUTHOR:  Andrew Davies
  5.  
  6. This is an example of how to use the Hobby Components RTC library to read and
  7. write to and from the DS1307 real time clock 24C32 EEPROM. The library is intended
  8. to be used with our RTC clock module (HCMODU0011), but should work fine with any
  9. module that uses a DS1307 device.
  10.  
  11. You may copy, alter and reuse this code in any way you like, but please leave
  12. reference to HobbyComponents.com in your comments if you redistribute this code.
  13. This software may not be used directly for the purpose of selling products that
  14. directly compete with Hobby Components Ltd's own range of products.
  15.  
  16. THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
  17. EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  18. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
  19. HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
  20. INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
  21. REASON WHATSOEVER.
  22. */
  23.  
  24.  
  25. /* Include the wire library */
  26. #include "Wire.h"
  27. /* Include the Hobby Components RTC library */
  28. #include <HCRTC.h>
  29.  
  30. /* The RTC and EEPROM have fixed addresses of 0x68 and
  31.     0x50 so define these in software */
  32. #define I2CDS1307Add 0x68
  33. #define I2C24C32Add  0x50
  34.  
  35. /* Example string to write to EEPROM */
  36. char ExampleString[] = "Hobby Components";
  37.  
  38. /* Used in example as an index pointer */
  39. byte index;
  40.  
  41. /* Create an instance of HCRTC library */
  42. HCRTC HCRTC;
  43.  
  44.  
  45. void setup()
  46. {
  47.   Serial.begin(9600);
  48.  
  49.   /* Use the RTCWrite library function to set the time and date.
  50.      Parameters are: I2C address, year, month, date, hour, minute, second,
  51.      day of week */
  52.   HCRTC.RTCWrite(I2CDS1307Add, 13, 4, 24, 14, 21, 0, 3);
  53. }
  54.  
  55. void loop()
  56. {
  57.   /************* Example write to EEPROM ***************/  
  58.  
  59.   /* Initiate a write sequence.
  60.      Parameters are: I2C address, EEPROM start location */
  61.   HCRTC.EEStartWrite(I2C24C32Add, 32000);
  62.  
  63.   for (index = 0; index < sizeof(ExampleString); index++)
  64.   {  
  65.     /* Sequentially write example data to the EEPROM */
  66.     HCRTC.EEWriteByte(ExampleString[index]);
  67.   }
  68.   /* End the write sequence */
  69.   HCRTC.EEEndWrite();
  70.  
  71.   /* Wait for cached data to finish writing */
  72.   delay(10);  
  73.  
  74.  
  75.   /************* Example read from EEPROM ***************/  
  76.  
  77.   /* Initiate read sequence.
  78.      Parameters are: I2C address, EEPROM start location */
  79.   HCRTC.EEStartRead(I2C24C32Add, 32000);
  80.  
  81.  
  82.   for (index = 0; index < sizeof(ExampleString); index++)
  83.   {
  84.     /* Sequentially read data from EEPROM and output it to the UART */
  85.     Serial.write(HCRTC.EEReadByte(I2C24C32Add));
  86.   }    
  87.   Serial.println();
  88.    
  89.  
  90.   /* Continuously read the current time and date from the RTC */
  91.   while(true)
  92.   {
  93.     /* Read the current time from the RTC module */
  94.     HCRTC.RTCRead(I2CDS1307Add);
  95.    
  96.     /* Output the information to the UART */
  97.     Serial.print(HCRTC.GetDay());
  98.     Serial.print("/");
  99.     Serial.print(HCRTC.GetMonth());
  100.     Serial.print("/");
  101.     Serial.print(HCRTC.GetYear());
  102.     Serial.print(" ");
  103.    
  104.     Serial.print(HCRTC.GetHour());
  105.     Serial.print(":");
  106.     Serial.print(HCRTC.GetMinute());
  107.     Serial.print(":");
  108.     Serial.print(HCRTC.GetSecond());
  109.     Serial.print(" DOW:");
  110.     Serial.println(HCRTC.GetWeekday());
  111.    
  112.     /* Now output the same thing but using string functions instead: */
  113.     Serial.print(HCRTC.GetDatestring());
  114.     Serial.print(" ");
  115.     Serial.println(HCRTC.GetTimestring());
  116.    
  117.     /* Wait a second before reading again */
  118.     delay(1000);  
  119.   }
  120. }

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

markandcath
Posts: 1
Joined: Fri May 31, 2013 11:38 am

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by markandcath » Fri May 31, 2013 12:20 pm

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

admin
Site Admin
Posts: 865
Joined: Sun Aug 05, 2012 4:02 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by admin » Sat Jun 01, 2013 9:55 am

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: Select all

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

floccs
Posts: 3
Joined: Wed Aug 07, 2013 5:57 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by floccs » Thu Aug 08, 2013 9:10 am

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: Select all

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

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andrew » Thu Aug 08, 2013 10:27 am

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.

floccs
Posts: 3
Joined: Wed Aug 07, 2013 5:57 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by floccs » Thu Aug 08, 2013 3:12 pm

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.

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andrew » Thu Aug 08, 2013 4:30 pm

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.

floccs
Posts: 3
Joined: Wed Aug 07, 2013 5:57 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by floccs » Fri Aug 09, 2013 8:20 am

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

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andrew » Fri Aug 09, 2013 9:19 am

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.

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: Tiny RTC DS1307 + 24C32 Real Time Clock Module (HCMODU00

Post by andrew » Fri Aug 09, 2013 11:35 am

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.

Post Reply

Return to “RTC”