Skip to content
17 changes: 15 additions & 2 deletions main/ZsensorBME280.ino
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@
BME280 mySensor;

void setupZsensorBME280() {
# if defined(ESP8266) || defined(ESP32)
// Allow custom pins on ESP Platforms
Wire.begin(BME280_PIN_SDA, BME280_PIN_SCL);
# else
Wire.begin();
# endif

mySensor.settings.commInterface = I2C_MODE;
mySensor.settings.I2CAddress = BME280_i2c_addr;
Log.notice(F("Setup BME280 on adress: %H" CR), BME280_i2c_addr);
Log.notice(F("Setup BME280 on adress: %X" CR), BME280_i2c_addr);
//***Operation settings*****************************//

// runMode Setting - Values:
Expand Down Expand Up @@ -101,7 +108,13 @@ void setupZsensorBME280() {
mySensor.settings.humidOverSample = 1;

delay(10); // Gives the Sensor enough time to turn on (The BME280 requires 2ms to start up)
Log.notice(F("Bosch BME280 Initialized - Result of .begin(): 0x %h" CR), mySensor.begin());

int ret = mySensor.begin();
if (ret == 0x60) {
Log.notice(F("Bosch BME280 successfully initialized: %X" CR), ret);
} else {
Log.notice(F("Bosch BME280 failed: %X" CR), ret);
}
}

void MeasureTempHumAndPressure() {
Expand Down
4 changes: 4 additions & 0 deletions main/config_BME280.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ extern void BME280toMQTT();
unsigned long timebme280 = 0;
int BME280_i2c_addr = 0x76; // Bosch BME280 I2C Address

// Only supported for ESP
int BME280_PIN_SDA = 21; // PIN SDA
int BME280_PIN_SCL = 22; // PIN SCL

#endif