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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum PiFace RTC on Raspberry Pi2: still losing time on reboot!
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 24 replies
  • Answers 1 answer
  • Subscribers 678 subscribers
  • Views 3506 views
  • Users 0 members are here
  • clock
  • pi
  • rtc
  • raspberry_pi
  • raspberrypi
  • date
  • settings
  • piface
Related

PiFace RTC on Raspberry Pi2: still losing time on reboot!

Former Member
Former Member over 9 years ago

Hi!

 

I bought a PiFace RTC and I'm trying it on a Raspberry Pi 2 Model B. I followed the many guides I found on the internet, but I'm still having problem with the date: when I reboot, the system time is always set to Jan 1, 1970! It seems to be in a reset condition.

The I2C detects well the device at the address 0x6F, and the battery is ok.

After the execution of the .sh script as written in the PiFace RTC user guide, I set the actual date with "sudo date -s "12 jan 2016 10:30:00",

set the i2c module from raspi-config.

I triyed in so many ways but I really can't understand what I'm doing wrong!

 

Any idea would be appreciated!
Thanks,

 

Andrea.

  • Sign in to reply
  • Cancel
Parents
  • clem57
    0 clem57 over 9 years ago

    You did not install startup script. See https://github.com/piface/PiFace-Real-Time-Clock for install script.

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to clem57

    Hi Clem,

     

    Thank you.

    Yes, I installed the script, either automatically (connected to the internet) and manually (procedure described in the link you provided). Unfortunately, nothing is changed..

    After installing the script with

    $ sudo ./install-piface-real-time-clock.sh

    This message appears:

    Changing /etc/rc.local to load time from PiFace Clock.
    Now *reboot* and set your clock with
    sudo date -s "14 JAN 2014 10:10:30"

    So, I enabled the I2C by running

    $ raspi-config

    as described in the link you provided, then I rebooted and set the date with sudo date -s ...

    Then:

    sudo reboot

    The new date seems to be not retained!

    $ date

    Gives to me:

    gio 1 gen 1970, 01.00.18, CET

    It still not working image!

     

    I checked the i2c with:

    $ i2cdetect -y 1

    this is the output:

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- UU
    70: -- -- -- -- -- -- -- --

     

    As far as I remember, this means that the PiFace RTC seems to be well detected...

     

    I really can't understand where can be the problem, what am I doing wrong?

    Thanks in advance,

     

    Andrea

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to Former Member

    Do you have pullups on the I2C lines, if not you should, they will help alot

     

    about 5K-10K should work if the RTC is closs to the PI

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to Robert Peter Oakes

    Just looked at the board and it appears to have some so perhaps a different problem ??

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to Robert Peter Oakes

    Thanks Peter,

     

    yes, perhaps it's a different problem.

     

    For testing purpose, I tryied to set the date with:

    sudo date -s "14 jan 2016 08:55:30"

     

    then I copy the time to the RTC with:

    sudo hwclock -w

     

    Then I read the RTC with:

    sudo hwclock -r

     

    Ok, the time displayed is correct.

     

    After that, I shut down, wait for five minutes and I power up.

     

    I try to read the RTC once more:

    sudo hwclock -r

     

    It gives:

    gio 1 gen 1970, 01.00.31, CET

     

    and sudo hwclock -r gives:

    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).

     

    So the time has not being retained! I really don't know where the problem can be image

    Please help!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 9 years ago in reply to Former Member

    #=======================================================================

    # NAME: start_on_boot

    # DESCRIPTION: Load the I2C modules and send magic number to RTC, on boot.

    #=======================================================================

    start_on_boot() {

      echo "Changing /etc/rc.local to load time from PiFace Clock."

      # remove exit 0

      sed -i "s/exit 0//" /etc/rc.local

     

      if [[ $RPI_REVISION == "1" ]]; then

      i=0 # i2c-0

      else

      i=1 # i2c-1

      fi

     

      cat >> /etc/rc.local << EOF

    modprobe i2c-dev

    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N

    i2cset -y $i 0x6f 0x08 0x47

    modprobe i2c:mcp7941x

    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-$i/device/new_device

    hwclock -s

    EOF

    }

    The script above is not setting /etc/rc.local correctly. Please show the contents here. Ty

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to clem57

    Hi Clem,

     

    where have to be placed the script you posted? Is it automatically executed at the startup?

     

    My /etc/rc.local contains the code below (is it correct? Perhaps some problems here?)

    _IP=$(hostname -I) || true
    if [ "$_IP" ]; then
      printf "My IP address is %s\n" "$_IP"
    fi
    
    
    modprobe i2c-dev
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s
    modprobe i2c-dev
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s
    
    #Andrea
    echo mcp7941x 0x6f > sys/class/i2c-adapter/i2c-1/new_device
    ( sleep 2; hwclock -s ) &
    
    modprobe i2c-dev
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s
    
    #added by myself
    echo mcp7941x 0x6f > sys/class/i2c-adapter/i2c-1/new_device
    sudo hwclock -s
    
    modprobe i2c-dev
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s
    
    #added by myself
    echo mcp7941x 0x6f > sys/class/i2c-adapter/i2c-1/new_device
    sudo hwclock -s
    modprobe i2c-dev
    
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s
    modprobe i2c-dev
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s

     

    Thanks again!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 9 years ago in reply to clem57

    Hi Clem,

     

    where have to be placed the script you posted? Is it automatically executed at the startup?

     

    My /etc/rc.local contains the code below (is it correct? Perhaps some problems here?)

    _IP=$(hostname -I) || true
    if [ "$_IP" ]; then
      printf "My IP address is %s\n" "$_IP"
    fi
    
    
    modprobe i2c-dev
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s
    modprobe i2c-dev
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s
    
    #Andrea
    echo mcp7941x 0x6f > sys/class/i2c-adapter/i2c-1/new_device
    ( sleep 2; hwclock -s ) &
    
    modprobe i2c-dev
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s
    
    #added by myself
    echo mcp7941x 0x6f > sys/class/i2c-adapter/i2c-1/new_device
    sudo hwclock -s
    
    modprobe i2c-dev
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s
    
    #added by myself
    echo mcp7941x 0x6f > sys/class/i2c-adapter/i2c-1/new_device
    sudo hwclock -s
    modprobe i2c-dev
    
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s
    modprobe i2c-dev
    # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s

     

    Thanks again!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • clem57
    0 clem57 over 9 years ago in reply to Former Member

    Ok you have too much. remove all up to last "#  Calibrate" using nano. save and reboot. Should work

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to clem57

    I will try and let you know if it can solve the problem. Thanks!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to Former Member

    Hi Clem,

     

    I modified my /etc/rc.local according with your tip. At the first reboot the time was ok! But with the successive shutdown and reboots, time and date was still not retained! Is it possible?

    Now my /etc/rc.local is:

    #Print the IP address
    _IP=$(hostname -I) || true
    if [ "$_IP" ]; then
       printf "My IP address is %s\n" "$_IP"
    fi
    
    #Calibrate the clock (default: 0x47). See datasheet for MCP7940N
    i2cset -y 1 0x6f 0x08 0x47
    modprobe i2c:mcp7941x
    echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-1/device/new_device
    hwclock -s

    Do you think it should be ok?

    Thanks.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • clem57
    0 clem57 over 9 years ago in reply to Former Member

    You do have a battery in holder, right?

    Clem

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to clem57

    Yes,

    I just check it now with a multimeter...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • 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