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?
Checking the source code for Adafruit RTClib shows that it incorporates another of Adafruit's libraries, which resumably includes Wire and perhaps others.
#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.
Thanks. I now recall previous comment to that effect. I will look elsewhere!
Hi @Nick_Pyner ,
You haven't specified which RTC you're using. Depending on the RTC chip you'll be using you'll have different libraries available.
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.//
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.
Do you want to use it for square waves or as an interrupt?
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.....
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.
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.
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.
Indeed...
And this is a battery powered project that uses stuff already to hand
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:
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.
Ah.Yes.I have seen similar stuff here
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.
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?
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.