element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Michael Conners's Blog Enabling RTC on the Raspberry Pi 2
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: mconners
  • Date Created: 26 Jan 2016 9:05 PM Date Created
  • Views 1148 views
  • Likes 4 likes
  • Comments 5 comments
  • raspberry
  • i2c
  • rtc
  • raspberry pi
  • rtc_pi
  • ds1307
Related
Recommended

Enabling RTC on the Raspberry Pi 2

mconners
mconners
26 Jan 2016

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

 

image

 

Then I selected

 

A7 I2C

 

image

 

I selected <Yes> on the next page indicating that I would like to enable ARM I2C

 

image

 

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.

 

image

 

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.

 

image

 

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

 

image

 

 

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

 

image

 

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

 

image

 

 

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

  • Sign in to reply

Top Comments

  • mports
    mports over 9 years ago +2
    Perfect, I've managed it get the PiFace RTC Shim running on my RPi 3 by following the above instructions , the only additions I made were to add the follwing line to my my /boot/config.txt file: dtoverlay…
  • gadget.iom
    gadget.iom over 9 years ago +1
    A really useful guide. Thanks. :)
  • mconners
    mconners over 9 years ago in reply to gadget.iom +1
    Glad you liked it, Paul. It was pretty straight forward to get it to work. Mike
  • mconners
    mconners over 9 years ago in reply to mports

    Glad to hear it was helpful.

     

     

    Mike

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mports
    mports over 9 years ago

    Perfect,

     

    I've managed it get the PiFace RTC Shim running on my RPi 3 by following the above instructions , the only additions I made were to add the follwing line to my my /boot/config.txt file:

     

    dtoverlay=i2c-rtc,mcp7941x

     

    Then enabling the Device Tree option from within the advanced tab using the sudo raspi-config command.

     

    Thank you so much making this post, it helped a lot.

     

    Cheers

     

    Mark

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • piknot
    piknot over 9 years ago

    VERY! useful ! Thank you

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mconners
    mconners over 9 years ago in reply to gadget.iom

    Glad you liked it, Paul. It was pretty straight forward to get it to work.

     

    Mike

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • gadget.iom
    gadget.iom over 9 years ago

    A really useful guide. Thanks. :)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube