Facebook Twitter Instagram Pinterest YouTube
    Trending
    • Add Kodi to RetroPie Menu
    • Disable Auto-login in Raspberry Pi OS
    • Raspberry Pi Cloud Storage with MEGA
    • RetroPie Temperature Monitor from Menu
    • Pi Pico Pinout and Power Pins
    • Install Arduino IDE on Raspberry Pi
    • Raspberry Pi 400 SSD Upgrade
    • Raspberry Pi Temperature Monitoring
    Facebook Twitter Instagram Pinterest YouTube RSS
    Raspberry Pi SpyRaspberry Pi Spy
    • Home
    • Categories
      • General
      • Hardware
      • Programming
      • Python
      • Software
      • Tutorials & Help
    • BerryClip
      • BerryClip Instructions
      • BerryClip Plus Instructions
      • Videos & Reviews
    • Buy
      • Buy Pi
      • Buy Pi Accessories
      • Buy Books
    • Tools
      • Ultimate Raspberry Pi Alexa Skill
      • Pi Power Estimator App
      • Pi-Lite 14×9 LED Matrix Sprite Editor
      • RPiREF Pin-out Reference App
      • Simple Ohm’s Law Calculator
      • Web Sites & Links
    • Tutorials & Help
        Featured
        November 9, 20200

        Raspberry Pi Temperature Monitoring

        Recent
        May 6, 2022

        Add Kodi to RetroPie Menu

        February 26, 2022

        Disable Auto-login in Raspberry Pi OS

        February 2, 2022

        Raspberry Pi Cloud Storage with MEGA

      1. Contact Us
      2. Site Map
      Raspberry Pi SpyRaspberry Pi Spy
      You are at:Home»Hardware»Getting Your Raspberry Pi Revision Number Using Python
      Raspberry Pi 3

      Getting Your Raspberry Pi Revision Number Using Python

      2
      By Matt on September 5, 2012 Hardware, Python, Tutorials & Help

      There have now been a number of different PCB revisions which have made small changes to the design of the Raspberry Pi PCB. In the latest revision some of these changes may affect the operation of Python code developed for earlier versions. In order to make you script react to these changes you may need to identify the board revision so your script can take appropriate action.

      The following Python function “getrevision()” can be used to return a string containing the hardware revision number. This is a four character string such as “0002”.

      Here is the Python function :

      def getrevision():
        # Extract board revision from cpuinfo file
        myrevision = "0000"
        try:
          f = open('/proc/cpuinfo','r')
          for line in f:
            if line[0:8]=='Revision':
              length=len(line)
              myrevision = line[11:length-1]
          f.close()
        except:
          myrevision = "0000"
      
        return myrevision

      If you include this definition at the beginning of your Python script you can use it to set a variable equal to the board revision number :

      myrevision = getrevision()

      If this variable is equal to “0000” then there was an error while running the function.

      Raspberry Pis that have been overvolted will have a code prefixed with “100”. If I overvolted my device I would end up with a hardware revision code of “1000002”.

      At the time of writing your board revision number could be “0002”, “0003”, “0004”, “0005” or “0006”. You can use the Checking Your Raspberry Pi Board Version post to double check the results of this Python function.

      Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
      Previous ArticleGetting Your Raspberry Pi Serial Number Using Python
      Next Article Raspberry Pi Board Revisions

      Related Posts

      Add Kodi to RetroPie Menu

      Disable Auto-login in Raspberry Pi OS

      Raspberry Pi Cloud Storage with MEGA

      2 Comments

      1. joosteto on October 20, 2012 9:34 pm

        Just a nitpick, but

        length=len(line)
        myrevision = line[11:length-1]

        could be replaced by the shorter and simpler:

        myrevision = line[11:-1]

        Or, the whole function could be replaced by the even shorter but not simpler:

        def getrevision():
        return ([l[11:-1] for l in open('/proc/cpuinfo','r').readlines() if l[:8]=="Revision"]+['0000'])[0]

        Reply
        • Alexandr Geller on March 23, 2018 2:15 pm

          JOOSTETO , you trying to save on code lines ?
          it better to be human readable

          Reply

      Leave A Reply Cancel Reply

      This site uses Akismet to reduce spam. Learn how your comment data is processed.

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      January 7, 2022

      RetroPie Temperature Monitor from Menu

      January 24, 2021

      Pi Pico Pinout and Power Pins

      Categories
      • 1-wire
      • 3D Printing
      • Add-ons
      • BBC Micro:bit
      • BerryClip
      • Books
      • Camera Module
      • Cases
      • Events
      • General
      • Hardware
      • I2C
      • Infographics
      • Interfaces
      • Minecraft
      • Model A+
      • Model B+
      • News
      • Pi Models
      • Pi Zero
      • Power
      • Programming
      • Python
      • Raspberry Pi OS
      • Raspbian
      • RetroGaming
      • Robotics
      • Sensors
      • Software
      • SPI
      • Tutorials & Help
      Tags
      3D Printing Arduino audio battery berryclip Birthday bluetooth cambridge camera CamJam DigiMakers display games GPIO I2C interface Kickstarter LCD LED Linux media Minecraft Model A Model B motionEyeOS PCB photography photos Pi-Lite portable power python Raspberry Jam Raspberry Pi Bootcamp raspbian Retrogaming retroPie screen SD card security sensor SPI temperature ultrasonic video
      Raspberry PI Related
      • Adafruit Blog
      • Average Maker
      • Official RaspBerry Pi Site
      • Raspberry Pi Pod
      • RasPi.tv
      • RaspTut
      • Stuff About Code
      Tech Resources
      • MattsBits – Pi Resources
      • Microbit Spy
      • Technology Spy
      Archives
      About

      Unofficial site devoted to the Raspberry Pi credit card sized computer offering tutorials, guides, resources,scripts and downloads. We hope to help everyone get the most out of their Pi by providing clear, simple articles on configuring, programming and operating it.

      Popular Posts
      September 19, 2014

      Top 5 Reasons The Raspberry Pi Sucks

      July 27, 2012

      16×2 LCD Module Control Using Python

      October 20, 2013

      Analogue Sensors On The Raspberry Pi Using An MCP3008

      Recent Posts
      May 6, 2022

      Add Kodi to RetroPie Menu

      February 26, 2022

      Disable Auto-login in Raspberry Pi OS

      February 2, 2022

      Raspberry Pi Cloud Storage with MEGA

      Facebook Twitter Instagram Pinterest YouTube RSS

      Entries RSS | Comments RSS

      This site is not associated with the official Raspberrypi.org site or the Raspberry Pi Foundation. Raspberry Pi is a trademark of the Raspberry Pi Foundation.

      Copyright © 2022 - All Rights Reserved - Matt Hawkins

      Type above and press Enter to search. Press Esc to cancel.