Switch Sensors from Adafruit_Si7021 to BME280


Fernando Nino Sr
 

Hi Howard, I believe you asked me a while ago if I was going to use a second BME280 to measure the inside temp and humidity, I said no I wanted to use the Si7021, but now I want to switch over to use the BME280 for simple wiring.  I was looking at the code but with the validator I dont know if adding a second BME would mess it up. I see in some other code they show the two bme as bme1 and bme2. Is there a simple way to modify the thermostat page to accept the bme280 with out causing issue?
Thanks
Nino


Howard Dutton
 

Sorry for the delay, I didn't notice the message in my email and only stop by here so often!

I suspect something like this would work (note the I2C address of the two BME280's need to be different:)

// =================================================================================================================
// ============================== add your inside temperature sensor support here ==================================

#include <Adafruit_BME280.h> // I2C address 0x76 or 0x77; https://github.com/adafruit/Adafruit_BME280_Library
Adafruit_BME280 bmeThermostat;

// this gets called once on startup to initialize any weather sensors
bool thermostatGood=false;
void thermostatInit() {
  if (bmeThermostat.begin(0x77,&Wire)) thermostatGood=true; // I2C address 0x76 or 0x77
}

// gets inside temperature in deg. C
// return (invalid) if not implemented or if there's an error
double thermostatInsideTemp() {
  if (!thermostatGood) return invalid;

  double t = bmeThermostat.readTemperature();
  if (t<-60.0 || t>60.0) t=invalid;
  return t;
}


// gets inside RH in %
// return (invalid) if not implemented or if there's an error
double thermostatInsideHumidity() {
  if (!thermostatGood) return invalid;

  double h=bmeThermostat.readHumidity();
  if (h<0.0) h=invalid;
  if (h>100.0) h=100.0;
  return h;
}


Fernando Nino Sr
 

On Tue, Jun 2, 2020 at 07:47 AM, Howard Dutton wrote:
#include <Adafruit_BME280.h> // I2C address 0x76 or 0x77; https://github.com/adafruit/Adafruit_BME280_Library
Adafruit_BME280 bmeThermostat;

// this gets called once on startup to initialize any weather sensors
bool thermostatGood=false;
void thermostatInit() {
  if (bmeThermostat.begin(0x77,&Wire)) thermostatGood=true; // I2C address 0x76 or 0x77
}

// gets inside temperature in deg. C
// return (invalid) if not implemented or if there's an error
double thermostatInsideTemp() {
  if (!thermostatGood) return invalid;

  double t = bmeThermostat.readTemperature();
  if (t<-60.0 || t>60.0) t=invalid;
  return t;
}


// gets inside RH in %
// return (invalid) if not implemented or if there's an error
double thermostatInsideHumidity() {
  if (!thermostatGood) return invalid;

  double h=bmeThermostat.readHumidity();
  if (h<0.0) h=invalid;
  if (h>100.0) h=100.0;
  return h;
}
Thanks Howard, I till give it a try.
Nino