DS1302 Real Time Clock Module (HCMODU0035)

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

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by andrew » Mon Nov 23, 2015 11:39 am

If you leave it running do the seconds tick up?

Also could try commenting out the following 3 lines:

Code: Select all

  //rtc.setDOW(MONDAY);
  //rtc.setTime(16,30,0);
  //rtc.setDate(21,11,2015); 
Then try resetting the Arduino a few times. Each time you reset it does it go back to Monday 21.01.2018 or does it continue to tick up.

If so try removing the power to the Arduino and RTC module for a minute and apply the power again. What happens this time? Does it go back to Monday 21.01.2018 or does it continue to tick up?
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Aermoe
Posts: 3
Joined: Tue Oct 13, 2015 12:52 pm

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by Aermoe » Thu Nov 26, 2015 12:59 pm

1) Yes the seconds tick up:

Code: Select all

Monday 19.01.2018 -- 00:00:00
Monday 19.01.2018 -- 00:00:01
Monday 19.01.2018 -- 00:00:02
Monday 19.01.2018 -- 00:00:03
Monday 19.01.2018 -- 00:00:04
Monday 19.01.2018 -- 00:00:05
Monday 19.01.2018 -- 00:00:06
Monday 19.01.2018 -- 00:00:07
Monday 19.01.2018 -- 00:00:08
2) Commented out the selected part:

Code: Select all

Monday 19.01.2018 -- 00:02:48
Monday 19.01.2018 -- 00:02:49
Monday 19.01.2018 -- 00:02:50
Monday 19.01.2018 -- 00:02:51
Monday 19.01.2018 -- 00:02:52
Monday 19.01.2018 -- 00:02:53
Monday 19.01.2018 -- 00:02:54
Monday 19.01.2018 -- 00:02:55
Monday 19.01.2018 -- 00:02:56
Monday 19.01.2018 -- 00:02:57
3) did the reset. Here something weird happens, look at that 03:70 jump to 4 minutes, jump to 5 minutes. I've resetted the arduino before this (keeps counting up from where it left) and then i resetted it mid monitor:

Code: Select all

Monday 19.01.2018 -- 00:03:66
Monday 19.01.2018 -- 00:03:67
Monday 19.01.2018 -- 00:03:68
Monday 19.01.2018 -- 00:03:69
Monday 19.01.2018 -- 00:03:70
Monday 19.01.2018 -- 00:04:81
Monday 19.01.2018 -- 00:05:44
Monday 19.01.2018 -- 00:05:45
Monday 19.01.2018 -- 00:05:46
Monday 19.01.2018 -- 00:05:47
Monday 19.01.2018 -- 00:05:48
4) waited a couple of minutes while the Arduino was disconnected (had lunch), plugged it back in, monitored:

Code: Select all

Monday 19.01.2018 -- 00:32:19
Monday 19.01.2018 -- 00:32:20
Monday 19.01.2018 -- 00:32:21
Monday 19.01.2018 -- 00:32:22
Monday 19.01.2018 -- 00:32:23

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

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by andrew » Thu Nov 26, 2015 2:59 pm

The tests do show that when left alone it is counting up correctly. The weird things seem to happen when your Arduino is reset. It's not clear what could be cauing it to do that but it could be something as simple a bad connection. I assume that you have the module connected to your Mega via some wires and not soldered to a PCB? If so are the wires long? If you can swap them around try that to see if it fixes it or causes a different problem.

One thing I forgot to ask is are you powering it from the Mega? if so do you have it connected to the 3.3V or 5V power pins?
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Aermoe
Posts: 3
Joined: Tue Oct 13, 2015 12:52 pm

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by Aermoe » Sat Nov 28, 2015 12:15 pm

Image

This is my current setup, so the wires are not very long. My earlier tests used pins 6,7,8. Now I'm using pins 2,3,4. But the issue remains. I have the RTC powered from my Mega and the battery is inserted. The power from the Mega is 3v3.

I've switched it to 5V supply and now I can set my date and time!! How is this possible??

Code: Select all

Saturday 28.11.2015 -- 12:53:00
Saturday 28.11.2015 -- 12:53:01
Saturday 28.11.2015 -- 12:53:02
Saturday 28.11.2015 -- 12:53:03
Saturday 28.11.2015 -- 12:53:04
Saturday 28.11.2015 -- 12:53:05
I unplugged the Arduino to check if it remains counting up.

Code: Select all

Saturday 28.11.2015 -- 13:09:35
Saturday 28.11.2015 -- 13:09:36
Saturday 28.11.2015 -- 13:09:37
seems fine now? This is weird

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

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by andrew » Mon Nov 30, 2015 11:05 am

I've switched it to 5V supply and now I can set my date and time!! How is this possible??
Ah, that will be the problem. A Mega needs a minimum of about 3V at its digital pin to see it as a logic high. If you power the RTC from a 3.3V supply then a logic high from the RTC will be just under 3V so it will be right on the edge of what the Mega will accept as a logic high. With a 5V supply a logic high from the RTC will be around 4.2V which is more than enough for the Mega.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

steveand39
Posts: 1
Joined: Wed Jan 10, 2018 2:59 pm

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by steveand39 » Mon Jan 22, 2018 7:25 pm

Hi I have downloaded you sample code for this module and got it displaying to your ic2 20 by 4 lcd display. If I use
(q) =(rtc.getTimeStr());
Serial.println (q);
the serial monitor print out a three digit number eg 584
this number stays the same how do I convert this or retrieve hour minute from the rtc to compare to a variable to make a alarm

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

Re: DS1302 Real Time Clock Module (HCMODU0035)

Post by andrew » Tue Jan 23, 2018 10:11 am

Have you defined q to be a String?

Code: Select all

String q = rtc.getTimeStr();
Serial.println(q);
how do I convert this or retrieve hour minute from the rtc to compare to a variable to make a alarm
This isn't our library so I can't give you much help on it but it seems to have a getTime() function that gets the hours, mins, secs, dow, etc seperatly (take a look at the DS1302.h file) and returns them in a class called Time. So you should be able to do something like this:

Code: Select all

Time result = rtc.getTime();

Serial.print(result.hour);
Serial.print(" : ");
Serial.println(result.min); 
As result.hour and result.min are just bytes you should be able to compare them with any other byte value.
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “RTC”