Installing the RasClock – Raspberry Pi Real Time Clock
https://www.modmypi.com/blog/installing-the-rasclock-raspberry-pi-real-time-clock
Installing the RasClock – Raspberry Pi Real Time Clock Module
Introduction
The Raspberry Pi is an ultra-small and ultra-low cost computer. In order to achieve this size and price, several non-essential items usually found on a computer had to be omitted. Laptops and computers keep time when the power is off by using a pre-installed, battery powered ‘Real Time Clock’ (RTC). However, this Real Time Clock module is not included with the Raspberry Pi. To keep time, the Raspberry Pi updates the date and time automatically over the internet via Ethernet or WiFi.
The Raspberry Pi will simply revert back to the standard date and time settings (usually 30 November 1999) when the network connection is removed. So, for projects which have no internet connection, you may want to add a low cost battery powered RTC to help your Pi keep time!
The RasClock has been specifically designed for use with the Raspberry Pi and, unlike other RTC’s available, can plug directly in to the Raspberry Pi’s GPIO Ports.
Step 1. Plug it in!
A.
Plug the coin battery into the module. This is completed by matching the positive + on the battery with the positive + on the module. This is depicted in Figure 1.
Figure 1.Installing the Battery into the RasClock
B.
Then simply plug the module into the Raspberry Pi as depicted in the Figure 2 below. It sits on the furthest 6 GPIO pins at the SD card end of the Raspberry Pi.
Figure 2.Installing the RasClock
Step 2. Set-Up
A.
This RTC module is designed to be used in Raspbian. So, the first step is to make sure you have the latest Raspbian Operating System (OS) installed on your Raspberry Pi. You can download the latest version here: http://www.raspberrypi.org/downloads
B.
Once installed, we’ll then need to make sure we’ve got the latest firmware drivers by running the following commands:
Sudo apt-get update
(This updates the list of available packages and their versions, but it does not install or upgrade any packages.)
Sudo apt-get upgrade
(This actually installs newer versions of the packages you have. After updating the lists, the package manager knows about available updates for the software you have installed.)
Sudo apt-get autoremove
(This will then remove all of the reduntant packages after the latest upgrade)
C.
Currently the module requires the installation of a driver that is not in the standard Raspbian distribution.
Source Code: https://github.com/afterthoughtsoftware/linux
We will install the module using a pre-compiled installation package as follows:
Grab the installation package off the internet by running the following commands on the Raspberry Pi (make sure you’re connected to the internet):
wget http://afterthoughtsoftware.com/files/linux-image-3.6.11-atsw-rtc_1.0_armhf.deb
(The wget command allows you to grab a file off the internet by providing a URL)
sudo dpkg -i linux-image-3.6.11-atsw-rtc_1.0_armhf.deb
(the dpkg command enables the management of Debian packages. The -i installs the package, or upgrades it if it is already installed)
sudo cp /boot/vmlinuz-3.6.11-atsw-rtc+ /boot/kernel.img
(The cp command stands for copy. Here, we need to copy the RTC module’s boot file to the Raspberry Pi boot directory)
D.
The next step involves editing the text in the Raspberry Pi boot files. I usually use nano text editor for these minor changes – it’s basic, pre-installed and easy to master.
First we then need to configure Raspbian to load the RTC drivers at boot, by adding the boot information to/etc/modules config file.
Sudo nano /etc/modules
(this will open the ‘modules’ file in the nano text editor and allow you to make changes. To enable system commands for nano, simply hold the CTRL key, denoted as ^ in nano, whilst pressing the relevant command. For example CTRL+X to exit, or CTRL+G for help)
To add text simply use the arrows keys to browse to the next line in the boot file and add the following text, one per line:
i2c-bcm2708
rtc-pcf2127a
Then exit nano (CTRL+X) and don’t forget to save those changes!
D.
The final step in set-up is to register the RTC module when the Raspberry Pi boots and set the system clock from the RTC. Again, using nano to edit the files. When editing files always follow the instructions outlined at the top of the file denoted by #. For example, the file we are just about to edit requires any text to be put before the end of the file, denoted by ‘exit 0′.
Open the required file for editing:
Sudo nano /etc/rc.local
For Rev 1. Raspberry Pi Boards Add the following text:
echo pcf2127a 0×51 > /sys/class/i2c-adapter/i2c-0/new_device
( sleep 2; hwclock -s ) &
For Rev 2. Raspberry Pi Boards Add the following text:
echo pcf2127a 0×51 > /sys/class/i2c-adapter/i2c-1/new_device
( sleep 2; hwclock -s ) &
Then reboot!
sudo reboot
Step 3. Using the RTC
After you reboot the Raspberry Pi, you should be able to access the module using the hwclock command.
The first time you use the clock you will need to set the time. To copy the system time into the clock module:
hwclock -w
To read the time from the clock module:
hwclock -r
To copy the time from the clock module to the system:
hwclock -s
That’s it! You can now keep time using your Raspberry Pi with no Internet!
The RasClock is compatible with all standard ‘hwclock’ commands!
The RasClock and ArchLinux
The RasClock is fully compatible with ArchLinux as long as one. . . .
a) uses the linux-raspberrypi-latest kernel (currently v3.11.2)
b) installs i2c-tools
c) adds i2c-bcm2708 & rtc_pcf2127 to the /etc/modules-load.d/raspberryp
d) makes a new file, /etc/modules-load.d/i2c-dev.co
i2c-dev
e) runs ” # echo pcf2127 0×51 > /sys/class/i2c-dev/i2c-1/devic
Thanks to Nigel Heasman for his work on this!