SARPi Project - Slackware ARM on a Raspberry Pi


Install a [DS3231] Real Time Clock on a Raspberry Pi running Slackware ARM

This SARPi mini-project will enable you to connect and install a real time clock (RTC) using Slackware ARM on a Raspberry Pi. The 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 as standard. So we thought it would be cool and interesting, as well as educational and fun, to give our Slackware ARM system on a raspberry Pi its own RTC module. In this mini-project we'll be installing a ChronoDot [DS3231] RTC.

Although we'll be installing a DS3231-based RTC you can just about use the same procedure with any [I2C] RTC module; DS1302, DS1307, PCF8563, RV3028, etc. The only real difference are the modules used for each device. Sometimes they are the same drivers. Sometimes you need to locate and/or build your own.

What you will need for this project

• A Raspberry Pi with a 26 or 40-pin GPIO header running Slackware ARM Linux.
• A Real Time Clock module, such as ChronoDot RTC (or other DS3231/DS1307-based real time clock).
Suitable cables to connect the ChronoDot to your RPi (other RTCs may connect directly to the GPIO without cables).
• The i2c-tools package installed; i2c-tools-4.2-armv7-1_slack14.2_sp1.txz for Slackware ARM 14.2. Slackware ARM current now includes i2c-tools package in the source tree. You may use 'slackpkg' or manually download i2c-tools*.txz to install it.

Note for Slackware ARM packages: Make sure to only install package(s) for the Slackware ARM version you're running. Packages that are built for current hard float port will not work with 14.2 soft float port (and vice versa).

For quick reference within this RTC guide:
Installing a RTC on a Raspberry Pi
Configuring the Slackware ARM system for a RTC
Configuring Slackware ARM to use a RTC on a Raspberry Pi
Installing & configuring a RTC on Slackware ARM without Device Tree overlays (using I2C-Tools etc.)

Installing a RTC on a Raspberry Pi

First of all you're going to connect the ChronoDot RTC to your Raspberry Pi.

The RTC module we're using in this project is the ChronoDot v2.1 [DS3231SN]. Two reasons why we chose this particular RTC is because it has one of the best reputations for being high quality and an accurate timekeeper, and features a replaceable battery. Another consideration was because it's already supported by the rtc-ds1307 module under Slackware Linux. The ChronoDot's Maxim DS3231SN temperature compensated [TCXO] controller was also a major factor in selecting this RTC module over its DS1307, and alternative RTC contemporaries.

This guide also works for most other DS3231-based real time clocks, such as the extremely popular DS3231 MINI RTC Module which plugs directly in to the Raspberry Pi GPIO without the need for any cables. The RTC device may be different but the drivers/modules required to use it is exactly the same.

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". The cable length is your prerogative. 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.

Below is a diagram showing how you need to connect the RTC to the Raspberry Pi. The diagram shown is a 26-pin GPIO from the Raspberry Pi (1) Model B (rev.2). The first 26 pins of a 40-pin GPIO header on a later Raspbery Pi models are exactly the same as this older 26-pin version.

• 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)

NB: Make sure you connect the ChronoDot to the 3.3v power supply and NOT the 5v power. Although the ChronoDot is designed to operate on anywhere between 2.3v and 5.5v, on the Raspberry Pi we need to be powering it from the (3v3) 3.3 volts supply using GPIO Pin 1.

We're going to insert the 3v Lithium CR1632 coin cell battery to the ChronoDot RTC (which comes supplied). The RTC you have might be the same or come with the battery already soldered to the circuit board. Just make sure the polarity of the battery is correct if you do need to insert one. Connect the RTC cables to the GPIO header your Raspberry Pi (as shown above) and do a final check of the connections before powering it on, just to be sure. When you're satisfied it's all correct you can power on the Raspberry Pi and boot your Slackware ARM system.

Configuring the Slackware ARM system for a RTC

For the purpose of this guide we have given the name "koor" to our Slackware ARM system. It's a Raspberry Pi (1) Model B and we have pre-installed the i2c-tools-4.2-armv7-1_slack14.2_sp1.txz package for Slackware ARM 14.2.

