求教!!有关Arduino和传感器的IIC通讯(MLX90615)

2014-01-192.2万
AI 快速预览详细 收起
本文讨论了使用Arduino和MLX90615红外传感器进行IIC通讯时遇到的问题。用户发现传感器返回值始终为高位254、低位183。通过检查电路连接和代码实现,发现上拉电阻值和设备地址可能存在问题。文章提供了详细的故障排查步骤,包括调整上拉电阻值(320K)和修改设备地址(0x5B)。最终,这些调整解决了IIC通讯故障,确保了温度测量的准确性。
我正在利用MLX90615这个IR传感器测温度,利用I2C总线通讯,可是返回值总是相同,高位为254,低位为183。
电路图求教!!有关Arduino和传感器的IIC通讯(MLX90615)图1

SDA,SCL参照数据手册引用320K上拉(数据手册建议300K,找不到300K电阻就用220K+100K.....)
代码

#include <i2cmaster.h>


void setup(){
        Serial.begin(9600);
        Serial.println("Setup...");
       
        i2c_init(); //Initialise the i2c bus
       
}

void loop(){
    int dev = 0x5B<<1;
    int data_low = 0;
    int data_high = 0;
    int pec = 0;
   
    i2c_start_wait(dev+I2C_WRITE);
    i2c_write(0x07);
   
    // read
    i2c_rep_start(dev+I2C_READ);
    data_low = i2c_readAck(); //Read 1 byte and then send ack
    data_high = i2c_readAck(); //Read 1 byte and then send ack
    pec = i2c_readNak();
    i2c_stop();
   
    //This converts high and low bytes together and processes temperature, MSB is a error bit and is ignored for temps
    double tempFactor = 0.02; // 0.02 degrees per LSB (measurement resolution of the MLX90614)
    double tempData = 0x0000; // zero out the data
    int frac; // data past the decimal point
   
    // This masks off the error bit of the high byte, then moves it left 8 bits and adds the low byte.
    tempData = (double)(((data_high & 0x007F) << 8) + data_low);
    tempData = (tempData * tempFactor)-0.01;
   
    float celcius = tempData - 273.15;
    float fahrenheit = (celcius*1.8) + 32;

    Serial.print("Celcius: ");
    Serial.println(celcius);


    delay(1000); // wait a second before printing again
}
代码根据http://bildr.org/2011/02/mlx90614-arduino/里提供的MLX90614的代码修改,就是把设备地址改成了0x5B,614和615除了引脚位置不同以外好像就没有差别了。。。。
问题在于我的615无法正常工作。。。。不知道为什么
实物图:求教!!有关Arduino和传感器的IIC通讯(MLX90615)图2

串口监视器输出结果求教!!有关Arduino和传感器的IIC通讯(MLX90615)图3


在此请教各位大神!!

创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(1)
何处不江南
何处不江南
没研究过这个,话说楼主为何不用自带的I2C的库呢 看看这个帖子能否帮到楼主?http://www.amobbs.com/thread-3990328-1-1.html
- 没有更多了 -