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.

dda
  • 1,595
  • 1
  • 12
  • 17
Zelkins
  • 135
  • 1
  • 6

3 Answers3

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.

dda
  • 1,595
  • 1
  • 12
  • 17
SDsolar
  • 1,175
  • 3
  • 11
  • 35
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

gre_gor
  • 1,682
  • 4
  • 18
  • 28
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.

dda
  • 1,595
  • 1
  • 12
  • 17
dannyf
  • 2,813
  • 11
  • 13