adafruit / Adafruit_BME280_Library

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

Important: Reinitialise if sensor disconnects #87

Closed raako71 closed 3 years ago

raako71 commented 3 years ago

In my usage I had a float variable for the sensor value, which I used in this section of code. Since the example doesn't have such a variable, I re-read the value. Very important to have such a section of code for example if the sensor is connected by a non perfect connector

ladyada commented 3 years ago

is NaN really the value returned if it gets disconnected?

raako71 commented 3 years ago

if it gets disconnected it will show (and hold) an incorrect value, if you reconnect it, it will show NaN. In my sketch I used the sleepydog library, basic idea I used is here. The key point being that watchdog will still reset once reconnected

// declare variables float t = 0; float t2 = 0;

// loop t = bme.readTemperature();

// No sensor if(t != t2){
Watchdog.reset(); //Serial.print(" Watchdog reset."); } t2 = t; if(isnan(t)){ bme.begin(0x76); Serial.print("\n reinitialise BME280 \n"); }

khoek commented 3 years ago

@ladyada Yes. Line 420 of Adafruit_BME280.cpp explicitly returns NAN: https://github.com/adafruit/Adafruit_BME280_Library/blob/master/Adafruit_BME280.cpp#L420

caternuson commented 3 years ago

Disconnect also potentially implies a power cycle and return to power on default state, losing any configuration done, like in init() or even by user. Does simply catching the NaN also result in everything else working as expected?

khoek commented 3 years ago

Certainly not, but the pull requester just proposes to change the simple example file.

At any rate, I was just pointing out a misconception I noticed in the original reply.

On Fri, 30 Jul 2021, 07:32 Carter Nelson, @.***> wrote:

Disconnect also potentially implies a power cycle and return to power on default state, losing any configuration done, like in init() or even by user. Does simply catching the NaN also result in everything else working as expected?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/adafruit/Adafruit_BME280_Library/pull/87#issuecomment-889474886, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADSU3VSBNEFDLVCWLIZ453T2HCFZANCNFSM4QEZIKUA .

caternuson commented 3 years ago

Oh, I see, begin() gets called when nan is detected. This should really be done in user code. That way any non-default usage of begin() can be taken care of as well. Looks like that's suggested above in the code example?

caternuson commented 3 years ago

Going to close this. If this continues to be a problem, please first open an issue.