【问题标题】:Anyone using a BME280 sensor on Windows Core IoT?有人在 Windows Core IoT 上使用 BME280 传感器吗?
【发布时间】:2016-09-30 15:43:06
【问题描述】:

我正在尝试从 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];

【问题讨论】:

    标签: windows iot i2c windowsiot


    【解决方案1】:

    我认为你做的一切都是对的。

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

            int _rawTemp = 0x7fd10;
            int _digT1 = 0x196e;
            int _digT2 = 0x7e66;
            int _digT3 = 0x3200;
    
            int var1 = (((_rawTemp >> 3 - _digT1 << 1)) * _digT2) >> 11;
            int var2 = (((((_rawTemp >> 4) - (_digT1)) * ((_rawTemp >> 4) - (_digT1))) >> 12) * (_digT3)) >> 14;
            int t_fine = var1 + var2;
            int temperature = ((t_fine) * 5 + 128) >> 8;
    

    我得到 2559,读数为 25.59℃。

    查看 https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c

    您是如何计算补偿值的?

    【讨论】:

    • 非常感谢,即将关闭,但只是没有得到这个。请使用 _rawTemp=0x80200 尝试相同的逻辑。我看到的是在设置符号位时位移是错误的。我相信 _rawTemp 应该是一个 uint ,但这把我的一切都搞砸了。我也尝试了浮点例程但没有成功。但是,我认为您让我指出了正确的方向。 (我从芯片中得到了正确的值)
    • @TomLindley,0x80200 我得到-2545,我猜是-25.45℃?
    • 您收集的校准数据似乎有误。一些 dig_xx 值是带符号的短裤,您将它们全部视为无符号短裤。此外,您应该一次读取所有校准寄存器,而不是一次请求几个字节。
    猜你喜欢
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    相关资源
    最近更新 更多