#include <stdio.h> #include <string.h> #include <stdlib.h> #include <fcntl.h> const char thermal_path[] = "/sys/class/thermal/thermal_zone0/temp"; int main(int argv, char *argc[]) { int fd = 0; int ret = 0; int i; char mbuf[128] = {0,}; float temp = 0.0; fd = open(thermal_path, O_RDONLY); if(fd < 0) { printf("open file[%s] failed\n", thermal_path); return (0); } while(1) { memset(mbuf, 0, 128); lseek(fd, 0, SEEK_SET); ret = read(fd, mbuf, 128); if(ret < 0) { printf("read file failed\n"); close(fd); return (0); } temp = atof(mbuf); temp = temp / 1000.0; printf("thermel temp = %f\n", temp); sleep(1); } close(fd); return (0); }
板载温度计的采集

官方已经提供了温度计的实现,所以我们直接打开文件即可,前有两位网友使用cat命令来读取,楼主这里使用文件打开的方式读取,测试效果还是不错的,现将源代码分享出来,供大家借鉴:
关键词: 温度计 采集 imx6







回复
打赏帖 | |
---|---|
【Zephyr】MCXN947 Zephyr 开发入门适配shell被打赏20分 | |
【我要开发板】6.联合MATLAB记录数据被打赏50分 | |
【瑞萨RA2E1开发板】:使用ADC功能实现位移传感器采集方案被打赏20分 | |
【nRF7002DK】基于sht30的温湿度计被打赏20分 | |
【nRF7002DK】日志打印被打赏20分 | |
【换取手持示波器】RGB屏幕移植ARM-2D库被打赏35分 | |
【分享开发笔记,赚取电动螺丝刀】分享一下如何解决瑞萨RA2E1使用printf编译报错问题被打赏27分 | |
rtthread硬件加密-5hash加密分析被打赏10分 | |
【换取手持示波器】Mongoose 零代码创建网页仪表盘被打赏33分 | |
【分享开发笔记,赚取电动螺丝刀】基于.Net6.0 WPF简单做一个MQTT收发小工具被打赏24分 |