Skip to main content
Share Your Experience: Take the 2024 Developer Survey
7 votes

Convert to and from Unix Timestamp

I think that the two most used libraries are the Adafruit RTClib and the pjrc.com TimeLib. They both have functions to convert the epoch, and they both are reliable. But both lack the timezone and the ...
Jot's user avatar
  • 3,246
6 votes
Accepted

How to run a timer every 12 hours (exceeding the max size of int) without an RTC?

Set the timer for every hour, which is within the limit. In your action, keep a static int, initialized to zero, which you increment each time. When it ==12, do the thing you want to do and reset your ...
Mark Smith's user avatar
  • 2,181
5 votes

How to have some code executed at a certain time of day with a DS3231 RTC?

If you are getting 165:165:165 that indicates usually a problem with your I2C bus. But it might also be a power problem in the RTC. In any case, check your wiring. Your processor is simply not ...
SDsolar's user avatar
  • 1,165
5 votes

How to run a timer every 12 hours (exceeding the max size of int) without an RTC?

I'm running into an issue because it takes milliseconds as an int ... No it doesn't. Look at the function prototype: int setInterval(long d, timer_callback f); Call function f every d ...
Nick Gammon's user avatar
  • 38.3k
5 votes
Accepted

Why the unsigned long is overflowing?

It's not the unsigned long that's overflowing but the calculation that you're assigning to it. 3600 is a signed integer (by default), and now.hour() is an unsigned byte. The unsigned byte gets ...
Majenko's user avatar
  • 105k
4 votes
Accepted

How to set up one second interrupt/ISR for ds3231 RTC

This answer addresses the original question of why the interrupts didn't work. I happened to have a DS3231 lying around so I made up a test. Interrupt vs pin number First, this is wrong in your code:...
Nick Gammon's user avatar
  • 38.3k
4 votes

My RTC is returning a sporadic date/time

