华清远见上海中心22071班
使用iic读取si7006数值
iic读取si7006温湿度
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include "si7006.h"
int main(int argc, const char *argv[])
{
int fd = open("/dev/si7006", O_RDWR);
if (fd == -1)
{
perror("open");
return -1;
}
int temp, humi;
float tempf, humif;
while (1)
{
ioctl(fd, GET_TEMP, &temp);
ioctl(fd, GET_HUMI, &humi);
humi = ntohs(humi);
temp = ntohs(temp);
tempf = 175.72 * temp / 65536 - 46.85;
humif = 125.0 * humi / 65536 - 6;
if (tempf >= 28)
{
ioctl(fd, LED_ON);
}
else
{
ioctl(fd, LED_OFF);
}
printf("TEMP: %f HUMI:%f\n", tempf, humif);
sleep(1);
}
return 0;
}