Multiple BME280 sensor for Domoticz



  • Hi,
    I'm trying to build a node that uses x2 BME280 sensors for a whole house fan controller, one inside temp/hum and one outside. The BME280 has a selectable I2C address by grounding the SDO pin on the sensor. I have successfully tested this using the BlueDot_BME280.h library and sketches.
    Problem I am having is turning this sketch into a working Mysensors node I can use in domoticz. I think I'm almost there but cannot see why i am getting an 'invalid use of non-static member function' message.
    here is my hacked code...

    I thought i would try and get it working with one BME280 first..

    
    /***************************************************************************
      Example for BME280 Weather Station using two Sensors with I2C Protocol
      written by Thiago Barros for BlueDot UG (haftungsbeschränkt)
      BSD License
    
      This sketch was written for the Bosch Sensor BME280.
      The BME280 is a MEMS device for measuring temperature, humidity and atmospheric pressure.
      For more technical information on the BME280, please go to ------> http://www.bluedot.space
    
     ***************************************************************************/
    #define MY_DEBUG
    #define MY_RADIO_NRF24
    //#define MY_RF24_CE_PIN 49 //only required for Mega
    //#define MY_RF24_CS_PIN 53 //only required for Mega
    #define MY_RF24_PA_LEVEL (RF24_PA_MIN)
    #define MY_NODE_ID 57
    
    #include <SPI.h>
    #include <Wire.h>
    #include "BlueDot_BME280.h"
    #include <MySensors.h>
    
    
    
    #define BARO_CHILD 0 //these will appear in domoticz child list for this node
    #define TEMP_CHILD 1
    #define HUM_CHILD 2
    
    long interval = 60000;           // interval at which to send (milliseconds)
    long previousMillis = interval;        // will store last time data was sent
    
    BlueDot_BME280 bme1;                                     //Object for Sensor 1
    BlueDot_BME280 bme2;                                     //Object for Sensor 2
    
    int bme1Detected = 0;
    ///int bme2Detected = 0;
    
    float dP_dt;
    boolean metric;
    MyMessage tempMsg(TEMP_CHILD, V_TEMP);
    MyMessage humMsg(HUM_CHILD, V_HUM);
    MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
    
    void setup() {
    
    metric = getControllerConfig().isMetric;  // was getConfig().isMetric; before MySensors v2.1.1
      Wire.begin(); // Wire.begin(sda, scl)
      // use the 1.1 V internal reference
    #if defined(__AVR_ATmega2560__)
      analogReference(INTERNAL1V1);
    #else
      analogReference(INTERNAL);
    #endif
    
      Serial.begin(115200);
     
    
      bme1.parameter.communication = 0;                    //Setting communication for Sensor 1 (bme1)
     // bme2.parameter.communication = 0;                    //Setting communication for Sensor 2 (bme2)
      bme1.parameter.I2CAddress = 0x77;                    //I2C Address for Sensor 1 (bme1)
     // bme2.parameter.I2CAddress = 0x76;                    //I2C Address for Sensor 2 (bme2)
      bme1.parameter.sensorMode = 0b11;                    //In normal mode the sensor measures continually (default value)
    //  bme2.parameter.sensorMode = 0b11;
      bme1.parameter.IIRfilter = 0b000;                   //factor 0 (filter off)
     // bme2.parameter.IIRfilter = 0b000;                   //factor 16 (default value)
      bme1.parameter.humidOversampling = 0b101;            //factor 16
     // bme2.parameter.humidOversampling = 0b101;            //factor 16
      bme1.parameter.tempOversampling = 0b101;              //factor 16
     // bme2.parameter.tempOversampling = 0b101;              //factor 16
      bme1.parameter.pressOversampling = 0b101;             //factor 16
    //  bme2.parameter.pressOversampling = 0b101;             //factor 16
      bme1.parameter.tempOutsideCelsius = 10;               //default value of 15°C
     // bme2.parameter.tempOutsideCelsius = 10;               //default value of 15°C
    
      if (bme1.init() != 0x60)
      {
        Serial.println(F("First BME280 Sensor not found!"));
        Serial.println(F("Please check your connections."));
        bme1Detected = 0;
      }
      else
      {
        Serial.println(F("First BME280 Sensor detected!"));
        bme1Detected = 1;
      }
     
      
      Serial.println();
      Serial.println();
    
    }
    
    
    void presentation() {
      sendSketchInfo("BME x2 I2C master ", "V2.a");
    
      // Register sensors to gw (they will be created as child devices)
      present(BARO_CHILD, S_BARO);
      present(TEMP_CHILD, S_TEMP);
      present(HUM_CHILD, S_HUM);
    
    }
    
    void loop() {
    
    
      Serial.print(F("Duration in Seconds:\t\t\t\t"));
      Serial.println(float(millis()) / 1000);
    
      if (bme1Detected)
      {
        Serial.print(F("Temperature in Celsius from Sensor 1:\t\t"));
        Serial.println(bme1.readTempC());
        Serial.print(F("Humidity in % from Sensor 1:\t\t\t"));
        Serial.println(bme1.readHumidity());
        Serial.print(F("Pressure in hPa from Sensor 1:\t\t\t"));
        Serial.println(bme1.readPressure());
      }
      else
      {
        Serial.print(F("Temperature in Celsius from Sensor 1:\t\t"));
        Serial.println(F("Null"));
        Serial.print(F("Humidity in % from Sensor 1:\t\t\t"));
        Serial.println(F("Null"));
        Serial.print(F("Pressure in hPa from Sensor 1:\t\t\t"));
        Serial.println(F("Null"));
      {
    
    
        send(humMsg.set(bme1.readHumidity, 1));
    wait(50);
    
      //  send(humMsg.set(humidity, 1));
    //wait(50);
    
      delay(5000);
    }
    }}
    


  • @palmerfarmer said in Multiple BME280 sensor for Domoticz:

    Hi,
    I'm trying to build a node that uses x2 BME280 sensors for a whole house fan controller, one inside temp/hum and one outside. The BME280 has a selectable I2C address by grounding the SDO pin on the sensor. I have successfully tested this using the BlueDot_BME280.h library and sketches.
    Problem I am having is turning this sketch into a working Mysensors node I can use in domoticz. I think I'm almost there but cannot see why i am getting an 'invalid use of non-static member function' message.
    here is my hacked code...

    I thought i would try and get it working with one BME280 first..

    Check if you use } or { correctly.
    I can see one mistake:

    else
    {
    Serial.print(F("Temperature in Celsius from Sensor 1:\t\t"));
    Serial.println(F("Null"));
    Serial.print(F("Humidity in % from Sensor 1:\t\t\t"));
    Serial.println(F("Null"));
    Serial.print(F("Pressure in hPa from Sensor 1:\t\t\t"));
    Serial.println(F("Null"));
    { (This should be } )



  • Thanks for the reply and spotting one of my many errors (now corrected amongst others!).
    Managed to get one of them showing up in Domoticz, lets see if i can get them both in there without the temp hum being crossed over between physical sensors. There seems to be a few posts about this problem.


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.6k
Posts