#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); }
板载温度计的采集
官方已经提供了温度计的实现,所以我们直接打开文件即可,前有两位网友使用cat命令来读取,楼主这里使用文件打开的方式读取,测试效果还是不错的,现将源代码分享出来,供大家借鉴:
关键词: 温度计 采集 imx6
回复
有奖活动 | |
---|---|
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
【有奖活动】智能可穿戴设备AR/VR如何引领科技新潮流! | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
【有奖活动】震撼来袭!这场直播将直击工程师的心灵! |
打赏帖 | |
---|---|
如何实现基于NXPiMX.RT1021的BH1730采集被打赏50分 | |
【换取手持数字示波器】AHT10温度检测分享被打赏40分 | |
【换取手持数字示波器】ACM32F070开发板点亮LCD屏和触控按键,串口,ADC被打赏40分 | |
【换取手持数字示波器】ACM32F070LCD屏和触控按键功驱动蜂鸣器分享被打赏40分 | |
【换取手持数字示波器】国民技术PWM功能知识分享被打赏40分 | |
【换取手持数字示波器】放大器运放知识分享被打赏40分 | |
【分享评测,赢取加热台】+开关电源AC输入知识分享被打赏30分 | |
【换取手持数字示波器】N32G430点亮数码管与串口打印、ADC被打赏40分 | |
老胖子聊电路--分析一个反馈电路被打赏50分 | |
【换取手持数字示波器】+点亮WS2812RGB灯被打赏50分 |