目前网络上流传的检测树莓派 CPU 和 GPU 的温度主要是两个脚本,例子在这里(树莓派-GPIO、CPU、温度、内存 和 用Python小程序获取树莓派的CPU和GPU温度)
我分别认真读了两段脚本,发现一个问题,截图如下:
如图所示,两个红框圈出来的地方,读取的是同样的内容,但一个是作为 CPU温度,另一个是作为 GPU温度。并且,运行结果也不一样,截图如下:
如图,其中第一个跑的脚本是对应第一图中右边一个脚本,第二个跑的脚本对应第一图中左边一个脚本。时间相差不超过2秒。
我的设备情况是:树莓派 2代,CPU 和 GPU 均贴了一块铜质散热片,未装入盒子内,使用 iPad mini 1代的充电头和摩托罗拉手机的 micro USB 线供电,使用网线接入路由器,采用 SanDisk Class10 8GB TF卡,刷入的系统为 2015-02-16-raspbian-wheezy,入手后未安装其他软件。
想问一下,到底哪一个才是正确的。
2015-03-11更新:
根据答案部分@eziozl 前辈的回答,查看了他提供的wiki,注意到下图中这样一部分内容:
这里的资料表明,vcgencmd measure_temp
测出的是 CPU 的核心温度,那么现在的问题是,根据@沙渺 前辈的回答:以CPU名义注册的温度传感器也只有一个,位于/sys/class/thermal/thermal_zone0
。所以这两者都表示 CPU温度,所以想问,GPU 的核心温度怎么获取?
而根据@eziozl 前辈给出的另一个链接里看到如下图这样的内容:
这是否说明,其实所谓获取到的 CPU温度 就是 CPU 和 GPU 的温度?如何区分两者呢?
There is of course only one
vcgencmd
, located in/opt/vc/bin/vcgencmd
.vcgencmd
and its associated/opt/vc
software package are all closed source programs that communicate with VideoCore (you can tell by the name).There is only one temperature sensor registered in the name of the CPU, located at
/sys/class/thermal/thermal_zone0
.So the CPU and GPU temperatures are measured separately, and of course both are trusted. This is especially true for the Pi2 which actually has 4 CPU cores.
The phenomenon of unstable measurement results, specifically, the update of temperature data is actually "floating". Even at the same point in time (the difference does not need to be 1 second), it is possible to read two data values that are very different. You can try the following command to observe this phenomenon.
while :; do cat /sys/class/thermal/thermal_zone0/temp; done
while :; do vcgencmd measure_temp; done
But I really can’t explain why.
They are all accurate. It is recommended that you execute two programs at the same time to take a look. These two files are system-generated files that can reflect the current temperature obtained by the os from the CPU.
For details, please refer to: https://wiki.archlinux.org/index.php/Raspberry_Pi
http://elinux.org/RPI_vcgencmd_usage