#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
回复
| 有奖活动 | |
|---|---|
| 硬核工程师专属补给计划——填盲盒 | |
| “我踩过的那些坑”主题活动——第002期 | |
| 【EEPW电子工程师创研计划】技术变现通道已开启~ | |
| 发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
| 【EEPW在线】E起听工程师的声音! | |
| 高校联络员开始招募啦!有惊喜!! | |
| 【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
| 送您一块开发板,2025年“我要开发板活动”又开始了! | |
我要赚赏金