Log in and change to the 'root' user. The first thing you're going to do is edit the '/boot/config.txt' file and add some settings to enable the I2C interface and instruct the system that you're are using a RTC (a.k.a the ChronoDot in our case). To do this you need to type 'nano -w /boot/config.txt' at the command prompt.

Scroll down to the section you see in the screenshot below, titled "Uncomment to enable the optional hardware interfaces".

As shown in the screenshot below;
• Remove the hash '#' from the beginning of the 'dtparam=i2c=on' line.
• Remove the hash '#' from the beginning of the 'dtoverlay=i2c-rtc,ds3231' line.

dtparam=i2c_arm=on
dtoverlay=i2c-rtc,ds3231

NB: If these lines do not already exist in your /boot/config.txt file then add them.

If you are installing a DS3231 or DS1307 RTC then the 'dtoverlay=i2c-rtc,ds3231' setting is the same for both. For other RTCs you are going to need to do some investigating to find out which module supports yours. For example, if your RTC is PCF8523-based then you would add this line instead:

dtoverlay=i2c-rtc,pcf8523

This line can be put anywhere in the '/boot/config.txt' file.

Now exit and save the /boot/config.txt file [CTRL+X].

Next thing to do is type 'reboot' at the command prompt and allow the system to restart. Then log in again.

Configuring Slackware ARM to use a RTC on a Raspberry Pi

Log in, elevate to 'root' user and at the command prompt type 'hwclock -r && date'. You should see something similar to the example screenshot below.

If you receive any error notifications go back and check your settings in the /boot/config.txt file. If you find any mistakes correct them and reboot your system once more. Your /boot/config.txt file should pretty much match what's displayed in this guide in order to work successfully. Also check the cable connections between the RTC and Raspberry Pi.

As you can see from our example, the system time and ChronoDot RTC are not in sync. The first output is the hardware clock (the ChronoDot RTC) and beneath it is the output from the system date/time. Your own results will be completely different but the point is to check if the system time and hardware clock are accurate. For us they are not. For you they might be too, especially if you are configuring the RTC for the first time.

So now we need to accurately set the system and hardware clock date/time and we're going to use a ntp server to achieve this. You are probably going to need to do the same and if you want to use a ntp server you will require an internet connection.

If you don't have an internet connection you can set the system time by using the 'date MMDDHHmmYYYY.SS' command.
MM = 2 digit month (00-12)
DD = 2 digit date (01-31)
HH = 2 digit hours (00-23) [24 hour format]
mm = 2 digit minutes (00-59)
YYYY = 4 digit year
SS = 2 digit seconds (00-59)

So, for example, 07:44:13 PM on 09 April 2016 would be: 'date 040919442016.13'

Incidentally, you can also set the date/time from a ntp server connected to your local network if you have one available.

So, to set the system date/time you'll use the 'sntp' command, followed by a ntp server address. The ntp server we are using as an example is 'pool.ntp.org' but you can select your own here if you prefer. To set the hardware clock date/time you can get it from the system once you know it is relatively accurate. You can achieve this with one simple command.

At the command prompt type: 'sntp -sS pool.ntp.org && hwclock -w'

What you've effectively done is set the system date/time with the 'sntp -sS pool.ntp.org' part of this command and subsequently taken that setting and written it to the hardware clock (ChronoDot RTC) with the 'hwclock -w' part of this command.

Now you can use the 'hwclock -r && date' command again to check that the system and hardware clock date/time matches.

If the output of the system date/time and hardware clock date/time are identical then you have successfully installed and configured the RTC on your Slackware ARM system. Well done!

Seeing as you now have a fully working and installed, highly accurate, real time clock there's no need to rely on a ntp server at boot time. You can configure the system so that the date/time is set by the hardware clock (i.e. the ChronoDot RTC). Type the following command:

root@koor:~# nano -w /etc/rc.d/rc.local

Your /etc/rc.d/rc.local file should look like the screenshot below.

This file grabs the date/time from a ntp server at boot time. You can easily change it so that the system date/time is set by your RTC instead.

All you need to do is comment out the 'sntp -sS' line (i.e. put a hash '#' at the start of the line) so it doesn't run the command and then put 'hwclock -s' on a line by itself at the end of the /etc/rc.d/rc.local file. In the example below we have done just that, and also added a comment for our own reference.

Exit and save the /etc/rc.d/rc.local file ['CTRL' & 'X' keys together]