The RTC library does not check for communications success. In particular, here: DateTime RTC_DS1307::now() { Wire.beginTransmission(DS1307_ADDRESS); Wire.send((byte) 0); Wire.endTransmission(); ...
Nick Gammon's user avatar
  • 38.3k
4 votes

How to get current Date

An example how to use NTPClient is available at the projects github #include <NTPClient.h> // change next line to use with another board/shield #include <ESP8266WiFi.h> //#include <...
Filip Franik's user avatar
  • 1,292
4 votes
Accepted

Arduino program using i2c stops working after printing to OLED a few times

This is wrong in many ways: String input = Serial.readString(); serialInputBuffer = new char[input.length()]; input.toCharArray(serialInputBuffer, input.length()); What's fatal is that you later don'...
Juraj's user avatar
  • 18k
4 votes

How to convert my Arduino setup to a PIC setup?

The PIC32 has full (or nearly full) support for the Arduino API through the chipKIT project. If you want to use one of the smaller PIC chips (PIC16 / PIC18 etc) then you're out of luck. There just ...
Majenko's user avatar
  • 105k
3 votes

Creating a timer using a Real Time Clock with start and stop times

Gerben, thanks for your code. I took it and added seconds to the check, and tidied up a few typos. This isn't as sophisticated as other methods, but might be good for beginners to follow logic. hope ...
kadlugan's user avatar
3 votes
Accepted

How to improve date-time control from RTC?

Is there a simple way to convert to date-time object? Not with this library. But you can find other libraries supporting the DS3232 which work with the Arduino Time library[]. This time library ...
Edgar Bonet's user avatar
  • 43.3k
3 votes
Accepted

Please explain this adafruit image for connecting a DS1307 RTC

It's written in the tutorial If you set analog pin 3 (digital 17) to an OUTPUT and HIGH and analog pin 2 (digital 16) to an OUTPUT and LOW you can power the RTC directly from the pins!
Gerben's user avatar
  • 11.3k
3 votes
Accepted

How to have some code executed at a certain time of day with a DS3231 RTC?

SDA and SDL pins on an Arduino Micro are on pins D2 and D3 as mentioned on the official page: TWI: 2 (SDA) and 3 (SCL). Support TWI communication using the Wire library. and shown on this pinout ...
gre_gor's user avatar
  • 1,682
3 votes

DS1307RTC Outputting cryptic 165/165/2165 date. What are some possible fixes?

Had the same issue, however, my RTC was 1302 (not 1307) and yours seems to be as well, please check. If it's 1302, use this library: https://github.com/msparks/arduino-ds1302 Also, make sure you ...
Kostyantyn's user avatar
3 votes
Accepted

Problem on Arduino Interrupt and RTC

Well, for example Arduino's delay needs interrupts to be working and as you may not know it's disabled inside of ISR handler. Never ever use anything like while (1), delay(1000) and so on inside of ...
KIIV's user avatar
  • 4,752
3 votes
Accepted

Calculate absolute time based on cycles and RTC

In general, the idea is sound. But there are problems with some of the details and tuning. The most important detail: Use the correct data type for storing and computing with time variables (like ...
James Waldby - jwpat7's user avatar
3 votes

Simulating a real time clock module with software

how do i replace [an RTC] chip with software? You can't. An RTC is made of basically two things: a carefully trimmed crystal oscillator that has a very stable and well calibrated frequency some ...
Edgar Bonet's user avatar
  • 43.3k
3 votes
Accepted

How to manage two alarms with one interrupt?

Consider it is good practice to leave as little code in an interrupt as possible. In this case, as the time in question is much greater then how often the loop() function is called, setting a single ...
st2000's user avatar
  • 7,338
3 votes
Accepted

displaying a 3 digit clock time on a 4 digit 7 segment display

I tested your first code line and it outputs a right aligned 136 without colon at my display. (Said I have only a colon at the middle and no decimal points) The 5 at the fist digit (and also the A at ...
chrisl's user avatar
  • 16.3k
3 votes
Accepted

DS3231 rtc.begin() always returning false

No fault is there in code. Rather, it was an faulty connection which prevented RTC module from working. Now, after restoration, the RTC module is working fine.
Sashi Kant's user avatar
3 votes

Arduino Time Library and RTC Libraries

Let me first give some background about these libraries. The Time library uses millis() for timekeeping. Since this can be subject to significant drift, it provides a means to periodically sync to an ...
Edgar Bonet's user avatar
  • 43.3k
3 votes
Accepted

RTClib now() within while loop does not update

See the documentation of DateTime::toString(): The buffer parameter should be initialized by the caller with a string specifying the requested format. This format string may contain any of the ...
Edgar Bonet's user avatar
  • 43.3k
3 votes
Accepted

DS1337 with shared I2C pull-up

You need at least one pull-up on the SDA pin and at least one pull-up on the SCL pin. You cannot use the same pull-up for both pins as you will be shorting the two pins together. The pull-ups are ...
Majenko's user avatar
  • 105k
3 votes
Accepted

using RTC for storage

Some RTC chips contain a small amount of battery-backed SRAM ("NVRAM" - Non-Volatile RAM) which you can use for whatever you like. This is just ordinary RAM which is powered by the small ...
Majenko's user avatar
  • 105k
3 votes
Accepted

is there Raw RTC output?

The DS3231 doesn't report the Unix time. It reports the current time in broken-down form (year, month... second). If you need Unix time, you have to compute it. I suggest using Adafruit's RTClib. This ...
Edgar Bonet's user avatar
  • 43.3k
3 votes

DS3231 not keeping time when Arduino is turned off

rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); You have this line in setup that sets the date and time to the date and time that the code was compiled. That's fine to set it once, but that time ...
Delta_G's user avatar
  • 3,324
2 votes

How to improve date-time control from RTC?

I hope I am allowed to summarise progress. Edgar Bonet's answer above pointed me in the right direction regarding date-time format and I want to 'accept' that answer, although it did not resolve my ...
jules's user avatar
  • 75
2 votes
Accepted

Piezo connection causing RTC to go haywire

Add pinMode(TONE,OUTPUT); to setup() to fix the problem.
evolutionizer's user avatar
2 votes
Accepted

Using two digits to display a number using TM1637 and a 4-digit display

Using tm1637.display(digit#, value); calls, you can display a two-digit number using division to isolate the tens digit and mod to isolate the units digit. For example, if hour and mins have hour and ...
James Waldby - jwpat7's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible