# Adafruit RTClib

**URL:** <https://forum.arduino.cc/t/adafruit-rtclib/1390381>\
**Category:** General Guidance\
**Created:** [June 22, 2025, 3:02am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381 "2025-06-22T03:02:13Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nick\_Pyner](https://avatars.discourse-cdn.com/v4/letter/n/e8c25b/32.png) [@Nick\_Pyner](https://forum.arduino.cc/u/Nick_Pyner)\
**Post date:** [June 22, 2025, 3:02am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/1 "2025-06-22T03:02:13Z")

</div>

I have never used a library for my RTC but it looks like I might need to re-think this as I intend to use SQW to control my loop. The sample code I have uses RTClib but does not incorporate the wire and i2c libraries. Is this because the necessary is included in RTClib?

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [June 22, 2025, 3:14am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/2 "2025-06-22T03:14:53Z")

</div>

Checking the source code for [Adafruit RTClib](https://github.com/adafruit/RTClib/blob/master/src/RTClib.h) shows that it incorporates another of Adafruit's libraries, which resumably includes Wire and perhaps others.

```arduino
#ifndef _RTCLIB_H_
#define _RTCLIB_H_

#include <Adafruit_I2CDevice.h>

```

I tend to avoid Adafruit libraries because they try to hide details from beginners by throwing in the kitchen sink (in other words, bloatware). The very worst example is the Adafruit Unified Sensor library, which is so large that some examples won't fit on an Arduino Uno R3.

---

<div class="post-metadata">

**Author:** ![Nick\_Pyner](https://avatars.discourse-cdn.com/v4/letter/n/e8c25b/32.png) [@Nick\_Pyner](https://forum.arduino.cc/u/Nick_Pyner)\
**Post date:** [June 22, 2025, 4:16am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/3 "2025-06-22T04:16:43Z")

</div>

Thanks. I now recall previous comment to that effect. I will look elsewhere!

---

<div class="post-metadata">

**Author:** ![gabygold](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/gabygold/32/1048226_2.png) [@gabygold](https://forum.arduino.cc/u/gabygold)\
**Post date:** [June 22, 2025, 1:24pm UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/4 "2025-06-22T13:24:14Z")

</div>

Hi @Nick_Pyner ,

> [@Nick\_Pyner](#):
>
> I have never used a library for my RTC but it looks like I might need to re-think this as I intend to use SQW to control my loop. The sample code I have uses RTClib but does not incorporate the wire and i2c libraries. Is this because the necessary is included in RTClib?

You haven't specified which RTC you're using. Depending on the RTC chip you'll be using you'll have different libraries available.

> [@anon94801460](#):
>
> Checking the source code for [Adafruit RTClib](https://github.com/adafruit/RTClib/blob/master/src/RTClib.h) shows that it incorporates another of Adafruit's libraries, which resumably includes Wire and perhaps others.

Adafruit has different RTC breakboards, so it's library has gone the "one library, any RTC" kind of way. Last time I checked the Adafruit RTCLib depended at least on the Adafruit\_BUSIO library to cover the I2C and the SPI communications models they sell, but it seems to be right for their customers, so it's on them.

Once again you'll find some dedicated libraries for your RTC if you look for the RTC chip specific model.

Good Luck!

Gaby.//

---

<div class="post-metadata">

**Author:** ![david\_2018](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/david_2018/32/1013044_2.png) [@david\_2018](https://forum.arduino.cc/u/david_2018)\
**Post date:** [June 22, 2025, 1:28pm UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/5 "2025-06-22T13:28:37Z")

</div>

> [@Nick\_Pyner](#):
>
> I have never used a library for my RTC but it looks like I might need to re-think this as I intend to use SQW to control my loop

What is it about controlling the SQW output that prevents you from writing your own code? Seems like just a slightly different series of commands to set the proper bits in a control register.

---

<div class="post-metadata">

**Author:** ![ShermanP](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@ShermanP](https://forum.arduino.cc/u/ShermanP)\
**Post date:** [June 22, 2025, 2:09pm UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/6 "2025-06-22T14:09:56Z")

</div>

> [@david\_2018](#):
>
> What is it about controlling the SQW output that prevents you from writing your own code? Seems like just a slightly different series of commands to set the proper bits in a control register.

+1

I use the DS3231, but generally avoid RTC libraries. It seems there are at least 18 DS3231 libraries named DS3231.h. Ok well maybe not 18, but more than a few. And all the libraries operate just a little differently. So I use my own code. SQW output is fairly straightforward once you understand how it works. I use it to generate an alarm interrupt, and to power up an entire circuit at the right time with a mosfet. Very handy.

---

<div class="post-metadata">

**Author:** ![oldcurmudgeon](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/oldcurmudgeon/32/1280882_2.png) [@oldcurmudgeon](https://forum.arduino.cc/u/oldcurmudgeon)\
**Post date:** [June 22, 2025, 2:38pm UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/7 "2025-06-22T14:38:28Z")

</div>

Do you want to use it for square waves or as an interrupt?

---

<div class="post-metadata">

**Author:** ![Nick\_Pyner](https://avatars.discourse-cdn.com/v4/letter/n/e8c25b/32.png) [@Nick\_Pyner](https://forum.arduino.cc/u/Nick_Pyner)\
**Post date:** [June 22, 2025, 11:58pm UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/8 "2025-06-22T23:58:37Z")

</div>

I want SQW for the interrupt and a countdown in seconds. I wasn't clear enough about this and I now realise that I don't actually need a library for that. I guess though that I might as well use a library for stuff I don't normally do, like auto update and setting up for future events.  
The order of battle is:  
1 enter time of future event up to 100 hrs  
2 use itp to update local RTC via phone (ESP-01)  
3 subtract nowtime from thentime (ProMini)  
4 start countdown with LED display in hhmmss  
5 trigger camera via opto iso.

RTC is a DS3231 on ZS-042 board.

I have seen a programme using Ada's library and calls for wire.lib but not I2C.....

---

<div class="post-metadata">

**Author:** ![oldcurmudgeon](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/oldcurmudgeon/32/1280882_2.png) [@oldcurmudgeon](https://forum.arduino.cc/u/oldcurmudgeon)\
**Post date:** [June 23, 2025, 4:54pm UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/9 "2025-06-23T16:54:59Z")

</div>

You may want to look at my Garagerator project. It uses a DS3231RTC to time data logging intervals. It is a bit dated now but the idea is usable. Ignore the majority of the code. The parts of interest are **rtcISR()** to handle the timer interrupt, **setNextSampleTime()** to update the alarm Time, **setup()** external interrupt setup, Rtc setup and the **timerInterupt** handling in **loop()**.

You would need to modify the **setNextSampleTime()** to also handle days/months if you want delay times greater then 24 hours. If you use day of the week the library I used has the UNIX convention of 0-6 for day of the week rather than 1-7 as used by the DS3231. There are other libraries that just use the 1-7 of the DS3231.

> [@Web based temperature logger with ESP8266,DS18B20,DS3231 and LittleFS](https://forum.arduino.cc/t/web-based-temperature-logger-with-esp8266-ds18b20-ds3231-and-littlefs/1014793):
>
> This is a demo project that was written a few years ago when we hosted the family (US) Thanksgiving gathering. With all the extra food we were using the garage as a refrigerator for storage. Hence the name Garagerator. This code was initially written to insure the temperature was food safe. The code is a stand alone access point, so needs no connection to a LAN. On the board options for Flash Size set the file system size - I use 3MB. After uploading the code… Connect to the WiFi network Gar…

---

<div class="post-metadata">

**Author:** ![Nick\_Pyner](https://avatars.discourse-cdn.com/v4/letter/n/e8c25b/32.png) [@Nick\_Pyner](https://forum.arduino.cc/u/Nick_Pyner)\
**Post date:** [June 24, 2025, 12:40am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/10 "2025-06-24T00:40:21Z")

</div>

> [@oldcurmudgeon](#):
>
> parts of interest are **rtcISR()** to handle the timer interrupt, **setNextSampleTime()** to update the alarm Time, **setup()** external interrupt setup, Rtc setup and the **timerInterupt** handling in **loop()**.

Thank you. I'm coming to the conclusion that I don't actually need an RTC at all - or its library. I just need to convert the event time to epoch format, get current epoch time from ntp, subtract it from the former, and start counting. But I will still need ds3231's 1Hz sqw to control everything!

I believe Random Nerd has gone quite some way to simplify this sort of thing with an ntp library.

I will look at using ntp to automatically update the ds3231 for a seriously accurate RTC, but it's really just confectionery.

---

<div class="post-metadata">

**Author:** ![ShermanP](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@ShermanP](https://forum.arduino.cc/u/ShermanP)\
**Post date:** [June 24, 2025, 2:22am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/11 "2025-06-24T02:22:27Z")

</div>

If you just need a square wave, an alternative would be to get a GPS module with a PPS output pin. It will give you exactly 1Hz that you will never need to sync. But the downside would be the current draw. GPS can be greedy.

---

<div class="post-metadata">

**Author:** ![Nick\_Pyner](https://avatars.discourse-cdn.com/v4/letter/n/e8c25b/32.png) [@Nick\_Pyner](https://forum.arduino.cc/u/Nick_Pyner)\
**Post date:** [June 24, 2025, 3:02am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/12 "2025-06-24T03:02:12Z")

</div>

Indeed...  
And this is a battery powered project that uses stuff already to hand

> [@ShermanP](#):
>
> But the downside would be the current draw.

---

<div class="post-metadata">

**Author:** ![ShermanP](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@ShermanP](https://forum.arduino.cc/u/ShermanP)\
**Post date:** [June 24, 2025, 5:29pm UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/13 "2025-06-24T17:29:54Z")

</div>

If battery life is really important, note that the DS3231 runs on about 100uA when powered through its Vcc pin, but only about 3uA when powered through its Vbat. So you may want to just let it run all the time on its coin cell, except you would need to turn on Vcc to supply the I2C pullups when communicating with the RTC.

But there is a complication in that the ZS-042 also has a pullup resistor on the SQW pin which is connected to the Vcc header. If you're running on the coin cell you would need to disconnect that pullup and instead use a GPIO internal pullup or an external pullup. You can do that by cutting a trace:

 ![Disable INTSQW pullup resistor](https://europe1.discourse-cdn.com/arduino/original/4X/7/9/c/79c0461827e6dea2776f20893c8e325250f6eed6.jpeg)

An alternative is to rewire the module so the Vcc header feeds the Vbat pin instead of the Vcc pin. Ed Mallon has an excellent video on this option.

[https://www.youtube.com/watch?v=rG50U6bQhYo](https://www.youtube.com/watch?v=rG50U6bQhYo)

---

<div class="post-metadata">

**Author:** ![Nick\_Pyner](https://avatars.discourse-cdn.com/v4/letter/n/e8c25b/32.png) [@Nick\_Pyner](https://forum.arduino.cc/u/Nick_Pyner)\
**Post date:** [June 25, 2025, 6:14am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/14 "2025-06-25T06:14:37Z")

</div>

Ah.Yes.I have seen similar stuff [here](https://www.eevblog.com/forum/projects/surprising-power-reduction-mods-for-ds3231-rtc-in-zs-042-module/)  
I'm not so keen on doing that sort of thing at my age. Besides, it is already on the PCB - jam side down. I would rather look at recharging the 18650 on the fly, but I will defer that until it is clear that I need it.  
Controlling the LCD backlight is of more immediate interest.

---

<div class="post-metadata">

**Author:** ![ShermanP](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@ShermanP](https://forum.arduino.cc/u/ShermanP)\
**Post date:** [June 25, 2025, 2:37pm UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/15 "2025-06-25T14:37:43Z")

</div>

Yes, the backlight will be pretty expensive current-wise. But I also wonder about the processor itself. Is it running only to display the countdown? Does the countdown always need to be visible? At a distance, or could you push a button when you need to see it?

---

<div class="post-metadata">

**Author:** ![Nick\_Pyner](https://avatars.discourse-cdn.com/v4/letter/n/e8c25b/32.png) [@Nick\_Pyner](https://forum.arduino.cc/u/Nick_Pyner)\
**Post date:** [June 26, 2025, 12:21am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/16 "2025-06-26T00:21:21Z")

</div>

I believe there is about 100mA in the backlight and the LCD is hardly needed. Indeed it is so bright it is probably a bloody liability. The actual countdown is on 20mm leds under 7219,and I expect them to run pretty dim.

---

<div class="post-metadata">

**Author:** ![Nick\_Pyner](https://avatars.discourse-cdn.com/v4/letter/n/e8c25b/32.png) [@Nick\_Pyner](https://forum.arduino.cc/u/Nick_Pyner)\
**Post date:** [August 9, 2025, 5:54am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/17 "2025-08-09T05:54:35Z")

</div>

> [@david\_2018](#):
>
> What is it about controlling the SQW output that prevents you from writing your own code?

Simply the lack of expertise, which has now been acquired - after considerable internet trawling.

[ZS-042 DS3231 RTC module](https://forum.arduino.cc/t/zs-042-ds3231-rtc-module/268862)? post#9

It’s been amazing how difficult this has been to sort out, and/or how little attention the SQW pin gets.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [February 5, 2026, 5:54am UTC](https://forum.arduino.cc/t/adafruit-rtclib/1390381/18 "2026-02-05T05:54:52Z")

</div>

Closed on February 5, 2026, 5:54am UTC

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