Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Important: Reinitialise if sensor disconnects #87

Closed
wants to merge 1 commit into from

Conversation

raako71
Copy link

@raako71 raako71 commented Aug 19, 2020

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
Copy link
Member

ladyada commented Aug 19, 2020

is NaN really the value returned if it gets disconnected?

@raako71
Copy link
Author

raako71 commented Aug 20, 2020

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
Copy link

khoek commented Jul 29, 2021

@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
Copy link
Contributor

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
Copy link

khoek commented Jul 29, 2021 via email

@caternuson
Copy link
Contributor

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
Copy link
Contributor

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

@caternuson caternuson closed this Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants