这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界» 论坛首页» 活动中心» 板卡试用» 板载温度计的采集

共30条 1/3 1 2 3 跳转至

板载温度计的采集

院士
2019-09-28 23:50:00 打赏
官方已经提供了温度计的实现,所以我们直接打开文件即可,前有两位网友使用cat命令来读取,楼主这里使用文件打开的方式读取,测试效果还是不错的,现将源代码分享出来,供大家借鉴:
#include  #include  #include  #include  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); }





关键词: 温度计 采集 imx6

专家
2019-09-29 09:44:33 打赏
2楼

太棒了,晚上我也尝试一下,争取能网页看温度


专家
2019-09-29 10:27:28 打赏
3楼

赶紧测试下


高工
2021-04-11 10:21:16 打赏
4楼

试一试


菜鸟
2021-04-19 12:42:49 打赏
5楼

学习


高工
2021-05-02 06:26:11 打赏
6楼

谢谢分享


专家
2021-05-02 08:53:20 打赏
7楼

学习学习


院士
2021-05-02 21:41:23 打赏
8楼
谢谢

院士
2021-05-02 21:41:42 打赏
9楼
谢谢看呢

院士
2021-05-02 21:41:51 打赏
10楼
学习学习

共30条 1/3 1 2 3 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册]