RaspberryPiVcgencmd A python library to access Raspberry Pi vcgencmd command

To access some of the lower level aspects of the Raspberry Pi’s config you can use the built in command vcgencmd. This is a useful on the command line but to easily access it in a program you need to parse the output.

I am planning to use this command to store data like the temperature of the Raspberry Pi in python. Therefore to easily access the data I decided to make a small python module to do this.

RaspberryPiVcgencmd Python Module

This python module is a wrapper around the vcgencmd command to allow easy access to some of the internal data of the Raspberry Pi.

To include this module in your git based project you can run

git submodule add https://github.com/chewett/RaspberryPiVcgencmd
git commit

Now I have run the above command the library is installed as a git submodule. This means I can now use it in my python script.

So that I can use the library in my current script I need to import the submodule. To import this module I can add the below import statement to my script.

from RaspberryPiVcgencmd.RaspberryPiVcgencmd import RaspberryPiVcgencmd

This will make the RaspberryPiVcgencmd class available to be used in the current python file. Once I have imported it I can use the library to get the firmware version adding the below to the script.

vcgencmd = RaspberryPiVcgencmd()
print vcgencmd.get_version()

Using the vcgencmd object you can now call any of the functions available in the library.

Full details of what vcgencmd can do is available on elinux.

Current exposed functions

The majority of the useful output from vcgencmd is exposed in the class with the below functions

  • get_cpu_temp – Gets the system temperature of the soc in Celsius or Fahrenheit
  • get_ram_split – Gets the memory split between the gpu and cpu
  • measure_volts – Measures the voltage of various internal components
  • measure_clock – Mesures the clock frequency of various internal components
  • is_codec_available – Returns whether the codec specificed video/audio codec is available on the Raspberry Pi
  • get_version – Gets the version of the firmware installed on the Raspberry Pi
  • set_display_power – Allows turning off/on the video output of the Raspberry Pi

The RaspberryPiVcgencmd module is available on github and is licensed under the MIT licence. If you have any comments, suggestions or improvements you can comment below or raise a github issue.

Leave a Reply

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