刚开始去读/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 ;
}

最新文章

  1. [ASP.NET Core] Middleware
  2. mysql学习之触发器
  3. 关于电磁场中的E.B.D.H的理解
  4. JS DOM元素
  5. linux下的符号链接和硬链接
  6. BZOJ1143 [CTSC2008] 祭祀river
  7. Codeforces Round #277 (Div. 2)
  8. Swift—静态方法-备
  9. Apache Flink
  10. HDU - 5234 Happy birthday
  11. IBM芯片新功能:诊断癌症
  12. 通过nginx的fastcgi_param来设置环境变量
  13. SP8791 DYNALCA - Dynamic LCA 解题报告
  14. Go语言排序算法实现
  15. angular 2 - 006 change detection 脏治检查 - DC
  16. Python中os模块使用方法
  17. XSSExcelUtil
  18. 洛谷 P1603 斯诺登的密码
  19. IOS设计模式第四篇之装饰设计模式的类别设计模式
  20. ISE联合modelsim功能仿真和综合后仿真

热门文章

  1. java中static、this、super、final用途、用法及实例
  2. mysql中的order by
  3. Oracle LISTENER 主机名修改为IP地址后LISTENER无法监听到实例 oracle监听错误与hosts文件配置
  4. 使用 HTML5 History 新特性增强 Ajax 的体验(转)
  5. python学习笔记——守护进程
  6. python学习笔记—— 多进程中的 孤儿进程和僵尸进程
  7. linux内核线程,进程,线程
  8. Linux内核(10) - 内核中的链表
  9. Python多线程之线程创建和终止
  10. php - 中文字符串分割