After rebooting log in again and 'su -' to root user. At the command prompt type 'hwclock -r && date'. What you should see is that your Slackware ARM system date/time and RTC date/time are identical.

Now you can be sure whenever you boot your Slackware ARM system it will grab the date/time from your RTC. It won't matter if you don't have an Internet connection anymore as far as system time is concerned.

If, for whatever reason, you need to set the date/time accurately again on your RTC then you can use the same 'sntp -sS pool.ntp.org && hwclock -w' command to achieve this. Always remember that in order to use this command you must be logged in as the 'root' user.

root@koor:~# sntp -sS pool.ntp.org && hwclock -w

As far as this guide goes, for installing and configuring the ChronoDot RTC on your Slackware ARM system on a Raspberry Pi, you are done! Contratulations are in order if you have successfully managed to complete this fun little project. :-D

Installing & configuring the ChronoDot RTC on Slackware ARM without Device Tree overlays

You need to follow this section of the guide only if your system does not rely on Device Tree overlays to load and configure hardware at boot time. For the purpose of this section of the guide , we have given the name "myrasbox" to our Slackware ARM system.

Remember, if you want to use a non-Device Tree (pre-DT) system to install and configure your ChronoDot RTC, you'll need to disable Device Tree in the /boot/config.txt file by adding 'device_tree=' on a line by itself.

Log in as (or change to) the 'root' user. If the date is not already set to current time you should now set it manually, or use the 'sntp' 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' at this point will achieve this and, depending on the number of updates available, may take a while to complete.

As 'root' user, you're going to 'cd' to the /tmp directory and download the i2c-tools package. There's two choices; Slackware ARM 14.2, and current.

Note for Slackware ARM packages: Make sure to only install package(s) for the Slackware ARM version you're running. Packages that are built for current hard float port will not work with 14.2 soft float port (and vice versa).

• To install i2c-tools-4.2 for Slackware ARM current use 'slackpkg' or download it from a Slackware ARM mirror .

• To download and install i2c-tools-4.2 for Slackware ARM 14.2 type the following:

root@myrasbox:~# cd /tmp/
root@myrasbox:/tmp# wget https://slackware.uk/sarpi/pkg/14.2/i2c-tools-4.2-armv7-1_slack14.2_sp1.txz
root@myrasbox:/tmp# installpkg i2c-tools-4.2-armv7-1_slack14.2_sp1.txz

This i2c-tools Slackware ARM package was created specifically for this project using the i2c-tools.SlackBuild script available from SlackBuilds.org because it didn't seem to be already available for download on the Internet. It goes without saying that i2c-tools for Linux is useful for more than just setting up RTCs on a Raspberry Pi.

Once this has completed you should see something similar to 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 RTC. Do this with 'nano' by typing:

root@myrasbox:/tmp# nano -w /etc/rc.d/rc.local

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:

/sbin/modprobe i2c-bcm2708
/sbin/modprobe i2c-dev
/sbin/modprobe rtc-ds1307

Pay attention to the next section because it is important (only) for Raspberry Pi (1) Model B owners. Whether you are using a Raspberry Pi (1) Model B rev.1 or rev.2 board depends on the code you need to enter and this is crucial towards success. Raspberry Pi 1 Model A+ and Model B+, Raspberry Pi 2, Raspberry Pi 3, and Raspberry Pi 4 users do not have to bother checking their hardware version(s). If you're unsure which revision you're currently using see this page: Identifying Your Model of Raspberry Pi. Once you have determined which version of Raspberry Pi you are using, you can proceed.

• For Raspberry Pi (1) Model B rev.1 boards you need to enter the following code into the rc.local file below the text you have just entered:

echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-0/new_device
/sbin/hwclock -s

• For Raspberry Pi 3, Raspberry Pi 2, Raspberry Pi (1) Model B rev.2, Model A/A+/B+ boards you need to enter the following code into the rc.local file below the text you have just entered:

echo ds3231 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
/sbin/hwclock -s

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 current time from a NTP server over the Internet at boot time. It would be a little pointless to get a time reference from a NTP server when there's a highly accurate real time clock 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 i2c-bcm2708 module is the low level i2c subsystem driver. The i2c-dev module allows access to devices through the /dev interface. The rtc-ds1307 module contains the drivers for many RTC controllers, such as the DS1337 and MCP79410. Using the 'modinfo rtc-ds1307' command shows you that the DS3231 (i.e. the ChronoDot) is supported within the rtc-ds1307 module, and that's why it's needed at boot time.

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 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 RTC working with the system. Type the following code to run the rc.local file:

root@myrasbox:/tmp# /etc/rc.d/rc.local

After running the rc.local file you need to make sure the RTC is 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 (1) Model B rev.1 boards use this command:

root@myrasbox:/tmp# i2cdetect -y 0

• For Raspberry Pi 3, Raspberry Pi 2, Raspberry Pi (1) Model B rev.2, Model A/A+/B+ boards use this command:

root@myrasbox:/tmp# i2cdetect -y 1

The screenshot below is the result you're looking for. It shows that the device has been detected and recognised.

Instead of '68' being displayed you might see 'UU' in its place. This is perfectly fine because it just means that a software driver (the rtc-ds1307 module) has been loaded and is currently using the 0x68 address. In both cases it indicates the RTC has been detected.

So you can go right ahead and find out what time and date is set to on your 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:

root@myrasbox:/tmp# hwclock -r

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 RTC. 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 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 'sntp -sS' command. The latter is preferred for accuracy reasons alone.

• Set the time and date on the RTC manually by using the following command (pay attention to the date format):

root@myrasbox:/tmp# date MMDDHHmmYYYY && hwclock -w

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:17pm on September 11, 2016 then the command would be as follows:

root@myrasbox:/tmp# date 091121172016 && hwclock -w

In our example above the 'date 091121172016' command sets the time and date on our Slackware ARM Linux system and the 'hwclock -w' command which follows then writes that date and time to the hardware clock (the ChronoDot RTC).

• Set the time and date on the RTC using a NTP server with the following command:

root@myrasbox:/tmp# sntp -sS pool.ntp.org && hwclock -w

The 'sntp -sS pool.ntp.org' command grabs the current date and time from a NTP server and writes it to our Slackware ARM Linux system. The 'hwclock -w' command which follows then writes that date and time to the hardware clock (the ChronoDot RTC). The NTP server you use does not have to be the same one as in our example.

NB: The above 'date' and/or 'sntp -sS' command(s) can be used at any time (as 'root' user) to set the time & date on the RTC.

Now type 'hwclock -r' (i.e. READ the hardware clock) 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.

After you have set the date and time the RTC will retain it, even when your Raspberry Pi is turned off, because of the 3v Lithium CR1632 coin cell battery. The ChronoDot real time clock is the most accurate RTC module that we've ever come across and it's really impressed us with ease of use, cost effectiveness, and a totally cool design!

The final 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



Thanks & Credits!

Thank you for reading and taking part in this fun little project. We hope others find it as interesting and educational as we did.

Credit and a massive thank you to Matteo Bernardini for his i2c-tools.SlackBuild script which allowed us to build the i2c-tools (.txz) packages 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

Back to Top


Updated: 2021-04-06 12:46:18 UTC

Disclaimer: The SARPi Project website is for non-commercial and general information purposes only. The content is provided by Penthux.NET and while we endeavour to keep information up to date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the website or any information, software, products, services, or related graphics which is available on the website for any purpose. Any reliance you place on such information is therefore strictly at your own risk. In no event will Penthux.NET be liable for any loss or damage including without limitation, indirect or consequential loss or damage, or any loss or damage whatsoever arising from loss of data or profits arising out of, or in connection with, the use of this website or any of its contents. Through this website you are able to visit other websites which are not under our control. Penthux.NET has no influence over the nature, content or availability of any external URLs. The inclusion of any URLs does not necessarily imply a recommendation or endorsement of any content therein. Every effort is made to ensure the SARPi Project website remains accessible. However, Penthux.NET takes no responsibility for, and will not be liable for, the SARPi Project website being temporarily unavailable due to technical issues beyond our control. Penthux.NET is in no way affiliated with Slackware Linux, Inc, or the Linux Foundation, or the Raspberry Pi Foundation, or any of their members, trustees, partners, or associates.


Accept!
SARPi Project uses cookies for website traffic & data analysis. [ Cookie Policy ]