3

I recently bought a DS3231 RTC, but I cannot seem to figure out how to get it to work. I have tried all different tutorials and example programs but I keep getting 2165.25.165 165:165:165 as the output.

I am using an Arduino Micro, with the RTC connected as follows:

  • GND > GND
  • VCC > 5V
  • SDA > A4
  • SCL > A5

Project details:

The project uses a 16x2 LCD to display the time of day, and a countdown to the next occurrence of 06:00. Then at 6 it will allow for a button to be pressed to open a servo and do other things. I got temporary test code to work using millis(), but it is only displaying a 12-hour countdown in seconds, and I would like to replace it with a more reliable RTC.

  • 3
    Nostradamus says the problem is with your code, but his crystal ball is a little cloudy at the moment. – Milliways Jan 29 '17 at 3:05
  • 2
    Every time I got this 165:165:165 from an RTC, it turned out the RTC wasn't online -- either not powered, or not on the I2C bus for some reason. – dda Jan 29 '17 at 4:44
  • 2
    Usual questions on wiring of an I2C device: do you use pullup resistors on SDA and SCL signals? Note that some circuits may already integrate these, but it is hard to say without knowing the exact circuit (you provided the chip name but you probably have some breakout from Adafruit, Sparkfun... with additional components) – jfpoilpret Jan 29 '17 at 7:24
  • BTW if you want some logic to be executed at certain times, it is better to program RTC to generate alarm interrupt and process external interrupt on MCU. This way no constant polling will be needed on MCU. – Flanker Jan 31 '17 at 5:17
  • Sililar to arduino.stackexchange.com/questions/30638/… – SDsolar May 7 '17 at 21:02
3

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 reference:

enter image description here

5

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 properly communicating with the RTC. If the RTC's red light is on then check your wiring and make sure you haven't reversed SDA and SCL.

Also, the DS3231 has and most Arduinos have enough pull-up that you won't need external pull-up resistors in order to communicate directly with the DS3231.

Try plugging it straight into the Arduino - go minimalist and make that work before adding other devices to the I2C bus like a LCD display. Set the clock by code and watch it in the serial monitor.

Once you're sure the RTC is not a problem then you can go from there with the I2C bus. It is certainly possible for other devices on the bus to cause the RTC to be unable to respond correctly. For a short-range I2C bus that includes the DS3231 don't add any external pullups.

The most reliable RTC for Arduino is the DS3231, but if you bought it via the slow boat you might try a voltmeter to verify the battery so it keeps time even when powered down.

And of course, it is only as accurate as you program it to be. When I program my DS3231s, I always add a couple of minutes to the current time to allow for the time to fix forgotten semicolons and such before it gets around to actually programming the device.

One last note: The program will run when you open the serial monitor. So that will be when it sets the time then begins to display it.

  • I forgot to add that the DS3231 can set alarms that trigger software interrupts. Look up the data sheets and you'll find out how. Here is a library that makes it easy to control them: github.com/rodan/ds3231 – SDsolar Jan 30 '17 at 1:37
1

Your question doesn't match your title so I will go with your title.

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

The typical approach is to set an alarm on the RTC (to the extent that it supports it), and process that interrupt from the RTC on the MCU side.

Alternatively, you can poll the time on the RTC periodically and once the time is up, do your thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.