获取树莓派cpu温度的方法

树莓派vcgencmd命令查看硬件状态

1.vcgencmd commands可看到vcgencmd可接的指令

 2. 在python中读取树莓派cpu温度

因为os.popen返回的是一个文件,因此要用readline()进行文件的读取

print(os.popen('vcgencmd measure_temp').readline())

也可用replace函数使得返回一个温度数值

import os
rec = os.popen('vcgencmd measure_temp').readline()
print(rec.replace("temp=","").replace("'C\n",""))

猜你喜欢

转载自www.cnblogs.com/jynote/p/12462958.html