RTCモジュール


インターネットに接続できている場合は必要になる機能。
(NTPサーバにアクセスして、時間を修正できない為)

I2Cを使用可能にする(その1)

sudo vi /etc/modules

変更前

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835

変更後

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835
i2c-bcm2708
i2c-dev

I2Cを使用可能にする(その2)

sudo vi /etc/modprobe.d/raspi-blacklist.conf

変更前

# blacklist spi and i2c by default (many users don't need them)

blacklist spi-bcm2708
blacklist i2c-bcm2708
blacklist snd-soc-pcm512x
blacklist snd-soc-wm8804

変更後

# blacklist spi and i2c by default (many users don't need them)

blacklist spi-bcm2708
#blacklist i2c-bcm2708
blacklist snd-soc-pcm512x
blacklist snd-soc-wm8804

変更が完了したら再起動する
sudo reboot

モジュールをインストール
sudo apt-get install i2c-tools


RTCモジュールへの日時設定

アドレスの確認 (Model Bの場合)

sudo i2cdetect -y 1

pi@robohead ~ $ sudo i2cdetect -y 1
   0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@robohead ~ $

モジュールのロード(Model Bの場合)

sudo su
modprobe rtc-ds1307
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device

RTCモジュールの時刻を読み込む

hwclock -r

root@robohead:/home/pi# hwclock -r
Sat 01 Jan 2000 11:21:06 AM JST -0.204390 seconds
root@robohead:/home/pi##hr


時間がずれているので、現在日時をRTCモジュールに書き込む

hwclock -w

時刻が合っているのかを確認する

hwclock -r;date

root@robohead:/home/pi# hwclock -r;date
Fri 21 Nov 2014 02:45:58 AM JST -0.870302 seconds
Fri Nov 21 02:45:58 JST 2014
root@robohead:/home/pi#


起動時にRTCモジュールの日時をシステム日付に自動で設定(Model Bの場合)

sudo vi /etc/rc.local

変更前


#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) | | true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

exit 0


変更後


#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) | | true
if [ "$_IP" ]; then
printf "My IP address is %s\n" "$_IP"
fi

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
sleep 1
hwclock -s
exit 0



  • 最終更新:2015-04-05 18:49:22

このWIKIを編集するにはパスワード入力が必要です

認証パスワード