time

Using RTC PCF8563 on Raspberry PI running Raspbian OS

I built the RTC circuit. Now, I had to start using the “RTC to keep time, in Raspbian OS”! Well,after a bit of digging and experiment, here’s what I did.

I used a PCF8563 RTC with Raspberry Pi Model B, running latest version of Raspbian OS (Release date: 2014-01-07).

NOTE: RTC PCF8563 is supported in the latest Raspbian OS kernels. No need to build a custom kernel.

  • First, sudo vi /etc/modprobe.d/raspi-blacklist.conf
    • Then, comment out the following lines, by prepending them with a # character:
#blacklist i2c-bcm2708
  • Second, you need to configure to load modules at startup.
    • Open the file: sudo vi /etc/modules
    • Add the following lines, at the end of the file:
      i2c-bcm2708
      i2c-dev
      rtc-pcf8563
  • Install i2c-tools:
    sudo apt-get install i2c-tools

    and then REBOOT

  • After reboot, check to see if your h/w is connected and working:
    sudo  i2cdetect -y 1

    If your h/w is working you should see a 0x51 in the output of the above command.

  • Now, you need to add the rtc clock to work right at every boot:
    • Open /etc/rc.local:    sudo vi /etc/rc.local
    • Add the following lines, right before the line containing exit 0 (the exit 0 should be the last line of the rc.local file)
      modprobe i2c-bcm2708
      echo pcf8563 0x51 > /sys/class/i2c-adapter/i2c-1/new_device
      modprobe rtc-pcf8563
      hwclock -s
    • Now reboot again.
  • To change the date in rtc:
    • Check the current date and time in Raspbian OS: date
    • Set the date and time in your Raspbian OS(you should have set the correct timezone, before this step):

date -s "MMM DD HH:MM:SS"

Where, MMM=first 3 letters of months, DD=new date and HH:MM:SS = 24 hr format hours:minutes:seconds.
You should enclose the parameters, within double quotes. For more information check man page of date.

  • To view the current date and time stored in the RTC Pi:   hwclock -r
  • Set the Linux system time to the value in the RTC Pi:   hwclock –s
  • To set the RTC Pi with a custom time directly, use:

hwclock --set --date="2014-12-25 00:00:00" --utc
and then use:
hwclock --hctosys

For more information about hwclock, refer the man page.

  • Done!
Advertisements