http://www.banggood.com/RTC-Real-Time-Clock-Module-For-Raspberry-Pi-p-965976.html
There is no schematic or any further details, also there is no markings on the RTC module to indicate even which pin is positive. I found the following image on the internet showing the GPIO header pinout:

I took a guess that I should connect it to point 01, 03, 05, 07, 09. This is the inner most set of connectors. Then I carried on with a guide that I had found online. Luckily my guess was correct. There are no other pins on the GPIO header with an I2C label, but I was mostly concerned about the power connections - if connected the wrong way with 3.3V the wrong way across the battery it could cause some damage. Anyway, luck was on my side and it seemed to all work fine. So on to the software setup.
The first thing to do is to enable I2C in the raspi-config tool. To do this, open the configuration tool:
sudo raspi-config
Go in "Advanced Options" > "I2C" > "Yes"
When asked if the default module should be loaded by default, select "Yes", and then reboot the raspberry pi.
Then I followed steps from here: http://www.drewkeller.com/blog/adding-hardware-clock-raspberry-pi-ds3231
# Comment out the blacklist entry so the module can be loaded on boot
sudo sed -i 's/blacklist i2c-bcm2708/#blacklist i2c-bcm2708/' /etc/modprobe.d/raspi-blacklist.conf
# Load the module now
sudo modprobe i2c-bcm2708
# Notify Linux of the Dallas RTC device (use -0 for Model A or -1 for Model B)
echo ds3231 0x68 | sudo tee /sys/class/i2c-adapter/i2c-1/new_device
# Test whether Linux can see our RTC module.
sudo hwclock
The response was the time that the RTC thought it was, which hadn't yet been set. If you get this, then that looks good ad the hardware aspect is correctly connected and working.
The raspberry pi was connected to the internet and got the time and date automatically, as can be checked by the "date" command.
If the date is wrong, this can be set with the following command:
sudo date -s "Jan 27 2016 12:41:01"
I have previously had some problems when setting the time and date together, and found I had better luck setting first the date, and then the time, rather than both together in the same command. I think this was due to problems with the formatting, but this method of splitting the time and date helped. Then write the current date and time to the RTC module using the following command:
sudo hwclock -w
Then edit the /etc/rc.local file with this command:
sudo nano /etc/rc.local
and add the following two lines before the line "exit 0":
echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
hwclock -s
Now disable the fake hardware clock with the following line:
sudo update-rc.d fake-hwclock disable
The network time can also be disabled, but I wanted to leave this in place. To disable this, use the following command:
sudo update-rc.d ntp disable
But if it is left in place, then the clock should be updated each time that the raspberry pi connects to the internet, but will keep time when powered off, and when rebooted without power.
Hi Rob, may I ask which pins correspond to what connection on the sku193431 side? I assume there's 3.3V, GND, SDA and SCL but just don't know what order they're in on the board.
ReplyDelete