adafruit / Adafruit_BME280_Library

Arduino Library for BME280 sensors
Other
328 stars 301 forks source link

takeForcedMeasurement(): set up humidity measurement #77

Closed dsn-github closed 3 years ago

dsn-github commented 4 years ago

takeForcedMeasurement(): write to ctrl_hum register to properly set up humidity measurement

ladyada commented 4 years ago

hi, it isnt clear why this is needed? please explain it :)

dsn-github commented 4 years ago

On 27.02.2020 01:51, ladyada wrote:

hi, it isnt clear why this is needed? please explain it :)

Hi.

Yes, I saw that setSampling method wrote to ctrl_hum register.

But in this case this doesn't work, humidity measurement remains disabled:

include

Adafruit_BME280 bme;

void setup() {

  bme.begin(0x76);

  bme.setSampling(Adafruit_BME280::MODE_FORCED,                     Adafruit_BME280::SAMPLING_X1,                     Adafruit_BME280::SAMPLING_X1,                     Adafruit_BME280::SAMPLING_X1,                     Adafruit_BME280::FILTER_OFF   );

  // ...

}

void loop() {   float t, h;

  bme.takeForcedMeasurement();

  t = bme.readTemperature();

  h = bme.readHumidity(); // get nan

  // ...

}

ladyada commented 4 years ago

@caternuson lgtm can you check me ? :)

caternuson commented 4 years ago

I can't recreate the issue. I added some serial output to the example above:

#include <Adafruit_BME280.h>

Adafruit_BME280 bme;

void setup() {
   Serial.begin(9600);

   bme.begin();

   bme.setSampling(Adafruit_BME280::MODE_FORCED,
                     Adafruit_BME280::SAMPLING_X1,
                     Adafruit_BME280::SAMPLING_X1,
                     Adafruit_BME280::SAMPLING_X1,
                     Adafruit_BME280::FILTER_OFF   );

}

void loop() {
   float t, h;

   bme.takeForcedMeasurement();

   t = bme.readTemperature();

   h = bme.readHumidity(); // get nan

   Serial.print("t = "); Serial.print(t);
   Serial.print(" h = "); Serial.println(h);

   delay(500);
}

and it runs OK using the current version of the library: bme_test

I think as long as osrs_h is non-zero, the humidity measurement occurs. bme_data And there's no need to re-write to the humidity control register.

caternuson commented 4 years ago

@dsn-github Is this still an issue for you? If you run the same code I tested above, what do you get?

caternuson commented 3 years ago

Closing due to lack of activity. Original issue could not be recreated.

SebDominguez commented 2 years ago

For whatever reasons I get Humidity = nan %

according to the lib it's because read16(BME280_REGISTER_HUMIDDATA); return 0x8000.

Other readings are fine:

Temperature = 19.83 °C
Pressure = 932.42 hPa

really weird...

caternuson commented 2 years ago

@SebDominguez Please open a new issue.