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.

VCHI initialization failed Raspberry Pi Fixed

vcgencmd get_mem arm VCHI initialization failed
Example showing VCHI initialization failed error

If when running vcgencmd on a raspberry pi you get VCHI initialization failed then you need to add the video group to your user. The vcgencmd tool requires you have this group role so without it, it will give VCHI initialization failed.

To add the user group to your user you can run:

sudo usermod -aG video <username>

Where <username> is the user you want to run the vcgencmd command with. This command adds the video group to the the user you specify.

Once you have ran the command any new logins will run the command successfully. Logging out and back into the pi will let you use the command.

Why this problem occurs

This issue happens when you try and use the vcgencmd command with a user that isn’t a member of the video group. This typically happens when you create a new user for the raspberry pi and don’t give it the same groups that the pi user has.

The solution above fixes this by adding the correct video group to the created user.