有人在Windows Core IoT上使用BME280传感器吗?

时间:2016-09-30 15:43:06

标签: windows iot i2c windowsiot

我正在尝试从Windows IoT Core上的Bosch BME280读取数据。我能够复位芯片,读取芯片ID,获取微调值并读取温度/按下/哼声值(突发模式)。但是,补偿值不正确。以下是我现在获得的价值观。我希望有人可以分享一些我可以用来比较的价值观。将在帖子后面发布代码。感谢。

DT1 0x196e,DT2 0x7e66,DT3 0x3200 DP1 0xc78f,DP2 0xded5,DP3 0xd00b,DP4 0xae1b,DP5 0xf00,DP6 0xf9ff,DP7 0xac26,DP8 0xad8,DP9 0xbd10 DH1 0x4b,DH2 0x6d01,DH3 0x0,DH4 0x1308,DH5 0x800,DH6 0x1e 原始温度:0x7fd10,原始印刷机:0x581bc,原始加湿:0x6cca

此处的补偿值: BME280:温度:187.36c压力:1344.55毫巴湿度:100%rH

我确信我只是在做一些愚蠢的事情,只需要朝着正确的方向稍微推动一下。感谢。

命令和方式的定义我读取了修剪值。 (只是示例中的temp)

    public static class BME280Commands
{
    public static byte[] ChipID = {0xD0 };
    public static byte[] Version = { 0xD1 };
    public static byte[] SoftReset = { 0xE0, 0xB6 };
    public static byte[] ControlHumidity = { 0xF2, 0x04 };  // second parm was 0x01
    public static byte[] Status = { 0xF3 };
    public static byte[] Control = { 0xF4, 0x91 };          // second parm was 0x87
    public static byte[] Control1 = { 0xf4, 0x3f };
    public static byte[] Config = { 0xF5, 0x16 };
    public static byte[] PressureData = { 0xF7 };
    public static byte[] TemperatureData = { 0xFA };
    public static byte[] HumidityData = { 0xFD };
    public static byte[] DIG_T1 = { 0x88 };
    public static byte[] DIG_T2 = { 0x8A };
    public static byte[] DIG_T3 = { 0x8C };
    public static byte[] DIG_P1 = { 0x8E };
    public static byte[] DIG_P2 = { 0x90 };
    public static byte[] DIG_P3 = { 0x92 };
    public static byte[] DIG_P4 = { 0x94 };
    public static byte[] DIG_P5 = { 0x96 };
    public static byte[] DIG_P6 = { 0x98 };
    public static byte[] DIG_P7 = { 0x9A };
    public static byte[] DIG_P8 = { 0x9C };
    public static byte[] DIG_P9 = { 0x9E };
    public static byte[] DIG_H1 = { 0xA1 };
    public static byte[] DIG_H2 = { 0xE1 };
    public static byte[] DIG_H3 = { 0xE3 };
    public static byte[] DIG_H4 = { 0xE4 };
    public static byte[] DIG_H5 = { 0xE5 };
    public static byte[] DIG_H6 = { 0xE7 };
    public static byte ExpectedChipId = 0x60;
    public static byte SlaveAddress = 0x77;
    public static byte SoftResetCode = 0xb6;
    public Configure()
    {
        var data = new byte[1];
        bme280Sensor.WriteRead(BME280Commands.SoftReset, data);
        bme280Sensor.WriteRead(BME280Commands.ChipID, Id);
        if (Id[0] == BME280Commands.ExpectedChipId)
        {  // How I read the trimming values
            bme280Sensor.WriteRead(BME280Commands.DIG_T1, buf2);
            _digT1 = (UInt32)((buf2[0] << 8) | buf2[1]);
            bme280Sensor.WriteRead(BME280Commands.DIG_T2, buf2);
            _digT2 = ((buf2[0] << 8) | buf2[1]);
            bme280Sensor.WriteRead(BME280Commands.DIG_T3, buf2);
            _digT3 = ((buf2[0] << 8) | buf2[1]);
        }
   }

我如何阅读实际值

    var buf8 = new byte[8];
    bme280Sensor.Write(BME280Commands.ControlHumidity);
    bme280Sensor.Write(BME280Commands.Control);

    bme280Sensor.WriteRead(BME280Commands.PressureData, buf8);
    _rawPress = (buf8[0] << 16 | buf8[1] << 8 | buf8[2]) >> 4;
    _rawTemp = (buf8[3] << 16 | buf8[4] << 8 | buf8[5]) >> 4;
    _rawHumid = (buf8[6] << 8) | buf8[7];

1 个答案:

答案 0 :(得分:1)

我认为你做的一切都是正确的。

但是,按照您提供的原始值,我使用以下数学计算补偿温度,例如,

for ii=1:size(Fruitbasket,2)
    app(ii)=Fruitbasket(ii).apples; % or getfield(Fruitbasket(ii),'apples');
end

我得到2559,读取25.59°C。

参见 https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c

你是如何计算补偿值的?