如何读取树莓派4B处理器(CPU)的实时温度
发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,这篇文章将为大家详细讲解有关如何读取树莓派4B处理器(CPU)的实时温度,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。读取树莓派4B处理器(CPU)的
千家信息网最后更新 2024年09月22日如何读取树莓派4B处理器(CPU)的实时温度
这篇文章将为大家详细讲解有关如何读取树莓派4B处理器(CPU)的实时温度,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
读取树莓派4B处理器(CPU)的实时温度
树莓派发布4B后,性能提升了不少,但是温度也是高的不行,所以最好配置一个小风扇和散热片还是比较好的,效果明显。
1.Shell命令读取
打开终端
cd /sys/class/thermal/thermal_zone0
查看温度
cat temp
树莓派的返回值
35050
返回值除以1000为当前CPU温度值。即当前温度为53摄氏度。如下图所示
2.编写一段c语言程序读取
程序源代码
温度是在 /sys/class/thermal/thermal_zone0/temp 文件下看的
编写代码
创建程序文件 read_cpu_temp.c 并打开编写代码
//读取树莓派4B处理器(CPU)的实时温度// 编译// gcc -o read_cpu_temp read_cpu_temp.c// 运行// ./read_cpu_temp#include#include #include #include #include #define TEMP_PATH "/sys/class/thermal/thermal_zone0/temp"#define MAX_SIZE 32int main(void){ int fd; double temp = 0; char buffer[MAX_SIZE]; int i; while(i < 100) { i+=1; //延时1s sleep(1); //打开文件 fd = open(TEMP_PATH,O_RDONLY); if(fd < 0) { fprintf(stderr,"Failed to open thermal_zone0/temp\n"); return - 1; } //读取文件 if(read(fd,buffer,MAX_SIZE) < 0) { fprintf(stderr,"Failed to read temp\n"); return -1; } //计算温度值 temp = atoi(buffer) / 1000.0; //打印输出温度 printf("Temp:%.4f\n",temp); //关闭文件 close(fd); }}
编译运行结果
gcc -o read_cpu_temp read_cpu_temp.c
编译程序出现三个警告,可以不用管它,生成可以执行文件read_cpu_temp
输入./read_cpu_temp运行程序
./read_cpu_temp
(我安装了风扇和散热片以及外壳,大概平均在36摄氏度左右)
3. 编写Erlang程序读取
编写代码
创建程序文件 read_cpu_temp.erl 并打开编写代码
%%%-------------------------------------------------------------------%%% @author SummerGao%%% @copyright (C) 2020,%%% @doc%%%%%% @end%%% Created : 15. 7月 2020 13:59%%%--------------------------------------------------------------------module(read_cpu_temp).-author("SummerGao").%% API-export([loop/0]).loop() -> {ok, Original} = file:read_file("/sys/class/thermal/thermal_zone0/temp"), [A, _] = binary:split(Original, [<<"\n">>]), T = binary_to_integer(A) / 1000, io:format("Temp ℃ : ~p~n", [T]), timer:sleep(1000), loop().
编译运行结果
Erlang/OTP 22 [erts-10.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]Eshell V10.4 (abort with ^G)1> c(read_cpu_temp). {ok,read_cpu_temp}2> read_cpu_temp:loop().
获取硬件相关信息
查看cpu信息
lscpu
查看内存信息
free -h
关于如何读取树莓派4B处理器(CPU)的实时温度就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
温度
文件
程序
树莓
处理器
实时
处理
代码
编译
运行
信息
内容
文章
更多
知识
篇文章
结果
风扇
散热片
不行
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
前后端数据库之间的协议
守望先锋数据库app
为什么360网络安全防护
报告服务器大神请自重
马鞍山企业软件开发公司
自然资源数据库建设标准
怎么装材质包手机版服务器
成都栋格互联网科技有限公司
我的世界服务器龙域
数据库data输入
功能强大的电脑软件开发平台
大麦打印服务器设置完怎么登
岢岚中学加强网络安全
人工智能和数据库哪个前景好
ark服务器推荐倍率
金格数据库 中间件
盐城无线网络技术口碑推荐
2021年网络安全事故
证书 网络安全
天空在线网络技术
电子资源数据库有哪些搜索方式
阿里云服务器到期后发票
恒为服务器制造
网络安全重点保障工作
澜起科技第四代津逮服务器
关于扫黄打非网络安全的资料
福建数据软件开发服务推广
掌控网络安全学院
网络安全兴趣小组招人
nextlib 数据库