# Reading DS3231 RTC in Node Red

**URL:** https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133
**Category:** Dashboard
**Created:** [31 January 2021 21:06 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133 "2021-01-31T21:06:25Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![wa9mvz](https://avatars.discourse-cdn.com/v4/letter/w/aeb1de/32.png) [@wa9mvz](https://discourse.nodered.org/u/wa9mvz)
#### Post date: [31 January 2021 21:06 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/1 "2021-01-31T21:06:26Z")

</div>

Is there a simple way to input time to display on the dashboard from the DS3231 RTC module? Using the I2C IN node, I can see and read what looks like seconds and minutes data using the 00 and 01 commands in those nodes. The SECONDS update to a new number every second, but it isn't decimal. The seconds start at 0 and count to 9 then jump to 16. It displays erratically up to 100 and then the minutes digit changes.

So now I suppose I have to decode this somehow to decimal to display a real looking clock on the dashboard.

This seem very awkward. Is there a simpler way?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [31 January 2021 21:27 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/2 "2021-01-31T21:27:43Z")

</div>

I think that is called binary coded decimal. Been ages since I’ve seen it but I’m sure google will help

---

<div class="post-metadata">

### Author: ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)
#### Post date: [31 January 2021 21:35 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/3 "2021-01-31T21:35:35Z")

</div>

Looking at the datasheet the upper 4 bits are the 10 seconds and the lower the seconds, same for the minutes etc.  
I don't know Javascript good enough for bit manipulation.  
In C we AND the right 4 bits to get the seconds value and then shift the left 4 bits to right to get 10th seconds value.

 ![rtc](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a3f00072d48b1df4b0cc91a7f279b382e73bc581.png)

---

<div class="post-metadata">

### Author: ![wa9mvz](https://avatars.discourse-cdn.com/v4/letter/w/aeb1de/32.png) [@wa9mvz](https://discourse.nodered.org/u/wa9mvz)
#### Post date: [31 January 2021 21:51 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/4 "2021-01-31T21:51:59Z")

</div>

Yes, I recognize it as HEXADECIMAL, and I could certainly decode it in C but that really wasn't my question.

This was very easy to do on an Arduino so I'll rephrase my question: isn't there an easier way to read this very common device (DS3231 RTC) in NODE RED? Surely someone has done this before.

---

<div class="post-metadata">

### Author: ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)
#### Post date: [31 January 2021 22:02 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/5 "2021-01-31T22:02:13Z")

</div>

Try this in a function node

```auto
var val = msg.payload
msg.payload= ((Math.floor(val/16)*10)+val%16)
return msg;

```

---

<div class="post-metadata">

### Author: ![wa9mvz](https://avatars.discourse-cdn.com/v4/letter/w/aeb1de/32.png) [@wa9mvz](https://discourse.nodered.org/u/wa9mvz)
#### Post date: [31 January 2021 22:39 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/6 "2021-01-31T22:39:19Z")

</div>

I guess I gotta do what I gotta do.

Thanks for that snippet edje11 ... it decodes and displays perfectly now.

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [1 February 2021 00:01 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/7 "2021-02-01T00:01:10Z")

</div>

> [@wa9mvz](#):
>
> isn't there an easier way to read this very common device (DS3231 RTC) in NODE RED? Surely someone has done this before.

Did you check NPM for a node.js package ? Apparently there are two of them who are up to the job.

---

<div class="post-metadata">

### Author: ![wa9mvz](https://avatars.discourse-cdn.com/v4/letter/w/aeb1de/32.png) [@wa9mvz](https://discourse.nodered.org/u/wa9mvz)
#### Post date: [1 February 2021 00:27 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/8 "2021-02-01T00:27:33Z")

</div>

I did search, but nothing returned. Could you be more specific for my search?

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [1 February 2021 20:18 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/9 "2021-02-01T20:18:11Z")

</div>

Only today I could have a better look on them. Both are lacking a Github repository. It seems to me they are abandoned. You probably did the right choice on handling them directly with I2C node, reading the internal registers.

> **[@nanomatic/ds3231](https://www.npmjs.com/package/@nanomatic/ds3231)**
>
> RTC DS3231 implementation for the Raspberry PI 4 + temperature reading 🌡

> **[ds3231-rtc](https://www.npmjs.com/package/ds3231-rtc)**
>
> This package is to use DS3231 realtime clock module with nodejs

---

<div class="post-metadata">

### Author: ![wa9mvz](https://avatars.discourse-cdn.com/v4/letter/w/aeb1de/32.png) [@wa9mvz](https://discourse.nodered.org/u/wa9mvz)
#### Post date: [4 February 2021 16:19 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/10 "2021-02-04T16:19:45Z")

</div>

Well, I seemed to have really messed something up. All was working well until I followed some tutorials about how to set the HWCLOCK.

Now, when I scan using 'i2cdetect -y 1' it shows ports 57 and a UU in port 68 where the DS3231 is supposed to be. The 'UU' is supposedly a conflict but the commands 'sudo hwclock -r' and sudo hwclock -w' entered into the terminal seem to work.

Yet using the i2c Scan node, a port 87 appears. I get errors when I try to use the 'i2c in' nodes to connect to 57 or 68. It will connect to the phantom port 87 but I only receive '255' in the msg.

Can someone tell me what I've messed up here?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [18 February 2021 16:20 UTC](https://discourse.nodered.org/t/reading-ds3231-rtc-in-node-red/40133/11 "2021-02-18T16:20:09Z")

</div>

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