add alternative BME reading using SparkFun librarry
This commit is contained in:
parent
fff19fe3fc
commit
52df4e31b2
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#if ADAFRUIT_BME
|
||||
|
||||
#include <Adafruit_BME280.h>
|
||||
|
||||
namespace Bme {
|
||||
@ -47,4 +49,59 @@ namespace Bme {
|
||||
Adafruit_BME280::SAMPLING_X1, // humidity
|
||||
Adafruit_BME280::FILTER_OFF);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
#include <SparkFunBME280.h>
|
||||
|
||||
namespace Bme {
|
||||
|
||||
BME280 bme; // I2C Interface
|
||||
bool initialised = false;
|
||||
|
||||
struct {
|
||||
float temp;
|
||||
float humidity;
|
||||
float pressure;
|
||||
float readTemp() {
|
||||
char buf[10];
|
||||
sprintf(buf, "%.1f", bme.readTempC());
|
||||
temp = atof(buf);
|
||||
return temp;
|
||||
}
|
||||
float readHumidity() {
|
||||
char buf[10];
|
||||
sprintf(buf, "%.1f", bme.readFloatHumidity());
|
||||
humidity = atof(buf);
|
||||
return humidity;
|
||||
}
|
||||
void readAll() {
|
||||
if (!initialised) return;
|
||||
// bme.takeForcedMeasurement();
|
||||
readTemp();
|
||||
readHumidity();
|
||||
pressure = bme.readFloatPressure();
|
||||
}
|
||||
} data;
|
||||
|
||||
void setup() {
|
||||
Serial.println(F("BME280 setup"));
|
||||
|
||||
bme.setI2CAddress(0x76);
|
||||
if (!bme.beginI2C()) {
|
||||
Serial.println(F("Could not find a valid BME280 sensor, check wiring!"));
|
||||
return;
|
||||
}
|
||||
initialised = true;
|
||||
|
||||
/* Settings from examples: advancedsettings.ino */
|
||||
// -- Weather Station Scenario --
|
||||
// Serial.println("-- Weather Station Scenario --");
|
||||
// bme.setSampling(Adafruit_BME280::MODE_FORCED, /* Operating Mode. */
|
||||
// Adafruit_BME280::SAMPLING_X1, // temperature
|
||||
// Adafruit_BME280::SAMPLING_X1, // pressure
|
||||
// Adafruit_BME280::SAMPLING_X1, // humidity
|
||||
// Adafruit_BME280::FILTER_OFF);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -20,9 +20,10 @@ lib_deps =
|
||||
jchristensen/Timezone@^1.2.4
|
||||
adafruit/Adafruit Unified Sensor @ ^1.1.4
|
||||
adafruit/Adafruit BME280 Library@^2.2.4
|
||||
sparkfun/SparkFun BME280@^2.0.9
|
||||
https://git.hodos.ro/libraries/wifi.git@^1.0.1
|
||||
https://git.hodos.ro/libraries/ha-mqtt.git@^1.0.0
|
||||
build_flags = -D WIFI_ALWAYS_ON=1
|
||||
build_flags = -D WIFI_ALWAYS_ON=1 -D ADAFRUIT_BME=1
|
||||
|
||||
[env:laptop_home]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user