Skip to content

Commit

Permalink
Updated to new BME280 lib
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaGitH authored May 1, 2018
1 parent cd2bf9d commit 98d77db
Showing 1 changed file with 32 additions and 69 deletions.
101 changes: 32 additions & 69 deletions Examples/GarageMote/GarageMote.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Can trigger door open/close
// http://www.LowPowerLab.com/GarageMote
// **********************************************************************************
// Copyright Felix Rusu 2016, http://www.LowPowerLab.com/contact
// Copyright Felix Rusu 2018, http://www.LowPowerLab.com/contact
// **********************************************************************************
// License
// **********************************************************************************
Expand Down Expand Up @@ -37,16 +37,15 @@

//For WeatherShield with BME280 see the WeatherNode example
#ifdef WEATHERSHIELD
#include <SFE_BMP180.h> //get it here: https://github.com/LowPowerLab/SFE_BMP180
#include <SI7021.h> //get it here: https://github.com/LowPowerLab/SI7021
#include <SparkFunBME280.h> //get it here: https://github.com/sparkfun/SparkFun_BME280_Arduino_Library/tree/master/src
#include <Wire.h>
#endif
//****************************************************************************************************************
//**** IMPORTANT RADIO SETTINGS - YOU MUST CHANGE/CONFIGURE TO MATCH YOUR HARDWARE TRANSCEIVER CONFIGURATION! ****
//****************************************************************************************************************
#define GATEWAYID 1
#define NODEID 11
#define NETWORKID 250
#define NETWORKID 100
//#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ
#define FREQUENCY RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
Expand Down Expand Up @@ -94,8 +93,7 @@
#endif

#ifdef WEATHERSHIELD
SI7021 weatherShield_SI7021;
SFE_BMP180 weatherShield_BMP180;
BME280 bme280;
#endif

//function prototypes
Expand All @@ -112,6 +110,9 @@ unsigned long lastWeatherSent=0;
int ledPulseValue=0;
boolean ledPulseDirection=false; //false=down, true=up
char Pstr[10];
char Fstr[10];
char Hstr[10];
double F,P,H;
char sendBuf[30];
SPIFlash flash(8, 0xEF30); //WINDBOND 4MBIT flash chip on CS pin D8 (default for Moteino)

Expand Down Expand Up @@ -155,17 +156,27 @@ void setup(void)
else setStatus(STATUS_UNKNOWN);

#ifdef WEATHERSHIELD
//initialize weather shield sensors
weatherShield_SI7021.begin();
if (weatherShield_BMP180.begin())
{ DEBUGln("BMP180 init success"); }
else { DEBUGln("BMP180 init fail\n"); }
Wire.begin();
Wire.setClock(400000); //Increase to fast I2C speed!

//initialize weather shield BME280 sensor
bme280.setI2CAddress(0x77); //0x76,0x77 is valid.
bme280.beginI2C();
bme280.setMode(MODE_SLEEP); //MODE_SLEEP, MODE_FORCED, MODE_NORMAL is valid. See 3.3
bme280.setStandbyTime(0); //0 to 7 valid. Time between readings. See table 27.
bme280.setFilter(0); //0 to 4 is valid. Filter coefficient. See 3.4.4
bme280.setTempOverSample(1); //0 to 16 are valid. 0 disables temp sensing. See table 24.
bme280.setPressureOverSample(1); //0 to 16 are valid. 0 disables pressure sensing. See table 23.
bme280.setHumidityOverSample(1); //0 to 16 are valid. 0 disables humidity sensing. See table 19.
P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg
F = bme280.readTempF();
H = bme280.readFloatHumidity();

#endif
}

unsigned long doorPulseCount = 0;
char input=0;
double P;

void loop()
{
Expand Down Expand Up @@ -312,10 +323,16 @@ void loop()
if (millis()-lastWeatherSent > WEATHERSENDDELAY)
{
lastWeatherSent = millis();
P = getPressure();
P*=0.0295333727; //transform to inHg
bme280.setMode(MODE_FORCED); //Wake up sensor and take reading
P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg
F = bme280.readTempF();
H = bme280.readFloatHumidity();

dtostrf(F, 3,2, Fstr);
dtostrf(H, 3,2, Hstr);
dtostrf(P, 3,2, Pstr);
sprintf(sendBuf, "F:%d H:%d P:%s", weatherShield_SI7021.getFahrenheitHundredths(), weatherShield_SI7021.getHumidityPercent(), Pstr);

sprintf(sendBuf, "F:%s H:%s P:%s", Fstr, Hstr, Pstr);
byte sendLen = strlen(sendBuf);
radio.send(GATEWAYID, sendBuf, sendLen);
}
Expand Down Expand Up @@ -366,57 +383,3 @@ void Blink(byte PIN, byte DELAY_MS)
delay(DELAY_MS);
digitalWrite(PIN,LOW);
}

#ifdef WEATHERSHIELD
double getPressure()
{
char status;
double T,P,p0,a;
// If you want sea-level-compensated pressure, as used in weather reports,
// you will need to know the altitude at which your measurements are taken.
// We're using a constant called ALTITUDE in this sketch:

// If you want to measure altitude, and not pressure, you will instead need
// to provide a known baseline pressure. This is shown at the end of the sketch.
// You must first get a temperature measurement to perform a pressure reading.
// Start a temperature measurement:
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = weatherShield_BMP180.startTemperature();
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);

// Retrieve the completed temperature measurement:
// Note that the measurement is stored in the variable T.
// Function returns 1 if successful, 0 if failure.
status = weatherShield_BMP180.getTemperature(T);
if (status != 0)
{
// Start a pressure measurement:
// The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
// If request is successful, the number of ms to wait is returned.
// If request is unsuccessful, 0 is returned.
status = weatherShield_BMP180.startPressure(3);
if (status != 0)
{
// Wait for the measurement to complete:
delay(status);

// Retrieve the completed pressure measurement:
// Note that the measurement is stored in the variable P.
// Note also that the function requires the previous temperature measurement (T).
// (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
// Function returns 1 if successful, 0 if failure.
status = weatherShield_BMP180.getPressure(P,T);
if (status != 0)
{
return P;
}
}
}
}
return 0;
}
#endif

0 comments on commit 98d77db

Please sign in to comment.