树莓派:3. 树莓派采集温度-使用AD7416

1. AD7416简介

1. 概述

AD7416是有8个管脚的温度监测器。该温度监测器可通过多路复用器的0通道进行访问。片上寄存器可编程控制极限温度,当温度超过极限时漏极开路温度过热指示器(OTI)处于工作状态。AD7417和AD7418分别是10位,4通道和单通道的ADC,其片上温度传感器可用2.7V~5.5V电压供电。该装置包含一个约15μs的转换器,5通道多路复用器,温度传感器,时钟振荡器,跟踪-保持器和一个2.5V的参考电压。

2. 特点

●10位ADC,转换时间15μs和30μs     
●单通道和4单通道模拟输入 
●片上跟踪-保持     
●温度过热指示 
●转换结束自动掉电 
●供电电压范围:2.7V~5.5V     
●I2C兼容串口 
●串行总线地址允许八个AD7416/AD7417连接到一条总线上     
●AD7416可代替LM75

3. 封装

这里写图片描述

2. 编写应用软件读取温度

1. 软件代码

这部分代码将编译成为CGI程序,供BOA调用

hello.c
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include <linux/i2c-dev.h>
#include <errno.h>
#define I2C_ADDR 0x49
typedef unsigned char uint8;

static int read_HWclock(int fd, char buff[], int addr, int count)
{
    unsigned char ZorF; //正还是负
    int res;
    unsigned int tempeture = 0;
    float wendu;

    if(write(fd,&addr,1)!=1)        //写地址失败
    {
        return -1;   
    }

    res=read(fd,buff,count);

    tempeture = buff[0];

    tempeture=tempeture<<8;
    tempeture=tempeture|buff[1];
    tempeture=tempeture>>6;

    if(buff[0]&0x80) //负
    {
        tempeture=tempeture-0x01;
        tempeture=~tempeture; //变回原码
        tempeture=tempeture&0x03FF;
        wendu = (float)((double)tempeture/4);
        ZorF=0;
    }
    else //正
    {
        wendu = (float)((double)tempeture/4);
        ZorF=1;
    }
    printf("%.2f",wendu);
    return res;
}

int main(void)
{
    time_t now;   
    struct tm *timenow;   
    char strtemp[255];   

    int fd;
    char buf[3]; 
    char val,value;
    float flight;

    fd=open("/dev/i2c-1",O_RDWR);
    if(fd<0){
        printf("err open file:%s\r\n",strerror(errno)); return 1;
    }

    if(ioctl( fd,I2C_SLAVE,I2C_ADDR)<0 ){
        printf("ioctl error : %s\r\n",strerror(errno));return 1;
    }
    else{
        printf("ioctl ok \r\n");
    }
    int addr = 0;

    time(&now);   
    timenow = localtime(&now);   

    printf("Content-Type: text/html \n\n");
    printf("<html>\n");
    printf("<head><meta http-equiv=\"refresh\" content=\"3\"><title>CGI Output</title></head>\n");

    printf("<body>\n");
    printf("<h1>");
    read_HWclock(fd,buf,addr,2);
    printf("</h1>\n");
    printf("</body>\n"); 
    printf("</html>\n");

    return 0;    
}

2. 编译CGI

将文件通过FileZilla上传到树莓派的/home/pi目录下
使用如下命令进行编译,并将hello.cgi拷贝到/var/www/cgi-bin目录下

gcc -o hello.cgi hello.c 
cp hello.cgi /var/www/cgi-bin

3. 远程登录,查看CGI效果

再浏览器的地址栏输入:http://192.168.3.106/cgi-bin/hello.cgi,IP地址根据树莓派的实际地址填写

3. 板子不在手边,等以后补上效果图

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据实验所测数据F:0.160; w:1.005; lgw:0.002; DA:2.000; AD:2.004; M:1.002; DB:0.017; DU:-0.778; Re:1.002; Im:-0.014; F:0.200; w:1.257; lgw:0.099; DA:2.000; AD:2.006; M:1.003; DB:0.026; DU:-1.224; Re:1.003; Im:-0.021; F:0.250; w:1.571; lgw:0.196; DA:2.000; AD:2.011; M:1.006; DB:0.048; DU:-2.610; Re:1.004; Im:-0.046; F:0.320; w:2.011; lgw:0.303; DA:2.000; AD:2.018; M:1.009; DB:0.078; DU:-2.045; Re:1.008; Im:-0.036; F:0.400; w:2.513; lgw:0.400; DA:2.000; AD:2.031; M:1.016; DB:0.134; DU:-2.880; Re:1.014; Im:-0.051; F:0.500; w:3.142; lgw:0.497; DA:2.000; AD:2.050; M:1.025; DB:0.214; DU:-6.120; Re:1.019; Im:-0.109; F:0.630; w:3.958; lgw:0.597; DA:2.000; AD:2.079; M:1.040; DB:0.336; DU:-8.838; Re:1.027; Im:-0.160; F:0.800; w:5.027; lgw:0.701; DA:2.000; AD:2.133; M:1.067; DB:0.559; DU:-8.208; Re:1.056; Im:-0.152; F:1.000; w:6.283; lgw:0.798; DA:2.000; AD:2.219; M:1.110; DB:0.903; DU:-14.040; Re:1.076; Im:-0.269; F:1.260; w:7.917; lgw:0.899; DA:2.000; AD:2.363; M:1.182; DB:1.449; DU:-15.869; Re:1.136; Im:-0.323; F:1.590; w:9.990; lgw:1.000; DA:2.000; AD:2.634; M:1.317; DB:2.392; DU:-24.638; Re:1.197; Im:-0.549; F:2.000; w:12.566; lgw:1.099; DA:2.000; AD:3.056; M:1.528; DB:3.682; DU:-43.200; Re:1.114; Im:-1.046; F:2.520; w:15.834; lgw:1.200; DA:2.000; AD:3.303; M:1.652; DB:4.358; DU:-78.466; Re:0.330; Im:-1.618; F:3.180; w:19.981; lgw:1.301; DA:2.000; AD:2.475; M:1.238; DB:1.851; DU:-116.222; Re:-0.547; Im:-1.110; F:4.000; w:25.133; lgw:1.400; DA:2.000; AD:1.437; M:0.719; DB:-2.871; DU:-140.400; Re:-0.554; Im:-0.458; F:5.000; w:31.416; lgw:1.497; DA:2.000; AD:0.834; M:0.417; DB:-7.597; DU:-156.600; Re:-0.383; Im:-0.166; F:6.340; w:39.835; lgw:1.600; DA:2.000; AD:0.473; M:0.237; DB:-12.523; DU:-161.259; Re:-0.224; Im:-0.076; F:8.000; w:50.265; lgw:1.701; DA:2.000; AD:0.253; M:0.127; DB:-17.958; DU:-166.320; Re:-0.123; Im:-0.030; F:10.000; w:62.832; lgw:1.798; DA:2.000; AD:0.226; M:0.113; DB:-18.938; DU:-165.600; Re:-0.109; Im:-0.028; ,求出其对应的相位角φ(w)
06-11

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值