HOW TO Install a ChronoDot Real Time Clock (RTC) on Slackware ARM on a Raspberry Pi
This project would suit those who do not wish to depend on NTP servers for time information, or where no Internet connection is available, and accurate time is a factor. There may be other reasons why you might want to rely on an onboard RTC for time keeping purposes but, alas, the Raspberry Pi doesn't come with one. So we thought it would be cool and interesting, as well as good fun, to give our Slackware ARM Linux system a real time clock (RTC) module. For this project we used a Raspberry Pi model B 512Mb rev.2 (Made in China).
What you will need for this project
• Your Raspberry Pi running Slackware ARM 14.1, or 14.0 Linux
• A ChronoDot Real Time Clock (RTC) module and suitable cables to connect it to your Raspberry Pi.
• The i2c-tools Slackware ARM package - i2c-tools-3.1.0-arm-1_SBo_fd.tgz [MD5]
Connecting the ChronoDot RTC module to your Raspberry Pi
With everything powered off, follow the diagram below and connect the ChronoDot to your Raspberry Pi GPIO header. One easy way to do this is by using solderless female-female breadboard jumper cables which simply "plug-in". You can of course make your own connections and cables by using old CD/DVD ROM audio cables, etc. The only important thing is that you ensure the wiring is correct and insulated.
• ChronoDot VCC Raspberry Pi GPIO Pin 1 (3v3)
• ChronoDot SDA Raspberry Pi GPIO Pin 3 (SDA)
• ChronoDot SCL Raspberry Pi GPIO Pin 5 (SCL)
• ChronoDot GND Raspberry Pi GPIO Pin 9 (Ground) - can also be connected to GPIO Pin 6 (Ground)
Connect the 3v Lithium CR1632 coin cell battery to the ChronoDot RTC (which comes supplied). Make sure the polarity is correct! Do a final check of the connections between the ChronoDot and your Raspberry Pi, just to be sure.
Now you can power on your Raspberry Pi and boot into your Slackware ARM Linux operating system.
Once you have booted to the login prompt you should login as 'root' user. If the date is not already set to current time you should now set it manually, or use the 'ntpdate' command. It's a good idea to make sure your Slackware ARM software and Raspberry Pi kernel and firmware are fully up to date. Running slackpkg and rpi-update at this point will achieve this and, depending on the number of updates available, may take a while to complete. A reboot may also be required.
Installing & configuring the ChronoDot RTC on Slackware ARM
root@myrasbox:/tmp# wget http://rpi.fatdog.eu/files/pkg/i2c-tools-3.1.0-arm-1_SBo_fd.tgz
You may also want to verify the file's integrity with the MD5 checksum: 9b8bacd037cc7e49e9b7de68db966f7c
Or download the file:
Next you're going to install the i2c-tools package. This software contains a diverse set of I2C tools for your Slackware ARM Linux system: a bus probing tool, a chip dumper, register-level SMBus access helpers, EEPROM decoding scripts, EEPROM programming tools, and a python module for SMBus access. Type the following command to install it:
Once this has completed you should see the following output.
After installing the i2c-tools package, you're going to edit the rc.local file and instruct the Slackware ARM system to load the required modules and perform commands at boot time in order to communicate with the ChronoDot RTC. Do this with 'nano' by typing:
You will hopefully see something similar to the screenshot below.
You need to tell the system to load some specific modules. These will be explained later. Enter the following code into the rc.local file below any existing text:
Pay attention to the next section because it is important. Whether you are using a Raspberry Pi rev.1 or rev.2 depends on the code you need to enter and this is crucial towards success. If you're not sure which revision you're currently using it's easy to check which Raspberry Pi board revision you have from this link.
• For Raspberry Pi rev.1 boards you need to enter the following code into the rc.local file below the text you have just entered:
• For Raspberry Pi rev.2 boards you need to enter the following code into the rc.local file below the text you have just entered:
The last thing you need to do before saving the rc.local file is to comment out the sntp line by putting a #hash in front of it. This stops the system from attempting to grab the date from a NTP server over the Internet at boot time. It would be a little pointless to have our system get a time reference from a NTP server when there's a highly accurate ChronoDot RTC available! :-D
Now you should have a rc.local file looking very similar to the one below.
Once you've finished editing the rc.local file press CTRL+X keys to exit, press "Y" (yes) when asked if you wish to save any changes and then press Enter to save the file.
The 'echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device' command is telling the i2c subsystem that there's a new 'ds3231' device available (the ChronoDot) and where it is on the bus. It's worth noting that this command only works the first time you use it. Any repeated usage will result in an error message.
The '/sbin/hwclock -s' command is asking the real time clock (the ChronoDot) for a time reference and subsequently writing that date and time to the Slackware ARM Linux system.
It's time to get it all working
So now your rc.local file should be configured to initialise the ChronoDot RTC and use it at boot time. You could 'reboot' at this point to test your setup but there's no real need to do so.
Instead of rebooting your Raspberry Pi, you can simply run the rc.local file to load the modules and perform the commands required to get the ChronoDot RTC working with the system. Type the following code to run the rc.local file:
After running the rc.local file you need to make sure the ChronoDot RTC is being recognised by the system and, most importantly, set the correct time and date on it. So, depending on whether your Raspberry Pi is a rev.1 or rev.2 board (check it with this link), type the following:
• For Raspberry Pi rev.1 boards use this command:
• For Raspberry Pi rev.2 boards use this command:
The screenshot below is the result you're looking for. It shows that the device has been detected and recognised.
So you can go right ahead and find out what time and date is set to on your ChronoDot RTC. If this is the first time you have used it don't expect the current settings to be anywhere near accurate. Type the following command:
The result should be something similar to what you see below. Notice that in our screenshot the current date and time is years out on the ChronoDot. Yours may also be the same. However, this is just a transient error because it's the first time the ChronoDot RTC has been powered on. ;-)
Setting the ChronoDot RTC to the correct time & date
This can be achieved in two ways: manually using the 'date' command, or by utilising a NTP server on the Internet with the 'ntpdate' command. The latter is preferred for accuracy reasons alone.
• Set the time and date on the ChronoDot RTC manually by using the following command (pay attention to the date format):
The month (MM), day (DD), hour (HH), and minute (mm) values are always specified in 2 digits and have a leading zero '0' when applicable. The time is always specified as the 24 hour clock. The year (YYYY) value is always specified by 4 digits.
Example: if the time is 9:17am on August 14, 2013 then the command would be as follows:
• Set the time and date on the ChronoDot RTC using a NTP server with the following command:
NB: The above 'date' and/or 'ntpdate' command(s) can be used at any time (as 'root' user) to set the time & date on the ChronoDot RTC.
Now type 'hwclock -r' to see if you have successfully set the ChronoDot RTC to the correct date and time. You should check the output to make sure it's accurate.
countdown reboot? (optional)
As final confirmation that you've done everything right you can power off your Raspberry Pi (disconnecting any Ethernet cable or wireless Internet device) and power it back on, booting into your Slackware ARM Linux system. Once again, login as 'root' and type the 'hwclock -r' or 'date' command, or both. If the result is accurate to current time then it's perfect.
When we rebooted our Raspberry Pi, and disconnected it from any Internet connection, a few minutes later we logged in as 'root' and typed the following:
The section of output above from the 'dmesg' command tells us that the i2c modules have been loaded successfully and are working, and that our ChronoDot RTC (ds3231) has been recognised and is configured correctly for use by our Slackware ARM Linux system. We also checked that the date and time was still current and accurate by typing:
The date and time were spot on! If you found the same results, WELL DONE! 100% success. Happy days once again. :-D
Thank you for reading and/or taking part in this fun little project. We hope others find it as interesting and educational as we did.
Credits: a massive thank you to Phenoptix for selling us the awesome ChronoDot RTC v2.1, Matteo Bernardini for his i2c-tools.SlackBuild script which allowed us to build the i2c-tools-3.1.0-arm-1_SBo_fd.tgz Slackware ARM package and, as always, Stuart Winter for his ceaseless efforts towards Slackware ARM. Without you all this project would not have been successful, or even possible. <3