|
@ -22,13 +22,33 @@ bool BME280::begin(void) { |
|
|
if (retries > 5) break; |
|
|
if (retries > 5) break; |
|
|
retries++; |
|
|
retries++; |
|
|
Serial.println("Could not find a valid BME280 sensor, check wiring!"); |
|
|
Serial.println("Could not find a valid BME280 sensor, check wiring!"); |
|
|
// bme->reset();
|
|
|
|
|
|
delay(500); |
|
|
delay(500); |
|
|
} |
|
|
} |
|
|
if (!valid) return false; |
|
|
if (!valid) return false; |
|
|
|
|
|
|
|
|
|
|
|
bme->setSampling(Adafruit_BME280::sensor_mode::MODE_NORMAL, |
|
|
|
|
|
Adafruit_BME280::sensor_sampling::SAMPLING_X16, |
|
|
|
|
|
Adafruit_BME280::sensor_sampling::SAMPLING_X16, |
|
|
|
|
|
Adafruit_BME280::sensor_sampling::SAMPLING_X16, |
|
|
|
|
|
Adafruit_BME280::sensor_filter::FILTER_OFF, |
|
|
|
|
|
Adafruit_BME280::standby_duration::STANDBY_MS_250); |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BME280::sleep() { |
|
|
|
|
|
bme->setSampling(Adafruit_BME280::sensor_mode::MODE_SLEEP, |
|
|
|
|
|
Adafruit_BME280::sensor_sampling::SAMPLING_X16, |
|
|
|
|
|
Adafruit_BME280::sensor_sampling::SAMPLING_X16, |
|
|
|
|
|
Adafruit_BME280::sensor_sampling::SAMPLING_X16, |
|
|
|
|
|
Adafruit_BME280::sensor_filter::FILTER_OFF, |
|
|
|
|
|
Adafruit_BME280::standby_duration::STANDBY_MS_1000); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void BME280::init() { |
|
|
|
|
|
bme->init(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void BME280::printValues() { |
|
|
void BME280::printValues() { |
|
|
Serial.print("Temperature = "); |
|
|
Serial.print("Temperature = "); |
|
|
Serial.print(bme->readTemperature()); |
|
|
Serial.print(bme->readTemperature()); |
|
@ -50,6 +70,21 @@ void BME280::printValues() { |
|
|
Serial.println(); |
|
|
Serial.println(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
float BME280::readTemperature(void) { return bme->readTemperature(); } |
|
|
float BME280::readTemperature(void) { |
|
|
float BME280::readPressure(void) { return bme->readPressure() / 100.0F; } |
|
|
float temp = bme->readTemperature(); |
|
|
float BME280::readHumidity(void) { return bme->readHumidity(); } |
|
|
if (temp < -40 || temp > 85) valid = false; |
|
|
|
|
|
else valid = true; |
|
|
|
|
|
return temp; |
|
|
|
|
|
} |
|
|
|
|
|
float BME280::readPressure(void) { |
|
|
|
|
|
float p = bme->readPressure() / 100.0F; |
|
|
|
|
|
if (p < 300 || p > 1100) valid = false; |
|
|
|
|
|
else valid = true; |
|
|
|
|
|
return p; |
|
|
|
|
|
} |
|
|
|
|
|
float BME280::readHumidity(void) { |
|
|
|
|
|
float h = bme->readHumidity(); |
|
|
|
|
|
if (h < 0 || h > 100) valid = false; |
|
|
|
|
|
else valid = true; |
|
|
|
|
|
return h; |
|
|
|
|
|
} |
|
|