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.
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.
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).
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 ?
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).
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
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.