Difference between revisions of "Rtc"

From BitWizard Wiki
Jump to navigation Jump to search
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:

First, the i2c-bcm2708 i2c driver needs to be loaded. As far as I know, in the first few months of the raspberry pi being available, the module was blacklisted and didn't load automatically, but nowadays the module is loaded by default. If it isn't on your system:
= Adding the driver =
== new version ==

Go into raspi-config and enable i2c.

Then add:

dtoverlay=i2c-rtc,mcp7941x

to your /boot/config.txt

== old version ==

For historic reasons the old version is still here. Unless you have an old distribution it is recommended you do it the modern way as documented above.

First, the i2c-bcm2708 i2c driver needs to be loaded. As far as I know, in the first few months of the raspberry pi being available, the module was blacklisted and didn't load automatically. Nowadays "raspi-config" will already give you the option to enable the driver.

What "raspi-config" does (but you can also do by hand) is remove the drivers from /etc/modprobe.d/raspi-blacklist.conf .

If the driver isn't loaded on your system start with:
sudo modprobe i2c-bcm2708
sudo modprobe i2c-bcm2708


Load the I2C and RTC drivers as root:
Then load the I2C and RTC drivers as root:
sudo -s
sudo -s
modprobe i2c-dev
modprobe i2c-dev
Line 8: Line 28:
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-0/device/new_device # For rev1 RPi
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-0/device/new_device # For rev1 RPi
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device # For rev2 RPi
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device # For rev2 RPi


== Using the clock ==


To write the system time to the RTC (you might need to run this command twice, when you use the RTC for the first time):
To write the system time to the RTC (you might need to run this command twice, when you use the RTC for the first time):
Line 18: Line 41:
hwclock -s
hwclock -s


To automatically do this on startup, add the following lines to /etc/rc.d/rc.local
To automatically do this on startup, add the following lines to /etc/rc.local
modprobe i2c-dev
modprobe i2c-dev
modprobe i2c:mcp7941x
modprobe i2c:mcp7941x

Latest revision as of 12:15, 1 June 2018

Adding the driver

new version

Go into raspi-config and enable i2c.

Then add:

dtoverlay=i2c-rtc,mcp7941x

to your /boot/config.txt

old version

For historic reasons the old version is still here. Unless you have an old distribution it is recommended you do it the modern way as documented above.

First, the i2c-bcm2708 i2c driver needs to be loaded. As far as I know, in the first few months of the raspberry pi being available, the module was blacklisted and didn't load automatically. Nowadays "raspi-config" will already give you the option to enable the driver.

What "raspi-config" does (but you can also do by hand) is remove the drivers from /etc/modprobe.d/raspi-blacklist.conf .

If the driver isn't loaded on your system start with:

sudo modprobe i2c-bcm2708

Then load the I2C and RTC drivers as root:

sudo -s
modprobe i2c-dev
modprobe i2c:mcp7941x
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-0/device/new_device  # For rev1 RPi
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device  # For rev2 RPi


Using the clock

To write the system time to the RTC (you might need to run this command twice, when you use the RTC for the first time):

hwclock -w

Read out the RTC, and print the date and time to your console:

hwclock

Read out the RTC, and adjust system time:

hwclock -s

To automatically do this on startup, add the following lines to /etc/rc.local

modprobe i2c-dev
modprobe i2c:mcp7941x
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-0/device/new_device  # For rev1 RPi
echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device  # For rev2 RPi
hwclock -s

Source: http://www.element14.com/community/message/63885