Showing posts with label vcgencmd. Show all posts
Showing posts with label vcgencmd. Show all posts

Sunday, November 8, 2020

Run vcgencmd on Ubuntu for Raspberry Pi, fix "VCHI initialization failed"

vcgencmd is a command line utility that can get various pieces of information from the VideoCore GPU on the Raspberry Pi. Much of the information available is only of use to Raspberry Pi engineers, but there are a number of very useful options available to end users that will be described here.

In my trial on Ubuntu Desktop for Raspberry Pi, vcgencmd is installed by default. But fail with error of "VCHI initialization failed".

To fix it, add the video group to your user:

$ sudo usermod -aG video <username>


After log-out and log-in.



Saturday, October 10, 2020

Watch CPU frequency of Raspberry Pi: adding menu item of CPUFreq frontend and using vcgencmd.

This video show how to watch CPU frequency of Raspberry Pi running Rspberry Pi OS (tested on Raspberry Pi 4):
- adding menu item of CPUFreq frontend
- or using vcgencmd. 

vcgencmd is a command line utility that can get various pieces of information from the VideoCore GPU on the Raspberry Pi, details refer to Raspberry Pi Document of vcgencmd.

To get the actual speed of ARM cores, enter the command in Terminal:

$ vcgencmd measure_clock arm

You can also keep watching vcgencmd result in Terminal using the watch command.

$ watch -n 1 vcgencmd measure_clock arm

Alternatively, you can also check it in the file /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq, where cpu0 can be cpu0~4 for Raspberry Pi 4 with 4 core. Read HERE.


Saturday, March 28, 2015

Python to get core temperature of Raspberry Pi

On Raspberry Pi/Raspbian, the command "vcgencmd measure_temp" shows core temperature. It's a Python example to get current temperature.


import os 

#Get CPU temperature using 'vcgencmd measure_temp'                                      
def measure_temp():
    temp = os.popen('vcgencmd measure_temp').readline()
    return(temp.replace("temp=","").replace("'C\n",""))

print(measure_temp())



more:
- Display Raspberry Pi CPU temperature graphically, using Python 2 with Matplotlib

Wednesday, December 25, 2013

Read Raspberry Pi system temperature in Java

This exercise show how to read Pi's system temperature in Java, using ProcessBuilder with command of "vcgencmd measure_temp".

Read Raspberry Pi system temperature in Java
Read Raspberry Pi system temperature in Java

import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.Scanner;

/**
 * @web helloraspberrypi.blogspot.com
 */
public class readTemp {

    public static void main(String[] args) {

        // Example to run "dir" in Windows
        String[] command = {"vcgencmd", "measure_temp"};
        StringBuilder cmdReturn = new StringBuilder();
        try {
            ProcessBuilder processBuilder = new ProcessBuilder(command);
            Process process = processBuilder.start();
            
            try (InputStream inputStream = process.getInputStream()) {
                int c;
                while ((c = inputStream.read()) != -1) {
                    cmdReturn.append((char) c);
                }
            }
            
            System.out.println(cmdReturn.toString());
            String stringTemp = measure_temp_toString(cmdReturn.toString());
            System.out.println("Get the numerical part as String: " + stringTemp);
            System.out.println("converte to float: " + cnvStringToFloat(stringTemp));

        } catch (IOException ex) {
            System.out.println(ex.toString());
        }
        
    }
    
    private static String measure_temp_toString(String src){
        return src.replaceAll("[^0123456789.]", "");
    }
    
    private static float cnvStringToFloat(String src){

        float result = (float)0.0;
        Scanner scanner = new Scanner(src);
        while(scanner.hasNext()){
            if(scanner.hasNextFloat()){
                result = scanner.nextFloat();
            }else{
                scanner.next(); //ignore
            }
        }
        return result;
    }
    
}

Wednesday, December 4, 2013

Display running frequency of Raspberry Pi in command line

To display cpu's maximum, mimimum and current frequency, we can use the command:

  • $ cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
  • $ cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq
  • $ sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq
    (need permission)
Display CPU frequency
Display CPU frequency of Raspberry Pi
We can also use vcgencmd command
  • $ vcgencmd measure_clock arm
    to display ARM processor's clock speed. IT will be something like:
    frequency(45)=700000000
    means 700,000,000 Hz or 700MHz
  • vcgencmd measure_clock core
    to display system's core frequency, like:
    frequency(1)=250000000
    250,000,000 Hz, or 250MHz.
Display clock speed with vcgencmd command
Display clock speed with vcgencmd command
For more RPI vcgencmd usage, refer http://elinux.org/RPI_vcgencmd_usage

Tuesday, October 22, 2013