[app]温度传感器测试程序
2024-09-25 05:52:37
刚开始去读/dev/i2c-1, 但是在设置地址的时候,始终错误,返回-1, 所以最后还是用了sys接口
/*******************************************
* Description: Read temperature sensor from LM75
* Author: Aaron.gao
* Data: 20170524
* Histroy:
* 1. NULL
* ****************************************/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <linux/i2c-dev.h>
#include <stdlib.h>
#include <fcntl.h>
#include <termios.h> /* main func */
int main(int argc, char **argv)
{
int ret, fd;
char buffer[];
int value;
float temp = 0.0; while()
{
/* open device */
fd = open("/sys/bus/i2c/devices/i2c-1/1-004f/hwmon/hwmon0/temp1_input", O_RDONLY);
if( fd < )
{
printf("fd is %d\r\n", fd);
printf("open i2c device-lm75 failed!\r\n");
exit();
} ret = read(fd, buffer, );
if(ret < )
{
printf("read error\r\n");
}
value = atoi(buffer);
memset(buffer, , strlen(buffer));
temp = value / 1000.0;
printf("environment temperature is %.2lfC\r\n", temp);
sleep(); close(fd);
} return ;
}
最新文章
- [ASP.NET Core] Middleware
- mysql学习之触发器
- 关于电磁场中的E.B.D.H的理解
- JS DOM元素
- linux下的符号链接和硬链接
- BZOJ1143 [CTSC2008] 祭祀river
- Codeforces Round #277 (Div. 2)
- Swift—静态方法-备
- Apache Flink
- HDU - 5234 Happy birthday
- IBM芯片新功能:诊断癌症
- 通过nginx的fastcgi_param来设置环境变量
- SP8791 DYNALCA - Dynamic LCA 解题报告
- Go语言排序算法实现
- angular 2 - 006 change detection 脏治检查 - DC
- Python中os模块使用方法
- XSSExcelUtil
- 洛谷 P1603 斯诺登的密码
- IOS设计模式第四篇之装饰设计模式的类别设计模式
- ISE联合modelsim功能仿真和综合后仿真