element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum Installing Code for PiFace Real Time Clock
  • 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 52 replies
  • Answers 4 answers
  • Subscribers 665 subscribers
  • Views 5643 views
  • Users 0 members are here
  • raspberry_pi
Related

Installing Code for PiFace Real Time Clock

fc-element
fc-element over 8 years ago

Dear Element 14 Community.

All my Raspberry Pi devices (RPi 2, RPi Zero, and RPi 3 (planned) are running with the current Raspbian Jessie version. I have successfully installed PiFace Real Time Clock using the PiFace website instructions and GitHub.com software download on a number of RPi 2's and one of my three RPi Zero's.

 

I have recently continued the installations on another two RPi's and cannot continue because after these two lines:

1. chmod +x install-piface-real-time-clock.sh

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

 

The following new comments are returned: 1

1.. create new pifacertc init script to load time from PiFace RTC

2. Adding /etc/init.d/pifacertc .

3. install the pifacertc init script

4. enable I2c by using raspi-config

 

As I am a Linux beginner, can someone lead me through (expand) the coding of these lines so I may install PiFace RTC currently and in the future. The changelog on GitHub refers to a revision change but I am not knowledgable enough to understand why the install went through previously by not currently.

 

Thank you very much,

Frank.

  • Sign in to reply
  • Cancel
Parents
  • Former Member
    0 Former Member over 8 years ago

    Are those all of the comments that are returned? Having a glance at the install script it seems there should be a piece saying to reboot and another demonstrating how to set the clock etc... If these are missing it would indicate that the install script has not completed correctly.

     

    Has the install script created the /etc/init.d/pifacertc file? check by typing cat /etc/init.d/pifacertc into a terminal window, there should be around 37 lines of text print out into the terminal as a result.

     

    If the installer hasnt completed succesfully it should be easy enough to replicate the procedure manually, everything is provided in that script to do that.

     

    p.s.the comments 1,2 and 3 that appear ate just the install script telling you where it is up to. Comment 4 is an instruction to you to run raspi-config, as I said above, there should also be more text below this

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • fc-element
    0 fc-element over 8 years ago in reply to Former Member

    Thanks for the response of the many users over the last 48 hrs. 
    Dear lucie tozer:

    Let me respond directly to your suggestion:

    I opened the /etc/init.d/pifacertc file in from the File Manager
    and typed cat /etc/init.d/pifacertc at the terminal.
    Both ways yielded:

    # !/bin/sh
    ### BEGIN INIT INFO
    # Provides:   pifacertc
    # Required-Start:    udev mountkernfs $remote_fs raspi-config
    # Required-Stop:  
    # Required-Start:    S
    # Default-Stop:
    # Short Description: Add the PiFace RTC
    # Description:          Add the PiFace RTC
    ### END INIT INFO

    . /lib/lsb/init-functions

    case "$1" in
       start)
           log_success_msg "Probe the i2c-dev"
           modprobe i2c-dev
           # Calibrate the clock ( default: 0x47).  See datasheet or MCP7940N
           log_success_msg "Calibrate the clock"
           i2cset -y 0x6f 0x08 0x47
           log_success_msg "Probe the mcp7941x driver
           modprobe i2c :mcp7941x
           log-success-msg "Add the mcp7941x device in the sys filesystem"
           #https://www.kernel.org/doc/Documentation/i2c/instantiating-devices
           echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-0/device/new_device
           log-success-msg "Synchronise the system clock and hardware RTC"
           hwclock --hctosys
           ;;
       stop)
           ;;
       restart)
           ;;
       force-reload)
           ;;
       #)
          echo "Usage: $0 start" >&2
          exit 3
          ;;
    esac

     

    I opened the /etc/init.d/rc.local file in from the File Manager
    and typed cat /etc/init.d/rc.local at the terminal.
    Both ways yielded:

    # !/bin/sh
    ### BEGIN INIT INFO
    # Provides:     rc.local
    # Required-Start:      $ all
    # Required-Stop:  
    # Required-Start:      2 3 4 5
    # Required-Stop:
    # Short Description:  Run /etc/rc.local if it exist 
    ### END INIT INFO

     

    PATH=/sbin:/usr/sbin:/bin:/usr/bin

    ./lib/init/vars.sh
    ./lib/lsb/init-functions

    do_start () {
          if [ -x /etc/rc.local ]; then
                    [ "$VERBOSE" !=no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
                    /etc/rc.local
                    ES=$?
                    [ "$VERBOSE" !=no ] && log_end_msg $ES
                    return $ES
          fi
    }
    case "$1" in
          start )
             do_start
             ;;
          restart | reload | force-reload)
                echo "Error: argument "$1" not supported" >&2
                exit 3
                ;;
          stop | status )
                # No-op
                exit 0
                ;;
          *)
                echo "Usage: 0 start|stop" >&2
                exit 3
                ;;
    esac

    I appreciate you speedy response to continue with my problem. To re-summarize my total experience with Installing the PiFace Real Time Clock here's additional, more-specific information.

    I had successully installed previous RPi 2's and one of my RPi 0's all running the current Rasbian Jessie software following these websites:

    Starting Website to Add PiFace Real Time Clock
    http://www.piface.org.uk/products/piface_clock/

    Two Links (located towards bottom of site) were followed:

    1. Documentation (downloaded pdf File)

    2. PiFace Real Time Clock on GitHub
    https://github.com/piface/PiFace-Real-Time-Clock

    The previous installation on a RPi Zero (which was successfull) did not generate a /etc/init.d/pifacertc  file
    and during the boot phase, I did see a line:
    [Failed (in red): Failed to start /etc/rc.local compatibility.
    but evidently the clock installed correctly.
    The text for the rc.local files on this device and the RPi Zero device that failed are identical.

    My PATH to install on the failed device is briefly described next:

    pi@raspberrypi ~$ ls
    Downloads  (among other files)
    pi@raspberrypi ~$ cd Downloads
    install-piface-real-time-clock.sh  (in bold yellow/green color)
    chmod +/ install-piface-real-time-clock.sh  (returns prompt)
    sudo ./install-piface-real-time-clock.sh (problems occur)
    returns:
    Create a new pifacertc init script to load time from PiFace RTC
    Adding /etc/init.d/pifacertc .
    Install the pifacertc init script
    Enable I2C by adding:

    raspi-config

    then navigate to "Advanced Options" > I2C
    and select 'yes' to enable the ARM I2C interface. Then *reboot* ans set the clock with:

    sudo date -s "10 JAN 2014 10:10:30"
    sudo hwclock --systohc
    Downloads $

    (end of PATH return)

    I type the command:
    sudo reboot.
    During the boot phase, I noted the following 2 lines:
     
    [FAILED] Failed to start LSB: Add the PiFace Device
    See "systemct1 status pifacertc service" for details

    In fact, I have configured another RPi Zero device in a separate electrical system and tried the install and the same failure occurs.

    This begs two questions:
    1. How to Run command to "See systemct1 status pifacertc service for details" and
    2. Relative to the long-winded response from the terminal after the sudo ./install ... command (PATH above), what should the new pifacertc script contain, why add another /etc/init.d/pifacertc . , and how to install it. It does not detail any of these returns. Finally, you have indicated that the install script may not have completed correctly. Based on all of the above, did the script complete successully or do I need to create another script of which Iis unknown to me.

    Dear lucie tozer:

    If you've arrived here without abandoning me I appeciate it. I just don't understand why an installation can proceed in entirely two different paths on identical systems but yielding different file structures. I'm sure its my mistake and I am confident I'll find the solution through your and many others help. Thanks again. Frank

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • fc-element
    0 fc-element over 8 years ago in reply to Former Member

    Thanks for the response of the many users over the last 48 hrs. 
    Dear lucie tozer:

    Let me respond directly to your suggestion:

    I opened the /etc/init.d/pifacertc file in from the File Manager
    and typed cat /etc/init.d/pifacertc at the terminal.
    Both ways yielded:

    # !/bin/sh
    ### BEGIN INIT INFO
    # Provides:   pifacertc
    # Required-Start:    udev mountkernfs $remote_fs raspi-config
    # Required-Stop:  
    # Required-Start:    S
    # Default-Stop:
    # Short Description: Add the PiFace RTC
    # Description:          Add the PiFace RTC
    ### END INIT INFO

    . /lib/lsb/init-functions

    case "$1" in
       start)
           log_success_msg "Probe the i2c-dev"
           modprobe i2c-dev
           # Calibrate the clock ( default: 0x47).  See datasheet or MCP7940N
           log_success_msg "Calibrate the clock"
           i2cset -y 0x6f 0x08 0x47
           log_success_msg "Probe the mcp7941x driver
           modprobe i2c :mcp7941x
           log-success-msg "Add the mcp7941x device in the sys filesystem"
           #https://www.kernel.org/doc/Documentation/i2c/instantiating-devices
           echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-0/device/new_device
           log-success-msg "Synchronise the system clock and hardware RTC"
           hwclock --hctosys
           ;;
       stop)
           ;;
       restart)
           ;;
       force-reload)
           ;;
       #)
          echo "Usage: $0 start" >&2
          exit 3
          ;;
    esac

     

    I opened the /etc/init.d/rc.local file in from the File Manager
    and typed cat /etc/init.d/rc.local at the terminal.
    Both ways yielded:

    # !/bin/sh
    ### BEGIN INIT INFO
    # Provides:     rc.local
    # Required-Start:      $ all
    # Required-Stop:  
    # Required-Start:      2 3 4 5
    # Required-Stop:
    # Short Description:  Run /etc/rc.local if it exist 
    ### END INIT INFO

     

    PATH=/sbin:/usr/sbin:/bin:/usr/bin

    ./lib/init/vars.sh
    ./lib/lsb/init-functions

    do_start () {
          if [ -x /etc/rc.local ]; then
                    [ "$VERBOSE" !=no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
                    /etc/rc.local
                    ES=$?
                    [ "$VERBOSE" !=no ] && log_end_msg $ES
                    return $ES
          fi
    }
    case "$1" in
          start )
             do_start
             ;;
          restart | reload | force-reload)
                echo "Error: argument "$1" not supported" >&2
                exit 3
                ;;
          stop | status )
                # No-op
                exit 0
                ;;
          *)
                echo "Usage: 0 start|stop" >&2
                exit 3
                ;;
    esac

    I appreciate you speedy response to continue with my problem. To re-summarize my total experience with Installing the PiFace Real Time Clock here's additional, more-specific information.

    I had successully installed previous RPi 2's and one of my RPi 0's all running the current Rasbian Jessie software following these websites:

    Starting Website to Add PiFace Real Time Clock
    http://www.piface.org.uk/products/piface_clock/

    Two Links (located towards bottom of site) were followed:

    1. Documentation (downloaded pdf File)

    2. PiFace Real Time Clock on GitHub
    https://github.com/piface/PiFace-Real-Time-Clock

    The previous installation on a RPi Zero (which was successfull) did not generate a /etc/init.d/pifacertc  file
    and during the boot phase, I did see a line:
    [Failed (in red): Failed to start /etc/rc.local compatibility.
    but evidently the clock installed correctly.
    The text for the rc.local files on this device and the RPi Zero device that failed are identical.

    My PATH to install on the failed device is briefly described next:

    pi@raspberrypi ~$ ls
    Downloads  (among other files)
    pi@raspberrypi ~$ cd Downloads
    install-piface-real-time-clock.sh  (in bold yellow/green color)
    chmod +/ install-piface-real-time-clock.sh  (returns prompt)
    sudo ./install-piface-real-time-clock.sh (problems occur)
    returns:
    Create a new pifacertc init script to load time from PiFace RTC
    Adding /etc/init.d/pifacertc .
    Install the pifacertc init script
    Enable I2C by adding:

    raspi-config

    then navigate to "Advanced Options" > I2C
    and select 'yes' to enable the ARM I2C interface. Then *reboot* ans set the clock with:

    sudo date -s "10 JAN 2014 10:10:30"
    sudo hwclock --systohc
    Downloads $

    (end of PATH return)

    I type the command:
    sudo reboot.
    During the boot phase, I noted the following 2 lines:
     
    [FAILED] Failed to start LSB: Add the PiFace Device
    See "systemct1 status pifacertc service" for details

    In fact, I have configured another RPi Zero device in a separate electrical system and tried the install and the same failure occurs.

    This begs two questions:
    1. How to Run command to "See systemct1 status pifacertc service for details" and
    2. Relative to the long-winded response from the terminal after the sudo ./install ... command (PATH above), what should the new pifacertc script contain, why add another /etc/init.d/pifacertc . , and how to install it. It does not detail any of these returns. Finally, you have indicated that the install script may not have completed correctly. Based on all of the above, did the script complete successully or do I need to create another script of which Iis unknown to me.

    Dear lucie tozer:

    If you've arrived here without abandoning me I appeciate it. I just don't understand why an installation can proceed in entirely two different paths on identical systems but yielding different file structures. I'm sure its my mistake and I am confident I'll find the solution through your and many others help. Thanks again. Frank

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • clem57
    0 clem57 over 8 years ago in reply to fc-element

    Swap SD cards and if the problem moves, then the problem is on that card and is not identical!

    Clem

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 8 years ago in reply to fc-element

    Looking at the rest of the scripts output you just posted, it would appear that the installer did complete successfully, have you checked to see if the service is enabled sudo systemctl is-enabled pifacertc or you could try to find it in the list of services sudo systemctl -a even just trying to start the service manually might give some clues if it returns an error sudo systemctl start pifacertc

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • fc-element
    0 fc-element over 8 years ago in reply to Former Member

    Dear Ms. Tozer

    After attempting to get PiFace Real Time Clock to install on Raspberry Pi Zero over the last two months, I've to the possibility that the INSTALL PROGRAM at:  http://github.com/piface/PiFace-Real-Time-Clock does not address the Zero Model. The following is an extraction from the install code:

    #=======================================================================
    # NAME: start_on_boot
    # DESCRIPTION: Load the I2C modules and send magic number to RTC, on boot.
    #=======================================================================
    start_on_boot() {
        echo "Create a new pifacertc init script to load time from PiFace RTC."
        echo "Adding /etc/init.d/pifacertc ."

        if [[ $RPI_REVISION == "3" ]]; then
            i=1  # i2c-1
        elif [[ $RPI_REVISION == "2" ]]; then
            i=1  # i2c-1
        else
            i=0  # i2c-0
        fi

        cat > /etc/init.d/pifacertc  << EOF

     

    (end of code)

     

    Are these revisions referring to Software Revisions 2 and 3 or the Hardware Models 2 and 3 ?

    Does anyone know if Piface RTC can be installed on to a RPi ZERO model or not. ?

    Sorry for the persistence in my requests to you and the community but I'm running out of ideas but not patience.

    Am I am able to accomplish this task or not.

    Thank you.

    PS. The commands that you suggested,, such as:

    sudo systemctl is-enabled pifacertc

    sudo systemctl -a

    sudo systemctl start pifacertc

    all return the statements "PiFace RTC "not added, "failed to be added", "cannot be started" or generally notfound.

    Thanks for your help and hope someone out there will continue to respond.

    Frank

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 8 years ago in reply to fc-element

    A word on PI Revisions

    if you run the command  " cat  /proc/cpuinfo" you will get a bunch on information returned including the revision value

    Here is what I get on a Quark 1000 based Intel Galileo

    processor       : 0

    vendor_id       : GenuineIntel

    cpu family      : 5

    model           : 9

    model name      : Quark SoC X1000

    stepping        : 0

    cpu MHz         : 399.088

    cache size      : 16 KB

    fdiv_bug        : no

    f00f_bug        : no

    coma_bug        : no

    fpu             : yes

    fpu_exception   : yes

    cpuid level     : 7

    wp              : yes

    flags           : fpu vme pse tsc msr pae cx8 apic pbe nx smep

    bugs            :

    bogomips        : 798.17

    clflush size    : 32

    cache_alignment : 32

    address sizes   : 32 bits physical, 32 bits virtual

    power management:

    if I run this on a PI i get this

    processor       : 0

    model name      : ARMv7 Processor rev 4 (v7l)

    BogoMIPS        : 76.80

    Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32

    CPU implementer : 0x41

    CPU architecture: 7

    CPU variant     : 0x0

    CPU part        : 0xd03

    CPU revision    : 4

     

     

    processor       : 1

    model name      : ARMv7 Processor rev 4 (v7l)

    BogoMIPS        : 76.80

    Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32

    CPU implementer : 0x41

    CPU architecture: 7

    CPU variant     : 0x0

    CPU part        : 0xd03

    CPU revision    : 4

     

     

    processor       : 2

    model name      : ARMv7 Processor rev 4 (v7l)

    BogoMIPS        : 76.80

    Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32

    CPU implementer : 0x41

    CPU architecture: 7

    CPU variant     : 0x0

    CPU part        : 0xd03

    CPU revision    : 4

     

     

    processor       : 3

    model name      : ARMv7 Processor rev 4 (v7l)

    BogoMIPS        : 76.80

    Features        : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32

    CPU implementer : 0x41

    CPU architecture: 7

    CPU variant     : 0x0

    CPU part        : 0xd03

    CPU revision    : 4

     

     

    Hardware        : BCM2709

    Revision        : a02082

    Serial          : 00000000a1243900

    You can see the repeated parts for the 4 processor cores but also the revision statement near the end, you can see this does not match any of the test statements that simply expect a 2 or 3.... the reason for this is that Raspberry PI's made by sony have the 2, 3 style revision numbers, but the PI's made by Embest have the style above "a02082",

     

    now this also seems to have moved to the later style for both. here is a table I found

     

    RevisionRelease DateModelPCB RevisionMemoryNotes
    BetaQ1 2012B (Beta) ?256 MBBeta Board
    0002Q1 2012B1.0256 MB
    0003Q3 2012B (ECN0001)1.0256 MBFuses mod and D14 removed
    0004Q3 2012B2.0256 MB(Mfg by Sony)
    0005Q4 2012B2.0256 MB(Mfg by Qisda)
    0006Q4 2012B2.0256 MB(Mfg by Egoman)
    0007Q1 2013A2.0256 MB(Mfg by Egoman)
    0008Q1 2013A2.0256 MB(Mfg by Sony)
    0009Q1 2013A2.0256 MB(Mfg by Qisda)
    000dQ4 2012B2.0512 MB(Mfg by Egoman)
    000eQ4 2012B2.0512 MB(Mfg by Sony)
    000fQ4 2012B2.0512 MB(Mfg by Qisda)
    0010Q3 2014B+1.0512 MB(Mfg by Sony)
    0011Q2 2014Compute Module1.0512 MB(Mfg by Sony)
    0012Q4 2014A+1.1256 MB(Mfg by Sony)
    0013Q1 2015B+1.2512 MB ?
    0014Q2 2014Compute Module1.0512 MB(Mfg by Embest)
    0015 ?A+1.1256 MB / 512 MB(Mfg by Embest)
    a01040Unknown2 Model B1.01 GBUnknown
    a01041Q1 20152 Model B1.11 GB(Mfg by Sony)
    a21041Q1 20152 Model B1.11 GB(Mfg by Embest)
    a22042Q3 20162 Model B (with BCM2837)1.21 GB(Mfg by Embest)
    900092Q4 2015Zero1.2512 MB(Mfg by Sony)
    900093Q2 2016Zero1.3512 MB(Mfg by Sony)
    a02082Q1 20163 Model B1.21 GB(Mfg by Sony)
    a22082Q1 20163 Model B1.21 GB(Mfg by Embest)

     

    As you can see most current boards don't have what the script is looking for.

     

    To make this work for you, you can modify the script to just work for your board or change it to look for these additional identifiers.

     

    Now technically this should still work even without modification on most latest boards as it will default t I2C-0 if the revision is not matched.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 8 years ago in reply to fc-element

    See the procedure just above start_on_boot i.e.

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

    # NAME: set_revision_var

    # DESCRIPTION: Stores the revision number of this Raspberry Pi into

    #              $RPI_REVISION

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

    set_revision_var() {

        revision=$(grep "Revision" /proc/cpuinfo | sed -e "s/Revision\t: //")

        RPI2_REVISION=$((16#a01041))

        RPI3_REVISION=$((16#a02082))

        if [ "$((16#$revision))" -ge "$RPI3_REVISION" ]; then

            RPI_REVISION="3"

        elif [ "$((16#$revision))" -ge "$RPI2_REVISION" ]; then

            RPI_REVISION="2"

        else

            RPI_REVISION="1"

        fi

    }

     

    It is only recognizing RPi CPUs for hardware models 2 and 3.  I cannot see what the "Revision" value at the bottom of /proc/cpuinfo is because I do not have an RPi zero.  You might be able to modify these two procedures and make it work.

     

    Whether you are successful or not, I would suggest filing an issue at the github site if you have not yet already done so.  It would be great if you can develop a mod for the Pi Zero.  Good luck.

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

    Agreed, if the Pi zero doesnt have a compatable revision that the install script can use, it should be easy enough to do the install manually.

     

    Off the top of my head, I think the script was trying to work out the standard i2c port to register the real time clock with, different pi models must have different standard ports i2c-0, i2c-1 etc... I'll have a closer look when theres time unless someone else beats me to it!

     

    If someone finds a way to do it manually, it should be easy enough to make a new script or suggest a modification to the standard script for other people to use.

     

    -----------------------------

     

    I can see me having to get a pi zero in the near future (just wish they had onboard wifi...)

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

    Just realized my PI3 is using an I2C-1, not -0 so it would fail with this script.....

     

    simply run i2cdetect -l to see what is available to you

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 8 years ago in reply to fc-element

    Can you enable the i2c port using the raspi-config command and then do ls /dev

     

     

    You should see either i2c-0 or i2c-1 in the list, could you let us know which one it is please.

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

    Im going to try and re-write this script, rather than trying to determine the revision of the raspberry pi to workout which i2c port to address,

    it can be simplified to ls /dev | grep "i2c" This should get the device directly rather than guessing based on the model.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 8 years ago in reply to Former Member

    Here's my revised script, unfortunately I cant test it on a pi zero because I don't have one, nor do I have the real time clock module. The script isn't reliant upon the model or revision of the raspberry pi anymore. It finds the hardware i2c port from the devices list so it should be compatible with all models and revisions of the pi to date. If a raspberry pi is introduced in the future that utilizes multiple i2c ports/buses then this script would need to be modified but for the time being it should work fine.

     

    As a test on my Raspberry Pi 3 Model B, a ran the revised script, restarted and then searched for the MCP7941x device in the i2c-dev system folder, sure enough it was there. If I had the physical realtime clock module, this is the part of the system that would communicate with it.

     

    image

     

    Finally to the revised script:

     

    pifacetest.sh

    #!/bin/bash
    #: Description: Enables the required modules for PiFace Clock.
    # a modification of a script at:
    # https://github.com/piface/PiFace-Real-Time-Clock/blob/master/install-piface-real-time-clock.sh
    # this modification includes functionality with Raspberry Pi Zero
    # by making the model and revision checking redundant
    # credit for the original script goes to tompreston & pat3df at GitHub
    # modifications made by Lucie Tozer
    
    #=======================================================================
    # NAME: check_for_i2c_tools
    # DESCRIPTION: Checks if i2c-tools is installed.
    #=======================================================================
    check_for_i2c_tools() {
        dpkg -s i2c-tools > /dev/null 2>&1
        if [[ $? -eq 1 ]]; then
            echo "The package `i2c-tools` is not installed. Install it with:"
            echo ""
            echo "    sudo apt-get install i2c-tools"
            echo ""
            exit 1
        fi
    }
    
    #=======================================================================
    # NAME: final_message
    # DESCRIPTION: prints instructions for setting the clock
    #=======================================================================
    final_message(){
        echo "Now *reboot* and set your clock with:"
        echo ""
        echo '    sudo date -s "14 JAN 2014 10:10:30"'
        echo "    sudo hwclock --systohc"
        echo ""
    }
    
    #=======================================================================
    # NAME: get_i2c_device
    # DESCRIPTION: Obtains the working i2c port from the /dev file system
    #=======================================================================
    get_i2c_device(){
        I2C_DEVICE=$(ls /dev | grep "i2c")
        echo "i2c device on this model = " $I2C_DEVICE
        
        if [[ $I2C_DEVICE == "i2c-1" ]]; then
            I2C_PORT_NUMBER=1  # i2c-1
        else
            I2C_PORT_NUMBER=0  # i2c-0
        fi
        
        if [[ ! -e /sys/class/i2c-dev/i2c-$I2C_PORT_NUMBER ]]; then
            echo "Enable I2C by using:"
            echo ""
            echo "    raspi-config"
            echo ""
            echo "Then navigate to 'Advanced Options' > 'I2C' and select 'yes' to "
            echo "enable the ARM I2C interface."
            echo ""
            echo "Please Restart This Script Once The I2C Interface Has Been Enabled"
            echo "EXITING..."
            exit 1
        fi
    
    }
    
    #=======================================================================
    # NAME: start_on_boot
    # DESCRIPTION: Load the I2C modules and send magic number to RTC, on boot.
    #=======================================================================
    start_on_boot() {
        echo "Create a new pifacertc init script to load time from PiFace RTC."
        echo "Adding /etc/init.d/pifacertc ."
    
    
    
        cat > /etc/init.d/pifacertc  << EOF
    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides:          pifacertc
    # Required-Start:    udev mountkernfs \$remote_fs raspi-config
    # Required-Stop:
    # Default-Start:     S
    # Default-Stop:
    # Short-Description: Add the PiFace RTC
    # Description:       Add the PiFace RTC
    ### END INIT INFO
    
    . /lib/lsb/init-functions
    
    case "\$1" in
      start)
        log_success_msg "Probe the i2c-dev"
        modprobe i2c-dev
        # Calibrate the clock (default: 0x47). See datasheet for MCP7940N
        log_success_msg "Calibrate the clock"
        i2cset -y $I2C_PORT_NUMBER 0x6f 0x08 0x47
        log_success_msg "Probe the mcp7941x driver"
        modprobe i2c:mcp7941x
        log_success_msg "Add the mcp7941x device in the sys filesystem"
        # https://www.kernel.org/doc/Documentation/i2c/instantiating-devices
        echo mcp7941x 0x6f > /sys/class/i2c-dev/i2c-$I2C_PORT_NUMBER/device/new_device
        log_success_msg "Synchronise the system clock and hardware RTC"
        hwclock --hctosys
        ;;
      stop)
        ;;
      restart)
        ;;
      force-reload)
        ;;
      *)
        echo "Usage: \$0 start" >&2
        exit 3
        ;;
    esac
    EOF
        chmod +x /etc/init.d/pifacertc
    
        echo "Install the pifacertc init script"
        update-rc.d pifacertc  defaults
    }
    
    #=======================================================================
    # MAIN
    #=======================================================================
    # check if the script is being run as root
    if [[ $EUID -ne 0 ]]
    then
        printf 'This script must be run as root.\nExiting..\n'
        exit 1
    fi
    
    
    
    I2C_PORT_NUMBER=0
    I2C_DEVICE=""
    
    check_for_i2c_tools &&
    get_i2c_device &&
    start_on_boot &&
    final_message

     

    I kept as much of the original as possible so it should read similarly and changes should be easily noticed.

     

    here's an easy way to install:

    1) copy the script to clipboard

    2) log on to your raspberry pi with a terminal

    3) cd ~/

    4) nano ./pifacetest.sh

    5) Paste clipboard into nano (ctrl + shift + v)

    6) wait a few seconds for nano to buffer the clip board

    7) once clipboard has pasted press ctrl + o to write the file

    8) press ctrl + x to exit nano

    9) sudo chmod +x ./pifacetest.sh to enable the file to be executed

    10) finally run the script sudo ./pifacetest.sh

     

    If your having trouble creating the file, Im happy to upload it to a temporary location so you can use wget to download it directly to the raspberry pi.

    • Cancel
    • Vote Up +1 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