#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
回复
我要赚赏金打赏帖 |
|
|---|---|
| 【S32K3XX】LPSPI参数配置说明被打赏¥21元 | |
| 在WT9932C61-TINY上实现超声波测距被打赏¥22元 | |
| 基于WT9932C61-TINY的环境构建及OLED屏驱动测试被打赏¥20元 | |
| 【S32K3XX】Core-to-Core 中断使用被打赏¥21元 | |
| 「AI编程记录--含源码」用一晚上的时间写一个esp32的示波器被打赏¥19元 | |
| STM32C0116DK开发探索记(3)被打赏¥30元 | |
| STM32C0116DK开发探索记(2)被打赏¥24元 | |
| STM32C0116DK开发探索记(1)被打赏¥29元 | |
| 谨防极海G32M3101电机评估板易跌落的陷阱被打赏¥24元 | |
| 【全网首拆】M5STACK ATOM系列开发板拆解 / AtomS3R-CAM摄像头更换方法(提高10倍像素)被打赏¥26元 | |
我要赚赏金
