3

I'm assembling a Smart Mirror for an applied project for college. This mirror has a Raspberry Pi 3 on the back. How this all started is that the campus' network blocks NTP, so we had to buy an RTC chip for the Pi to be able to keep track of time properly. We bought a DS3231.

So, I install the chip, install the i2c interface, and "sudo i2cdetect -y 1" let me know that the address of the DS3231 is "UU", at the 0x68 spot. I then tried various tutorials to try and get the Pi to take time from the RTC. I come to find out from reading this forum that a lot of the tutorials out there are inaccurate and contradictory, and that the only thing I should need to do is add the "dtoverlay=i2c-rtc,ds3231" line to /boot/config.txt. However, I had already screwed up the Pi beyond repair at this point, so I just re-installed Raspbian to a spare SD card I had lying around, and tried the one-step solution on this new installation.

It seemed to work. I used NTP (at home) to sync the system time, then wrote that time to the DS3231. I disabled NTP at startup with the "sudo update-rc.d ntp disable" command, and disabled Wi-Fi before power-down. I unplugged the power to the Pi and let it sit for about 5 minutes and then turned it back on. The Pi had the proper system time, and the RTC had the same time as well. Since I disabled NTP at startup, it would seem that the system is getting its time from the RTC. Awesome. Or......

The guy I'm working with said I should shut it off and let it sit for about an hour and then turn it back on. So I did. The system time was about 40 minutes behind where it should have been, and the RTC time was set to 1999. It seems that the RTC isn't storing time for extended periods of time. Is there any specific steps I should take to get it to store time properly?

UPDATE: The DS3231 is not not keeping time after shut down of ANY period of time. I just did a shutdown and turned the Pi back on after only 10 seconds, and "sudo hwclock -r" showed the DS3231 clock at 1999.

flemingmirror
  • 31
  • 1
  • 3

1 Answers1

2

Same problem occured a year+ ago for me, here is the reason: most modules are 5V tolerant for a RTC chip, but the battery charger is strictly 3.3V! So if you power it on 5V - it will start choking battery with 5V(checked it with my multimeter) - and it dies. Use strictly 3.3V and check your battery - one of my modules had a faulty one, I've replaced it and it's still ok for 1year+, another module has a badly inserted one, but the battery was good - it just loosed it's contact sometimes: I just removed it and replugged it firmly - and it's OK still too, for 1year+ time.

Alexey Vesnin
  • 926
  • 9
  • 16
  • Interesting, that might be the problem. I used this as the guide for where to plug in the RTC chip:

    https://thepihut.com/blogs/raspberry-pi-tutorials/17209332-adding-a-real-time-clock-to-your-raspberry-pi

    – flemingmirror Mar 02 '17 at 18:03
  • can you send a pic of your module(s) ? – Alexey Vesnin Mar 02 '17 at 18:04
  • My images won't link for some reason, so here's the Imgur URL:

    http://imgur.com/a/lTBkl

    Also, according the the GPIO pin-out, it seems that I had the RTC plugged into the 3.3v pin, so I don't think that this is the problem.

    – flemingmirror Mar 02 '17 at 18:19
  • these ones are having one more "problem" - the chip on top seems to attract the statics to itself from all the surroundings and it flushes itself on. Battery issue is applicable too - my friend used to experience it. You better use the ones looking like this(I'm using it) - https://potentiallabs.com/cart/image/cache/catalog/New%20Components/ds3231%20rtc%20module-500x416.jpg - and it's a glitch-proof, only replug the battery before starting and check the battery itself. – Alexey Vesnin Mar 02 '17 at 18:23
  • 1
    Is there a version that has GPIO headers installed? – flemingmirror Mar 02 '17 at 18:25
  • you mean soldered to the board itself? I haven't seen it, but you can easy mount them yourself using a part connector. – Alexey Vesnin Mar 02 '17 at 18:27
  • Yes, there is a version with GPIO headers. Several varieties, available on Amazon. One of them (Sparkfun, I think) takes up two rows so extends up the voltages and ground. The others only take up the top few pins of tthe inside row. They are less than $10 for 5x on Amazon Prime. I have them on order but dont yet have a handle on the software required to have it hold time during power outages. I'd be willing to bet Joan's pigpio site has the code I'll need when it gets here. You can find them with this search: https://www.google.com/search?q=amazon+rapberry+pi+rtc+module – SDsolar Jun 23 '17 at 08:21
  • Of course, you will always want to make sure you have accurate time from the Stratum-1 Master clock at time.nist.gov - Here is the procedure to make Raspian and ubuntu use it: https://raspberrypi.stackexchange.com/questions/68811/how-do-i-set-raspbian-to-use-the-primary-time-server-time-nist-gov? - and forget these Stratum-16 pools that come installed by default on Raspbian, ubuntu and all flavors of Windows. They're a crapshoot. time.nist.gov is the real McCoy. – SDsolar Jun 23 '17 at 08:32
  • well, the Linux kernel itself has a pre-installed modules, they are in kernel. You need just to enable them in your rc.local and load time from the hardware clock at the same place. if you wish it to be a systemd-launched, then you can utilize the dependencies and run it the very first, so even syslog entries will be at the accurate time, because the syslog daemon will be launched after – Alexey Vesnin Jun 23 '17 at 21:11