I've seen a number of questions about this lately and folks seem to have great difficulty getting this to work. I happened to have a DS1307 break out board available and thought I would try my luck.
First I started out with a new copy of 2015-11-21-raspbian-jessie.zip that I downloaded from here
I created my SD card and expanded the filesystem. That was the only preconfiguration I did.The following are the steps I took to get it to work.
Boot Setup
I ran
sudo raspi-config
and selected option 9 - Advanced Options
Then I selected
A7 I2C
I selected <Yes> on the next page indicating that I would like to enable ARM I2C
On the following page I was simply presented with an OK prompt, which I selected by hitting the enter key.
I selected <Yes> on the subsequent page indicating that I would like the module loaded at boot time.
I then exited the raspi-config screen indicating that I would like to reboot.
Note: I did this the initial time , but on a subsequent reboot I removed the additional driver, so this step may not be necessary
After the raspi rebooted, I edited the file /etc/modules, this is just a text file, so any editor will do, I chose vi, so the command I entered was
sudo vi /etc/modules
I noticed the only line in there after the comments (which are preceded with the # symbol) was
i2c-dev
other instructions I have seen indicated that i2c-bcm2708 is required as well, so I will add that above the i2c-dev line, I can do this in vi by arrowing down to the i2c-dev line, hitting O (shift o) and typing in i2c-bcm2708, then esc, then :wq
End Note:
some instructions will tell you to check the file /etc/modprobe.d/raspi-blacklist.conf and ensure that the i2c device is not blacklisted, this file does not appear to exist on this version of raspbian, so this step was not necessary.
The last thing I did was check to ensure that /boot/config.txt contained the line
dtparam=i2c_arm=on
you can do this by typing
cat /boot/config.txt
if you started with a fresh install like I did and followed the procedure as outlined above, it should be the last line in the file.
Make sure it is not preceded by the # character indicating that line is a comment and will be ignored, in my file that was modified by raspi-config, the entry is actually in there 2 times, 1 time commented out, and one time uncommented, this is fine.
Now it is time to shutdown the pi and hook up the RTC.
You can shutdown the pi by typing
sudo shutdown -h now
once it has been shutdown, remove the power.
Hardware Setup
It is very important to remove the power and double check all of your connections, it is very easy to make a mistake, even with a simple circuit such as this.
The following image shows my connection.
My device is different than all the others I have seen, although it does have a ds 1307 rtc on the board.
My connections were simple
DS 1307 Ras Pi
VCC (Red) Pin 2
GND (Black) Pin 6
SDA (White) Pin 3
SCL (Green) Pin5
It is important to note that I am able to connect a 5v I2C device to the Raspberry Pi because there are no external pull up resistors on the SDA and SCL lines on the external board. If there are you must remove them, or you can damage your pi. I2C slave devices only drive signals to ground, when it is not low, they are open collector or open drain and will not assert a voltage on the line. If there are pull ups, they will bring the dormant lines up to the supply voltage.
Using the device
OK. Now that the hardware is hooked up, we can finish setting up the software.
at the command line enter
sudo apt-get install python-smbus
if it prompts, just enter y to continue
and
sudo apt-get install i2c-tools
if it prompts you, enter y to continue
if it tells you i2c-tools is already the newest version, that's fine too.
after that ,enter
sudo i2cdetect -y 1
and it should show that it detects the ds 1307 at I2C address 68
after that we will type
sudo modprobe rtc-ds1307
sudo bash
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
exit
and then we'll run i2cdetect again
sudo i2cdetect -y 1
and it should give you something similar to the following
notice this time it gave UU instead of 68 for the device address. This is because the driver for the device has been loaded.
Now we can exercise the device
we can type in
sudo hwclock -r
to read from the device
and type in
sudo hwclock -w
to set the device to the system time
after this you can follow other tutorials to have it set the time from rtc at system boot, or change some of the steps to accommodate different RTC devices.
Hopefully this will help people get devices like this and others configured
Top Comments