# How to read time from non I2C DS1302 RTC module

**URL:** <https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341>\
**Category:** Hardware Interfacing Questions\
**Created:** [August 25, 2020, 11:33am UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341 "2020-08-25T11:33:04Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![unosoperator](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/unosoperator/32/2678_2.png) [@unosoperator](https://forum.xod.io/u/unosoperator)\
**Post date:** [August 25, 2020, 11:33am UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/1 "2020-08-25T11:33:04Z")

</div>

Hi.  
I want to use time and data from rtc module based on ds1302 chip like in picture below:

![RTC-DS1302-MODUL-ZEGAR-CZASU-RZECZYWISTEGO-ARDUINO](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/3/30d786b123cbb3092ee12883e78972c6d6ad2507.jpeg)

I know there is Xod library for rtc module but its for i2c comunication. But module that i have is called 3 wire comunication. It has 5 pins: VCC, GND, CLK, DAT, and RST.

I checked this module using Arduino IDE and use sketch from this link:  
[https://playground.arduino.cc/Main/DS1302/](https://playground.arduino.cc/Main/DS1302/)

It work and show data in serial monitor.

Any idea how to use it with Xod.

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [August 25, 2020, 7:14pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/2 "2020-08-25T19:14:49Z")

</div>

Hi, can cesars/ds1302

> [@Problems with DS1302](https://forum.xod.io/t/problems-with-ds1302/1776):
>
> Hello, How to connect ds 1302 to arduino nano? Ds 1302 does not have i2c. In the description of the library ds-rtc nothing is written.

---

<div class="post-metadata">

**Author:** ![unosoperator](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/unosoperator/32/2678_2.png) [@unosoperator](https://forum.xod.io/u/unosoperator)\
**Post date:** [August 26, 2020, 8:38am UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/3 "2020-08-26T08:38:43Z")

</div>

I load your library and try it on two different boards, Nano and Uno, but still cant get any data from RTC module. However it works with sketch from link via Arduino IDE, so the module itself is fine.

---

<div class="post-metadata">

**Author:** ![unosoperator](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/unosoperator/32/2678_2.png) [@unosoperator](https://forum.xod.io/u/unosoperator)\
**Post date:** [August 26, 2020, 2:33pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/4 "2020-08-26T14:33:57Z")

</div>

I connect everything like in this picture, and go o debug mode:

 ![Bez tytułu](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/2/2b8ac8927aaafb563339df288732e4c49b528727.jpeg)

When left button is pressed and released, to set data and hour, it change its status from false to true,and back to false, just like supposed to. When right button is pressed to read data, it change its status from false to true, but when its released its looks like its freeze all debug mode, and its stay true, even the button is released. Rtc-ds node show “00-00-00”, rtc-wds show “watch”, and rtc-ds show “00:00:00”.

---

<div class="post-metadata">

**Author:** ![unosoperator](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/unosoperator/32/2678_2.png) [@unosoperator](https://forum.xod.io/u/unosoperator)\
**Post date:** [August 30, 2020, 12:35pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/5 "2020-08-30T12:35:43Z")

</div>

Anyone else have this module, and can check it with Xod?

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [August 30, 2020, 2:25pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/6 "2020-08-30T14:25:03Z")

</div>

You could be having conflict with timers used for serial communication for rtc and debug… Just grasping at straws…

---

<div class="post-metadata">

**Author:** ![unosoperator](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/unosoperator/32/2678_2.png) [@unosoperator](https://forum.xod.io/u/unosoperator)\
**Post date:** [August 30, 2020, 5:18pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/7 "2020-08-30T17:18:37Z")

</div>

Yes. Its looks like it’s because debug is on.

So, I finally make my RTC module work in Xod. I get date, weekday and time from it, and display on LCD:

 ![prt](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/5/54071a952c9d9d0ba750d27db51a03a5349fae21.jpeg)

I use `tobias/plc` library to format data from module. But there is problem with year and weekday. Year, instead “2020” is “55”, and weekday instead “SUN” ( sunday, which is seventh day of week) is “SAT”.

 ![IMG_20200830_191633](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/5/55b5aab11229ab533eef6e34ebcb74312b92de7e.jpeg)

---

<div class="post-metadata">

**Author:** ![danya](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@danya](https://forum.xod.io/u/danya)\
**Post date:** [August 30, 2020, 10:34pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/8 "2020-08-30T22:34:49Z")

</div>

Hi. What I will say now is more a question than an answer. I don’t have a sensor, and I don’t have the ds1302 and tobias / plc libraries, but why can’t I set a date (without a sensor) in some patch, and after every second add one to this patch? The Patch itself will have functions to convert seconds to minutes, minutes to hours, hours to days, etc (ships everywhere, the cesars/ds1302 library works like that).  
The question is: Why do i need a sensor, if using programming it is possible to calculate the time anyway? As I understand it, the only thing, that the sensor can do is work without an arduino board connected to the power supply (using battery), right?

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [August 31, 2020, 12:02am UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/9 "2020-08-31T00:02:29Z")

</div>

My guess would be that day of week is using 1 for Monday, but rtc-wds is an nth-input which starts at zero, so you need to add an extra pin in front of Monday.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [August 31, 2020, 12:04am UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/10 "2020-08-31T00:04:51Z")

</div>

Danya, RTC is used to remember time when Arduino is power cycled and it also keeps more accurate time than counting seconds in software.

---

<div class="post-metadata">

**Author:** ![danya](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@danya](https://forum.xod.io/u/danya)\
**Post date:** [August 31, 2020, 9:35am UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/11 "2020-08-31T09:35:57Z")

</div>

If rts-wds is like nth-input, then the number 7 will go beyond nth-input, then it will still show Sunday, not Saturday.

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/f/ff6767d60d5f66fbc774205c6c86f4316ef6bb69.png)  
So the error is not here. I have a guess that this is due to the year. The day of the week depends on the year.

---

<div class="post-metadata">

**Author:** ![danya](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@danya](https://forum.xod.io/u/danya)\
**Post date:** [August 31, 2020, 9:41am UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/12 "2020-08-31T09:41:52Z")

</div>

and as it turned out, the rtc-wds is not a nth-input.

 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/0/0c04f0c045f5a4999b63fe71d2bc40c1af9a314e.png)  
 ![image](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/2X/e/e579c4c3e768ad39368be5fd2f2a3e44da3872a6.png)

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [August 31, 2020, 7:21pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/13 "2020-08-31T19:21:25Z")

</div>

Isn’t Sunday the 1st day of the week rather than Monday?

---

<div class="post-metadata">

**Author:** ![unosoperator](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/unosoperator/32/2678_2.png) [@unosoperator](https://forum.xod.io/u/unosoperator)\
**Post date:** [September 1, 2020, 7:56am UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/14 "2020-09-01T07:56:54Z")

</div>

Looks like first day of the week is different around the world. I’m from Poland, and here, in every calendar I’ve seen, Monday is first . But for example in Google Calendar app you can choose which day is first.  
Now i have proper weekday on display, but still year is “55” instead “2020”.

---

<div class="post-metadata">

**Author:** ![gweimer](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@gweimer](https://forum.xod.io/u/gweimer)\
**Post date:** [September 1, 2020, 5:06pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/15 "2020-09-01T17:06:07Z")

</div>

Sounds like RTC may need 1965 added to the year. There could be something else wrong that this would only be a kludge to cover up the problem, though… 1965 is an odd year to be the “epoch”…

---

<div class="post-metadata">

**Author:** ![unosoperator](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/unosoperator/32/2678_2.png) [@unosoperator](https://forum.xod.io/u/unosoperator)\
**Post date:** [September 1, 2020, 5:39pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/16 "2020-09-01T17:39:29Z")

</div>

Thanks a lot. This trick work. Now I have correct 2020 year.

---

<div class="post-metadata">

**Author:** ![cesars](https://avatars.discourse-cdn.com/v4/letter/c/f05b48/32.png) [@cesars](https://forum.xod.io/u/cesars)\
**Post date:** [September 2, 2020, 3:02am UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/17 "2020-09-02T03:02:02Z")

</div>

Hi, It is one of my first libraries, which I modified later but there were errors.

Eliminate the internal debug, you should be able to simulate now, the error of the year is because I put 2020 and according to the datasheet the year record of the RTC is from 00 to 99.  
hence the error and the need to add 1965.

Updated @0.0.7, try …

---

<div class="post-metadata">

**Author:** ![unosoperator](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.xod.io/unosoperator/32/2678_2.png) [@unosoperator](https://forum.xod.io/u/unosoperator)\
**Post date:** [September 2, 2020, 6:50pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/18 "2020-09-02T18:50:30Z")

</div>

Ok. Thanks **cesars**.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex027/uploads/xod/original/1X/eb7348baa04192c2ef932d1db54d44f09f8a7888.png) [@system](https://forum.xod.io/u/system)\
**Post date:** [September 4, 2020, 6:50pm UTC](https://forum.xod.io/t/how-to-read-time-from-non-i2c-ds1302-rtc-module/4341/19 "2020-09-04T18:50:33Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
