DS3231 RTC: freezes all the time

Hello,

I am trying to wire a DS3231 real time clock (labelled as ZS-042) using an arduino Nano v3 (ATmega328).

The thing is, I tried a couple libraries and even if the code seems so simple, they don't work.

For instance, I followed this tutorial that used the library made by Rinky-Dink Electronics, and when I run it, the arduino nano just freezes. It seems that the piece of code that trigers the crash is: Serial.print(rtc.getDOWStr()); Anything below that won't be processed.

And well, other examples just have a similar fate: they either freeze the nano or show up a wrong date.

Since this RTC uses an I2C interface, I tried a "i2c scanner" script, which correctly detected the attached device:

I2C scanner. Scanning ...
Found address: 79 (0x4F)
Found address: 87 (0x57)
Done.
Found 2 device(s).

So I'm pretty sure the RTC is wired correctly (using the A4 and A5 for SDA and SCL, and 5v and GND for power and ground), but for some reason, it doesn't work at all. I even tried with another arduino nano, just in case.

What's going on? Is my RTC module faulty? Is there any way to test that?

Thanks in advance.

EDIT: Btw, when I used the rtc.getData(); command, I always obtain 2165-165-165 45:165:85 as a result.

Since this RTC uses an I2C interface, I tried a "i2c scanner" script, which correctly detected the attached device:

Why does the scanner see two I2C devices when the RTC is connected? Do you have another O2C device connected, too?

If so, have you tried running the scanner and sketch (that you don't post) without the other device connected?

No, there was only the RTC connected at that time. If I unplugged the SDA or SCL (or both), it would show 0 devices found.

wonx:
What's going on? Is my RTC module faulty?

Probably not, but there is quite a lot to suggest your I2C scanner is. What you might do is throw all caution to the winds, ditch the scanner, and simply define the address as 0x68 like everybody else does.

I submit the next thing to do is get some better information. I have never heard yet of an Instructable that is any good, and just reading the first two sentences of this one is a clear enough signal that the guy doesn't know what he is doing, although I can't imagine Henning Karlsen doing anything dodgy.

This is the most sensible tutorial I have found. It doesn't use a library. You may find you need to use a library if you want to do some sophisticated alarm stuff etc., but this will get you started. Note that there are two programmes, one to set the time, and one to use it. It also uses less memory than any other method I know of, but I don't know why.

I assume you are feeding ZS-042 with 5v and a Nano should be able to run it just like any other Arduino. All you need to know is which are the pins for SDA/SCL.

SDA and SCL need 4.7k pullup resistors. Add them and then try the I2C scanner again. Until you get the scanner to report that it sees address 0x68 you haven't got the thing wired correctly. The fact that you read the time as "2165-165-165 45:165:85" also indicates that the RTC is not wired correctly.

Pete

I tried the scripts in the tutorial with no success. All I see on the serial monitor is 165/165/165 45:165:165 over and over again. I'm not able to reset the time or show any time at all.

In the arduino nano v3, the SDA port is the A4 and the SCL port is the A5. I'm powering the board via a microusb cable connected to my laptop.

el_supremo, I tried putting a 5k resistor between the SDA pin and another one for the SCL. The scanner keeps saying "Found 0 device(s)".

EDIT: I kept trying with resistors. a 5K resistor between the 5v and the VCC is not enough to power the RTC. I also tried a 330 and 200 Ohm resistors that I had at hand, and the addresses were the same I got before (79 and 87).

What we need is a clear photograph showing the connections of the RTC to the Nano. Or a circuit diagram.

Pete

Sure, here it is:


I tried to create a Fritzing diagram but I couldn't find that part. There's nothing else connected in there.

Please, tell me I made a stupid error like connecting something backwards or sth like that, and I can forget about this :slight_smile:

You haven't got the pullups resistors. You need 4.7k from SDA to 5V and 4.7k from SCL to 5V.
Don't bother with fritzing. Your photos are clear enough.

Pete

I used 5k resistors because I don't have any 4.7k left. Anyway, same result, the "scanner" detects two addresses, just like before.

Btw, according to adafruit, this RTC already has some pullup resistors between SDA & SCL and VIN, although it's not exactly the same model.

I keep thinking mine is just broken. It's apparently a pretty simple device.

I forgot that I have an RTC exactly like that one and it does indeed have the 4.7k pullup resistors onboard - so you don't need more pullups.

I wired it up just like yours and the I2C scanner finds it at address 0x68.

Check that the backup battery has a reasonable voltage. If it doesn't, remove it and try without.

Pete

wonx:
I keep thinking mine is just broken.

You don't hear of them breaking and I submit you should blame yourself before you blame the 3231.

The 2165-165-165 45:165:85 may suggest wiring, but I think it definitely suggests inadequate power. There is also the power LED on the bottom. If that is out, you have no power, but if it is on, you may still have inadeqaute power.

Update. I removed the battery. It's a CR 2032, apparently rated 3v (that's what's written on it), but according to my multimeter, it only provides 1.25v, so it's probably dead (they're not rechargeable, right?).

Anyway, ran the i2c scanner with the battery removed, and the results are identical: 2 devices found, at the addresses 79 & 87.

The power led is always on (red), either with or without the battery, when the vcc and gnd cables are connected.

So, is it possible that it's all the battery's fault, and when I plug a new one it starts working automagically? Any way to test that without buying a new one? Any other recommendations for cheap RTCs on ebay :sweat_smile: ?

I've bought some from here. Only problem I've had is that sometimes the battery doesn't last as long as I'd expect.

If you remove the battery, the RTC should still work while it is plugged in but it will, of course, have to be reset after it is powered off. CR2032 are not rechargeable.

I'm guessing that you've got a dud (or perhaps you blew it up and didn't realize it).

Pete

You see two addresses, because that RTC board also has an EEPROM memory chip on it.

Some useful modifications to the board are described here. Using a $1 DS3231 Real-time Clock Module with Arduino | Underwater Arduino Data Loggers

wonx:
Update. I removed the battery. It's a CR 2032, apparently rated 3v (that's what's written on it), but according to my multimeter, it only provides 1.25v, so it's probably dead (they're not rechargeable, right?).

That's a surprise. I thought this battery stuff was confined to DS1307. My ZS-042s all use an LIR2032 3.6v and I understand is rechargeable

@jremington: The EEPROM explains the 0x57 address, but the DS3231 should be 0x68, not 0x4F.

Pete

DS3231 should be 0x68, not 0x4F.

Maybe the "DS3231" chip is something else, or a fake.

Wow, thanks everyone with the help. I'm not skilled enough to try these modifications. I just want to make a component work as expected like the rest of stuff I plug in my arduinos. I'll buy a couple RTCs more and see what happens.

Again, thanks!

According to the LadyAda list here, the I2C address 0x4F is PCA9685 which is a 16-channel, 12-bit PWM Fm+ I2C-bus LED controller.

You wouldn't happen to have one of those accidently lying around on your I2C bus? :slight_smile:

Pete