DS1302 Real Time Clock Module (HCMODU0035)

Real Time Clock modules for microcontrollers
andrew
Site Admin
Posts: 787
Joined: Sun Aug 05, 2012 4:15 pm

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by andrew » Fri Dec 13, 2013 2:23 pm

I have moved your last post to the general discussions forum as it was getting a bit off topic for this thread.

The reason why you are getting these errors is because you need to install the library that is in the first post of this thread. A guide on how to do this is available on the official Arduino website here:

http://arduino.cc/en/Guide/Libraries

I would recommend using the manual install method.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

normski001
Posts: 35
Joined: Thu Dec 12, 2013 7:58 am

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by normski001 » Fri Dec 13, 2013 3:12 pm

that is done now installed but i have nothing but squares on my led screen

normski001
Posts: 35
Joined: Thu Dec 12, 2013 7:58 am

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by normski001 » Fri Dec 13, 2013 3:41 pm

if i put in example from library i get a time and date up, here is what i put in
// DS1302_LCD (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to make a quick
// clock using a DS1302 and a 16x2 LCD.
//
// I assume you know how to connect the DS1302 and LCD.
// DS1302: CE pin -> Arduino Digital 2
// I/O pin -> Arduino Digital 3
// SCLK pin -> Arduino Digital 4
// LCD: DB7 -> Arduino Digital 6
// DB6 -> Arduino Digital 7
// DB5 -> Arduino Digital 8
// DB4 -> Arduino Digital 9
// E -> Arduino Digital 10
// RS -> Arduino Digital 11

#include <LiquidCrystal.h>
#include <DS1302.h>

// Init the DS1302
DS1302 rtc(26, 24, 22);

// Init the LCD
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup()
{
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);

// Setup LCD to 16x2 characters
lcd.begin(16, 2);

// The following lines can be commented out to use the values already stored in the DS1302
rtc.setDOW(FRIDAY); // Set Day-of-Week to FRIDAY
rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
rtc.setDate(6, 8, 2010); // Set the date to August 6th, 2010
}

void loop()
{
// Display time centered on the upper line
lcd.setCursor(4, 0);
lcd.print(rtc.getTimeStr());

// Display abbreviated Day-of-Week in the lower left corner
lcd.setCursor(0, 1);
lcd.print(rtc.getDOWStr(FORMAT_SHORT));

// Display date in the lower right corner
lcd.setCursor(6, 1);
lcd.print(rtc.getDateStr());

// Wait one second before repeating :)
delay (1000);
}

normski001
Posts: 35
Joined: Thu Dec 12, 2013 7:58 am

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by normski001 » Sun Dec 15, 2013 5:07 pm

here is my final code to test clock may keep it to use later, made a few changes showing how it is connected for mega board and keypad shield

Code: Select all

// DS1302_LCD (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// DS1302:  RST pin   -> Mega 2560 pin 26
//          I/O pin   -> pin 24
//          SCK pin   -> pin  22
// LCD: Keypad shield 6 button
//   DB7       -> Mega 2560 pin 7
//   DB6       -> Mega 2560 pin 6
//   DB5       -> Mega 2560 pin 5
//   DB4       -> Mega 2560 pin 4
//   E         -> Mega 2560 pin 9
//   RS        -> Mega 2560 pin 8
//   Backlite  -> Mega 2560 pin 10



#include <LiquidCrystal.h>
#include <DS1302.h>


DS1302 rtc(26, 24, 22);  // Init the DS1302
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);  // Init the LCD

void setup()
{
 
  rtc.halt(false);   // Set the clock to run-mode, and disable the write protection
  rtc.writeProtect(false);
  
  lcd.begin(16, 2);   // Setup LCD to 16x2 characters

// to first set up clock remove the slashes in lines below, once set put them back to use internal clock time
 // rtc.setDOW(SUNDAY);        // Set Day-of-Week to SUNDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
 // rtc.setDate(15, 12, 2013);   // Set the date to December 15th, 2013
}

void loop()
{
  lcd.setCursor(6, 0);    // Display time on the upper line
  lcd.print(rtc.getTimeStr());
  
  lcd.setCursor(1, 0);   // Display abbreviated Day-of-Week in the upper left corner
  lcd.print(rtc.getDOWStr(FORMAT_SHORT));
  
  lcd.setCursor(5, 1);   // Display date in the lower right corner
  lcd.print(rtc.getDateStr());

  
  delay (1000);   // Wait one second before repeating :)
}

normski001
Posts: 35
Joined: Thu Dec 12, 2013 7:58 am

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by normski001 » Tue Dec 17, 2013 8:19 am

if i have a program that uses a 1307 rtc can i use a 1302 rtc or do i need to use a 1307

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

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by andrew » Tue Dec 17, 2013 10:44 am

No they use different controller chips so a 1307 library won't work with a 1302 and vice versa. We do have libraries for both versions on this forum though.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

tag931
Posts: 1
Joined: Mon Mar 17, 2014 5:13 pm

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by tag931 » Mon Mar 17, 2014 5:16 pm

Hi, the battery on my RTC module has gone flat so it's forgetting the time whenever I unplug my Arduino. Is there any additional code I need to add to enable trickle charging or might there be another issue?
Thanks

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

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by andrew » Mon Mar 17, 2014 6:50 pm

The trickle charging option is off by default and can be turned on via a register access but please keep in mind that the battery supplied with these modules is not rechargeable.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

kenco
Posts: 12
Joined: Tue Jan 14, 2014 4:25 pm

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by kenco » Thu Nov 06, 2014 3:46 pm

hi andrew have uploaded code and when i view serial info i get 2 diffrent readings printed one the correct time which i have put in listing and a old time setting how do i get rid of the old time? it seems to read correct time then a old one from some where

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

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by andrew » Fri Nov 07, 2014 9:52 am

Which sketch are you using, is it the one in the first post of this thread written by us or something else?
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply