BME280 Sensor


Fernando Nino Sr
 

Not having any luck trying to get the weather bme280 sensor sketch to work. The OSC tab already has the "void setup()" and "void loop()" claimed. I copied some of the code over to the OSC tab, then I get an error msg, Ok i move it back to the weather tab and get another error msg.  Ok what is the correct way to code the bme280 sensor, anyone?   I checked and the sensor is working but having issues with implementing the code. Using Adafruit_BME280, along with the Adafruit sensor.

I ordered the ones that Howard uses but wont be in for a month, so I am using what I have on hand.
Thanks
Nino


Howard Dutton
 

First off, be sure you are using the latest OCS (from a couple of days ago.)  The structure of the Weather.ino file changed.


Howard Dutton
 
Edited

I put together an OCS w/BME280 this morning; the following code worked for me just copy each sensor type into its respective place in Weather.ino:

// -----------------------------------------------------------------------------------------------------------------
// gets outside temperature in deg. C

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

// return (invalid) if not implemented or if there's an error
double weatherOutsideTemp() {
  if (!outsideTempGood) return invalid;

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

bool initOutsideTemp() {
  bool success=true;
  if (!bme.begin(0x76,&Wire)) success=false;
  return success;
}

// -----------------------------------------------------------------------------------------------------------------
// gets barometric pressure in mb

// return (invalid) if not implemented or if there's an error; absolute pressure
double weatherPressure() {
  if (!pressureGood) return (invalid);
 
  double p0 = bme.readPressure()/100.0;  // hpa to millibar
  return p0;
}

// return (invalid) if not implemented or if there's an error; sea-level adjusted pressure
double weatherPressureSeaLevel() {
  if (!pressureGood) return (invalid);
 
  double p0=bme.readPressure();
  double p1=(p0/pow((1.0-((float)(WEATHER_ALTITUDE))/44330.0), 5.255))/100.0;
  return p1;
}

bool initPressure() {
  return true;
}

// -----------------------------------------------------------------------------------------------------------------
// gets relative humidity in %

// return (invalid) if not implemented or if there's an error
double weatherHumidity() {
  if (!humidityGood) return (invalid);

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

bool initHumidity() {
  return true;
}


Fernando Nino Sr
 

Yes sir, I noticed that the sketch had been updated, so I uploaded the newest sketch 1.4e, is there a newer one?


Fernando Nino Sr
 

Thanks Howard, I will upgrade to the 1.4f and try it. 


Fernando Nino Sr
 

This is what I have for the weather tab. if I try to compile it, I get error msgs on the "weatherskytemp" not declared, also error on "double weatherskytemp". I have the lastest sketch 1.4f  and arduino 1.8.10
Thanks Nino

// -----------------------------------------------------------------------------------------------------------------
// Weather functions

#include <Wire.h>
bool outsideTempGood=false, skyTempGood=false, windspeedGood=false, pressureGood=false, humidityGood=false, rainGood=false, skyQualityGood=false;

// =================================================================================================================
// =================================== add your weather sensor support below =======================================

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


// -----------------------------------------------------------------------------------------------------------------
// gets outside temperature in deg. C

// return (invalid) if not implemented or if there's an error
double weatherOutsideTemp() {
  if (!outsideTempGood) return invalid;

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

bool initOutsideTemp() {
  bool success=true;
  if (!bme.begin(0x76,&Wire)) success=false;
  return success;
}

// -----------------------------------------------------------------------------------------------------------------
// gets barometric pressure in mb

// return (invalid) if not implemented or if there's an error; absolute pressure
double weatherPressure() {
  if (!pressureGood) return (invalid);
 
  double p0 = bme.readPressure()/100.0;  // hpa to millibar
  return p0;
}

// return (invalid) if not implemented or if there's an error; sea-level adjusted pressure
double weatherPressureSeaLevel() {
  if (!pressureGood) return (invalid);
 
  double p0=bme.readPressure();
  double p1=(p0/pow((1.0-((float)(WEATHER_ALTITUDE))/44330.0), 5.255))/100.0;
  return p1;
}

bool initPressure() {
  return true;
}

// -----------------------------------------------------------------------------------------------------------------
// gets relative humidity in %

// return (invalid) if not implemented or if there's an error
double weatherHumidity() {
  if (!humidityGood) return (invalid);

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

bool initHumidity() {
  return true;
}

// -----------------------------------------------------------------------------------------------------------------
// gets windspeed in kph

// return (invalid) if not implemented or if there's an error
double weatherWindspeed() {
  if (!windspeedGood) return invalid;
  return invalid;
}

bool initWindspeed() {
  return false;
}

// return (invalid) if not implemented or if there's an error
 double weatherOutsideTemp() {
   if (!outsideTempGood) return invalid;
  return invalid;
}

bool initOutsideTemp() {
  return false;
}

// -----------------------------------------------------------------------------------------------------------------
// gets sky IR temperature in deg. C

 return (invalid) if not implemented or if there's an error
 double weatherSkyTemp() {
   if (!skyTempGood) return invalid;
   return invalid;
}

bool initSkyTemp() {
  return false;
}

// -----------------------------------------------------------------------------------------------------------------
// gets windspeed in kph

// return (invalid) if not implemented or if there's an error
double weatherWindspeed() {
  if (!windspeedGood) return invalid;
  return invalid;
}

bool initWindspeed() {
  return false;
}

// -----------------------------------------------------------------------------------------------------------------
// gets barometric pressure in mb

// return (invalid) if not implemented or if there's an error, absolute pressure
double weatherPressure() {
  if (!pressureGood) return invalid;
  return invalid;
}

// return (invalid) if not implemented or if there's an error, sea-level adjusted
double weatherPressureSeaLevel() {
  if (!pressureGood) return invalid;
  return invalid;
}

bool initPressure() {
  return false;
}

// -----------------------------------------------------------------------------------------------------------------
// gets relative humidity in %

// return (invalid) if not implemented or if there's an error
double weatherHumidity() {
  if (!humidityGood) return invalid;
  return invalid;
}

bool initHumidity() {
  return false;
}

// -----------------------------------------------------------------------------------------------------------------
// gets rain sensor info. 1 is Rain, 2 is Warn, and 3 is Dry

// return (invalid) if not implemented or if there's an error
int weatherRain() {
  if (!rainGood) return invalid;
  return invalid;
}

bool initRain() {
  return false;
}

// -----------------------------------------------------------------------------------------------------------------
// gets sky brightness in mag/arc-sec^2

// return (invalid) if not implemented or if there's an error
double weatherSkyQuality() {
  if (!skyQualityGood) return invalid;
  return invalid;
}

bool initSkyQuality() {
  return false;
}

// ============================= no user changes are required beyond this point ====================================
// =================================================================================================================


Howard Dutton
 

On Sun, Jan 12, 2020 at 05:38 PM, Fernando Nino Sr wrote:
// -----------------------------------------------------------------------------------------------------------------
// gets sky IR temperature in deg. C

 return (invalid) if not implemented or if there's an error
 double weatherSkyTemp() {
   if (!skyTempGood) return invalid;
   return invalid;
}
I didn't try to compile but the bolded line above is supposed to be a comment...

...
// return (invalid) if not implemented or if there's an error
 double weatherSkyTemp() {
   if (!skyTempGood) return invalid;
   return invalid;
}
...


Fernando Nino Sr
 

Thanks Howard for your help, It's working (bme280 sensor is in my  office next to my pc,)  I just had to re-read your post again. The rest of the sensors should be in this week just have to read up on the pin assignments. Also wanted to use relay 7 and 8 in series to use as open/close(relay 7-relay my pushbutton switch) and connect my ir sensors(relay 8- ir beam will shoot between the two walls) to make sure the telescope has cleared the roof before closing, just wondering how that would effect the control panel.
Nino


Howard Dutton
 

On Mon, Jan 13, 2020 at 02:11 PM, Fernando Nino Sr wrote:
Also wanted to use relay 7 and 8 in series to use as open/close(relay 7-relay my pushbutton switch) and connect my ir sensors(relay 8- ir beam will shoot between the two walls) to make sure the telescope has cleared the roof before closing, just wondering how that would effect the control panel.
So, are you using a garage door opener?
The ir beam would be on an input channel right?


Fernando Nino Sr
 

Correct. 
Thanks


Howard Dutton
 

On Mon, Jan 13, 2020 at 02:11 PM, Fernando Nino Sr wrote:
Also wanted to use relay 7 and 8 in series to use as open/close(relay 7-relay my pushbutton switch) and connect my ir sensors(relay 8- ir beam will shoot between the two walls) to make sure the telescope has cleared the roof before closing, just wondering how that would effect the control panel.
I think what you would want to do is perhaps use relay 7 to press the garage door opener button.

#define ROR_OPEN_CLOSE_MOMENTARY        7 //    OFF, n. Where n=1..14 (Relay#) A momentary switch closure (~1.5 seconds.)     Option

                                          //         To trigger a garage door opener (for example) to either open or close.

Then use relay 8 to control power to the garage door opener and interlock system.  For the interlock system the signal then goes either logic HIGH (5V) or LOW (Gnd.)  Lets say HIGH=ON (OK) for this example.

#define ROR_POWER_RELAY                 8 //    OFF, n. Where n=1..14 (Relay#) This controls roof motor pwr. For DC motor.    Option
                                          //         SSR/MOSFET PWM controls speed. For garage door openers, SW on/off only.

Finally lets have the interlock signal come in on "Sense 1" such that if the open/close sequence was initiated power will remain on until the sequence times out (Config.h setting) or the close limit switch is reached or the interlock signal goes LOW.


#define ROR_CLOSE_INTERLOCK             1 //    OFF, n. Where n=1..6 (Sense#) Roof safety interlock, close allowed when ON.   Option

There is also an option in the Config.h file to display a "Safety override" button which should be enabled.  This is for the user to take manual control in-case something unexpected happens and pressing override then allows manual recovery.  The OCS only presumes to know if an Open press or Close press will actually move in that direction if an opened or closed limit switch shows the roof at one end of the travel or the other.  If, for instance the ir beam interlock detects something and the OCS cuts power to the garage door opener the open/close state is lost and opening and closing are not allowed.  You then go and fix whatever caused the event, press the "Safety override" button, then press "Open" or "Close" .  The roof might move in the wrong direction but you can work that out since it's being closely monitored at this point.