MCP7491x Jessie
-
I am trying to get the UniPi RTC to work with Raspbian Jessie. If I reboot then try to read the RTC with hwclock -r then I get
@247cbith:hwclock: The Hardware Clock registers contain values that are either invalid (e.g. 50th day of month) or beyond the range we can handle (e.g. Year 2095).
I have been through the process several times and have condensed the setup to a single script which should make debugging easier. To reproduce the problem start from a clean install of Raspbian Jessie (I m using the 2016-03-18-raspbian-jessie.img image). Then copy on the script below and execute it as root.
#!/bin/bash # UniPi driver setup if [ "$EUID" -ne 0 ] then echo "This script must be run as root" exit fi echo Backup files cp /boot/config.txt /boot/config.txt.bak echo Enabling I2C bus... if ! grep -q '^dtparam=i2c_arm=on' /boot/config.txt then echo 'dtparam=i2c_arm=on' >> /boot/config.txt fi if ! grep -q '^dtparam=i2c_baudrate=400000' /boot/config.txt then echo 'dtparam=i2c_baudrate=400000' >> /boot/config.txt fi echo Enabling the RTC chip... if ! grep -q '^dtoverlay=i2c-rtc,mcp7941x' /boot/config.txt then echo 'dtoverlay=i2c-rtc,mcp7941x' >> /boot/config.txt fi echo Getting i2c development tools apt-get install -y i2c-tools if ! grep -q '^i2c-dev' /etc/modules then echo 'i2c-dev' >> /etc/modules fi echo Removing fake-hwclock... apt-get purge -y fake-hwclock update-rc.d -f fake-hwclock remove apt-get autoremove -y echo ' ' echo 'UniPi installed.' echo ' ' echo '!!! REBOOT IS REQUIRED !!!' echo ' ' read -p "Is it OK to reboot now? [y/N] " -n 1 -r echo ' ' if [[ $REPLY =~ ^[Yy]$ ]] then reboot else echo 'Reboot to finish configuring drivers' fi echo ' '
Having executed the script and rebooted the RPI the time can be set using sudo hwclock -w. If I then test the hwclock using sudo hwclock –debug I get the output below, all appears to be working - until I reboot.
hwclock from util-linux 2.25.2 Using the /dev interface to the clock. Last drift adjustment done at 1460394468 seconds after 1969 Last calibration done at 1460394468 seconds after 1969 Hardware clock is on UTC time Assuming hardware clock is kept in UTC time. Waiting for clock tick... /dev/rtc does not have interrupt functions. Waiting in loop for time from /dev/rtc to change ...got clock tick Time read from Hardware Clock: 2016/04/11 17:08:03 Hw clock time : 2016/04/11 17:08:03 = 1460394483 seconds since 1969 Mon 11 Apr 2016 17:08:03 UTC -0.371602 seconds ```I have already looked at [http://unipi.technology/wiki/Installing_required_software](247cbith), but the instructions seem to be more aimed at Wheezy, in fact there is a comment that states @247cbith: > If this tutorial does not work, try googling a new one. I have done plenty of googling and have not found a reliable solution. A few appeared to work - but did not include the step to remove the fake_hwclock. When I tested carefully it was the fake_hwclock that was retaining the time over a reboot and not the RTC. Any help much appreciated.
-
I am trying to get the UniPi RTC to work with Raspbian Jessie. If I reboot then try to read the RTC with hwclock -r then I get
@247cbith:hwclock: The Hardware Clock registers contain values that are either invalid (e.g. 50th day of month) or beyond the range we can handle (e.g. Year 2095).
I have been through the process several times and have condensed the setup to a single script which should make debugging easier. To reproduce the problem start from a clean install of Raspbian Jessie (I m using the 2016-03-18-raspbian-jessie.img image). Then copy on the script below and execute it as root.
#!/bin/bash # UniPi driver setup if [ "$EUID" -ne 0 ] then echo "This script must be run as root" exit fi echo Backup files cp /boot/config.txt /boot/config.txt.bak echo Enabling I2C bus... if ! grep -q '^dtparam=i2c_arm=on' /boot/config.txt then echo 'dtparam=i2c_arm=on' >> /boot/config.txt fi if ! grep -q '^dtparam=i2c_baudrate=400000' /boot/config.txt then echo 'dtparam=i2c_baudrate=400000' >> /boot/config.txt fi echo Enabling the RTC chip... if ! grep -q '^dtoverlay=i2c-rtc,mcp7941x' /boot/config.txt then echo 'dtoverlay=i2c-rtc,mcp7941x' >> /boot/config.txt fi echo Getting i2c development tools apt-get install -y i2c-tools if ! grep -q '^i2c-dev' /etc/modules then echo 'i2c-dev' >> /etc/modules fi echo Removing fake-hwclock... apt-get purge -y fake-hwclock update-rc.d -f fake-hwclock remove apt-get autoremove -y echo ' ' echo 'UniPi installed.' echo ' ' echo '!!! REBOOT IS REQUIRED !!!' echo ' ' read -p "Is it OK to reboot now? [y/N] " -n 1 -r echo ' ' if [[ $REPLY =~ ^[Yy]$ ]] then reboot else echo 'Reboot to finish configuring drivers' fi echo ' '
Having executed the script and rebooted the RPI the time can be set using sudo hwclock -w. If I then test the hwclock using sudo hwclock –debug I get the output below, all appears to be working - until I reboot.
hwclock from util-linux 2.25.2 Using the /dev interface to the clock. Last drift adjustment done at 1460394468 seconds after 1969 Last calibration done at 1460394468 seconds after 1969 Hardware clock is on UTC time Assuming hardware clock is kept in UTC time. Waiting for clock tick... /dev/rtc does not have interrupt functions. Waiting in loop for time from /dev/rtc to change ...got clock tick Time read from Hardware Clock: 2016/04/11 17:08:03 Hw clock time : 2016/04/11 17:08:03 = 1460394483 seconds since 1969 Mon 11 Apr 2016 17:08:03 UTC -0.371602 seconds ```I have already looked at [http://unipi.technology/wiki/Installing_required_software](247cbith), but the instructions seem to be more aimed at Wheezy, in fact there is a comment that states @247cbith: > If this tutorial does not work, try googling a new one. I have done plenty of googling and have not found a reliable solution. A few appeared to work - but did not include the step to remove the fake_hwclock. When I tested carefully it was the fake_hwclock that was retaining the time over a reboot and not the RTC. Any help much appreciated.
-
I had made a mistake and the notes on the wiki do work for me (I found I didn't need the entry in /etc/modules though). Anyway an updated script that works for me on a clean install of Jessie is below
#!/bin/bash # UniPi driver setup if [ "$EUID" -ne 0 ] then echo "This script must be run as root" exit fi echo Backup files cp /boot/config.txt /boot/config.txt.bak echo Enabling I2C bus... if ! grep -q '^dtparam=i2c_arm=on' /boot/config.txt then echo 'dtparam=i2c_arm=on' >> /boot/config.txt fi if ! grep -q '^dtparam=i2c_baudrate=400000' /boot/config.txt then echo 'dtparam=i2c_baudrate=400000' >> /boot/config.txt fi echo Enabling the RTC chip... if ! grep -q '^dtoverlay=i2c-rtc,mcp7941x' /boot/config.txt then echo 'dtoverlay=i2c-rtc,mcp7941x' >> /boot/config.txt fi echo Getting i2c development tools apt-get install -y i2c-tools if ! grep -q '^i2c-dev' /etc/modules then echo 'i2c-dev' >> /etc/modules fi echo Removing fake-hwclock... apt-get purge -y fake-hwclock update-rc.d -f fake-hwclock remove apt-get autoremove -y sed -i '/^if [ -e \/run\/systemd\/system/,/^fi/s/^/#/' /lib/udev/hwclock-set echo ' ' echo 'UniPi installed.' echo ' ' echo '!!! REBOOT IS REQUIRED !!!' echo ' ' read -p "Is it OK to reboot now? [y/N] " -n 1 -r echo ' ' if [[ $REPLY =~ ^[Yy]$ ]] then reboot else echo 'Reboot to finish configuring drivers' fi echo ' '