Merge pull request #101 from LukaGitH/master

Updated to new BME280 lib
This commit is contained in:
Felix Rusu 2018-05-01 17:46:22 -04:00 committed by GitHub
commit c7bddb1f78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 101 additions and 111 deletions

View File

@ -4,7 +4,7 @@
// Can trigger door open/close // Can trigger door open/close
// http://www.LowPowerLab.com/GarageMote // http://www.LowPowerLab.com/GarageMote
// ********************************************************************************** // **********************************************************************************
// Copyright Felix Rusu 2016, http://www.LowPowerLab.com/contact // Copyright Felix Rusu 2018, http://www.LowPowerLab.com/contact
// ********************************************************************************** // **********************************************************************************
// License // License
// ********************************************************************************** // **********************************************************************************
@ -37,8 +37,7 @@
//For WeatherShield with BME280 see the WeatherNode example //For WeatherShield with BME280 see the WeatherNode example
#ifdef WEATHERSHIELD #ifdef WEATHERSHIELD
#include <SFE_BMP180.h> //get it here: https://github.com/LowPowerLab/SFE_BMP180 #include <SparkFunBME280.h> //get it here: https://github.com/sparkfun/SparkFun_BME280_Arduino_Library/tree/master/src
#include <SI7021.h> //get it here: https://github.com/LowPowerLab/SI7021
#include <Wire.h> #include <Wire.h>
#endif #endif
//**************************************************************************************************************** //****************************************************************************************************************
@ -46,7 +45,7 @@
//**************************************************************************************************************** //****************************************************************************************************************
#define GATEWAYID 1 #define GATEWAYID 1
#define NODEID 11 #define NODEID 11
#define NETWORKID 250 #define NETWORKID 100
//#define FREQUENCY RF69_433MHZ //#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ //#define FREQUENCY RF69_868MHZ
#define FREQUENCY RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ) #define FREQUENCY RF69_915MHZ //Match this with the version of your Moteino! (others: RF69_433MHZ, RF69_868MHZ)
@ -94,8 +93,7 @@
#endif #endif
#ifdef WEATHERSHIELD #ifdef WEATHERSHIELD
SI7021 weatherShield_SI7021; BME280 bme280;
SFE_BMP180 weatherShield_BMP180;
#endif #endif
//function prototypes //function prototypes
@ -112,6 +110,9 @@ unsigned long lastWeatherSent=0;
int ledPulseValue=0; int ledPulseValue=0;
boolean ledPulseDirection=false; //false=down, true=up boolean ledPulseDirection=false; //false=down, true=up
char Pstr[10]; char Pstr[10];
char Fstr[10];
char Hstr[10];
double F,P,H;
char sendBuf[30]; char sendBuf[30];
SPIFlash flash(8, 0xEF30); //WINDBOND 4MBIT flash chip on CS pin D8 (default for Moteino) SPIFlash flash(8, 0xEF30); //WINDBOND 4MBIT flash chip on CS pin D8 (default for Moteino)
@ -155,17 +156,27 @@ void setup(void)
else setStatus(STATUS_UNKNOWN); else setStatus(STATUS_UNKNOWN);
#ifdef WEATHERSHIELD #ifdef WEATHERSHIELD
//initialize weather shield sensors Wire.begin();
weatherShield_SI7021.begin(); Wire.setClock(400000); //Increase to fast I2C speed!
if (weatherShield_BMP180.begin())
{ DEBUGln("BMP180 init success"); } //initialize weather shield BME280 sensor
else { DEBUGln("BMP180 init fail\n"); } 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 #endif
} }
unsigned long doorPulseCount = 0; unsigned long doorPulseCount = 0;
char input=0; char input=0;
double P;
void loop() void loop()
{ {
@ -312,10 +323,16 @@ void loop()
if (millis()-lastWeatherSent > WEATHERSENDDELAY) if (millis()-lastWeatherSent > WEATHERSENDDELAY)
{ {
lastWeatherSent = millis(); lastWeatherSent = millis();
P = getPressure(); bme280.setMode(MODE_FORCED); //Wake up sensor and take reading
P*=0.0295333727; //transform to inHg 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); 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); byte sendLen = strlen(sendBuf);
radio.send(GATEWAYID, sendBuf, sendLen); radio.send(GATEWAYID, sendBuf, sendLen);
} }
@ -366,57 +383,3 @@ void Blink(byte PIN, byte DELAY_MS)
delay(DELAY_MS); delay(DELAY_MS);
digitalWrite(PIN,LOW); 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

View File

@ -6,7 +6,7 @@
// IMPORTANT: adjust the settings in the configuration section below !!! // IMPORTANT: adjust the settings in the configuration section below !!!
// ********************************************************************************** // **********************************************************************************
// Copyright Felix Rusu of LowPowerLab.com, 2016 // Copyright Felix Rusu of LowPowerLab.com, 2018
// RFM69 library and sample code by Felix Rusu - lowpowerlab.com/contact // RFM69 library and sample code by Felix Rusu - lowpowerlab.com/contact
// ********************************************************************************** // **********************************************************************************
// License // License
@ -29,21 +29,21 @@
// Please maintain this license information along with authorship // Please maintain this license information along with authorship
// and copyright notices in any redistribution of this code // and copyright notices in any redistribution of this code
// ********************************************************************************** // **********************************************************************************
#include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69 #include <RFM69.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <RFM69_ATC.h>//get it here: https://www.github.com/lowpowerlab/rfm69 #include <RFM69_ATC.h> //get it here: https://www.github.com/lowpowerlab/rfm69
#include <SPI.h> //comes with Arduino IDE (www.arduino.cc) #include <SPI.h> //comes with Arduino IDE (www.arduino.cc)
#include <LowPower.h> //get library from: https://github.com/lowpowerlab/lowpower #include <LowPower.h> //get library from: https://github.com/lowpowerlab/lowpower
//writeup here: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/ //writeup here: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/
#include <SPIFlash.h> //get it here: https://www.github.com/lowpowerlab/spiflash #include <SPIFlash.h> //get it here: https://www.github.com/lowpowerlab/spiflash
#include <SparkFunBME280.h> //get it here: https://github.com/sparkfun/SparkFun_BME280_Breakout_Board/tree/master/Libraries/Arduino/src #include <SparkFunBME280.h>//get it here: https://github.com/sparkfun/SparkFun_BME280_Arduino_Library/tree/master/src
#include <Wire.h> //comes with Arduino #include <Wire.h> //comes with Arduino
//**************************************************************************************************************** //****************************************************************************************************************
//**** IMPORTANT RADIO SETTINGS - YOU MUST CHANGE/CONFIGURE TO MATCH YOUR HARDWARE TRANSCEIVER CONFIGURATION! **** //**** IMPORTANT RADIO SETTINGS - YOU MUST CHANGE/CONFIGURE TO MATCH YOUR HARDWARE TRANSCEIVER CONFIGURATION! ****
//**************************************************************************************************************** //****************************************************************************************************************
#define GATEWAYID 1
#define NODEID 88 //unique for each node on same network #define NODEID 88 //unique for each node on same network
#define NETWORKID 100 //the same on all nodes that talk to each other #define NETWORKID 100 //the same on all nodes that talk to each other
#define GATEWAYID 1
//Match frequency to the hardware version of the radio on your Moteino (uncomment one): //Match frequency to the hardware version of the radio on your Moteino (uncomment one):
//#define FREQUENCY RF69_433MHZ //#define FREQUENCY RF69_433MHZ
//#define FREQUENCY RF69_868MHZ //#define FREQUENCY RF69_868MHZ
@ -96,8 +96,10 @@ char BATstr[10]; //longest battery voltage reading message = 9chars
char sendBuf[32]; char sendBuf[32];
byte sendLen; byte sendLen;
#ifdef ENABLE_BME280 #ifdef ENABLE_BME280
float temperature=0; double F,P,H;
char Pstr[10];
char Fstr[10]; char Fstr[10];
char Hstr[10];
#endif #endif
void motionIRQ(void); void motionIRQ(void);
@ -135,14 +137,22 @@ void setup() {
if (flash.initialize()) flash.sleep(); //if Moteino has FLASH-MEM, make sure it sleeps if (flash.initialize()) flash.sleep(); //if Moteino has FLASH-MEM, make sure it sleeps
#ifdef ENABLE_BME280 #ifdef ENABLE_BME280
bme280.settings.commInterface = I2C_MODE;
bme280.settings.I2CAddress = 0x77; Wire.begin();
bme280.settings.runMode = 3; //Normal mode Wire.setClock(400000); //Increase to fast I2C speed!
bme280.settings.tStandby = 0;
bme280.settings.filter = 0; //initialize weather shield BME280 sensor
bme280.settings.tempOverSample = 1; bme280.setI2CAddress(0x77); //0x76,0x77 is valid.
bme280.settings.pressOverSample = 1; bme280.beginI2C();
bme280.settings.humidOverSample = 1; 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 #endif
} }
@ -167,10 +177,16 @@ void loop() {
#ifdef ENABLE_BME280 #ifdef ENABLE_BME280
//read BME sensor //read BME sensor
bme280.begin(); bme280.setMode(MODE_FORCED); //Wake up sensor and take reading
dtostrf(bme280.readTempF(), 3,2, Fstr); P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg
bme280.writeRegister(BME280_CTRL_MEAS_REG, 0x00); //sleep the BME280 F = bme280.readTempF();
sprintf(sendBuf, "MOTION BAT:%sv F:%s", BATstr, Fstr); H = bme280.readFloatHumidity();
dtostrf(F, 3,2, Fstr);
dtostrf(H, 3,2, Hstr);
dtostrf(P, 3,2, Pstr);
sprintf(sendBuf, "MOTION BAT:%sv F:%s H:%s P:%s", BATstr, Fstr, Hstr, Pstr);
#else #else
sprintf(sendBuf, "MOTION BAT:%sv", BATstr); sprintf(sendBuf, "MOTION BAT:%sv", BATstr);
#endif #endif
@ -195,10 +211,16 @@ void loop() {
{ {
#ifdef ENABLE_BME280 #ifdef ENABLE_BME280
//read BME sensor //read BME sensor
bme280.begin(); bme280.setMode(MODE_FORCED); //Wake up sensor and take reading
dtostrf(bme280.readTempF(), 3,2, Fstr); P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg
bme280.writeRegister(BME280_CTRL_MEAS_REG, 0x00); //sleep the BME280 F = bme280.readTempF();
sprintf(sendBuf, "BAT:%sv F:%s", BATstr, Fstr); H = bme280.readFloatHumidity();
dtostrf(F, 3,2, Fstr);
dtostrf(H, 3,2, Hstr);
dtostrf(P, 3,2, Pstr);
sprintf(sendBuf, "MOTION BAT:%sv F:%s H:%s P:%s", BATstr, Fstr, Hstr, Pstr);
#else #else
sprintf(sendBuf, "BAT:%sv", BATstr); sprintf(sendBuf, "BAT:%sv", BATstr);
#endif #endif
@ -246,4 +268,4 @@ void checkBattery()
batteryVolts = BATT_FORMULA(readings / 10.0); batteryVolts = BATT_FORMULA(readings / 10.0);
dtostrf(batteryVolts, 3,2, BATstr); //update the BATStr which gets sent every BATT_CYCLES or along with the MOTION message dtostrf(batteryVolts, 3,2, BATstr); //update the BATStr which gets sent every BATT_CYCLES or along with the MOTION message
} }
} }

View File

@ -5,7 +5,7 @@
// http://www.LowPowerLab.com/WeatherShield // http://www.LowPowerLab.com/WeatherShield
// Example setup (with R1): http://lowpowerlab.com/blog/2015/07/24/attic-fan-cooling-tests/ // Example setup (with R1): http://lowpowerlab.com/blog/2015/07/24/attic-fan-cooling-tests/
// ********************************************************************************** // **********************************************************************************
// Copyright Felix Rusu 2016, http://www.LowPowerLab.com/contact // Copyright Felix Rusu 2018, http://www.LowPowerLab.com/contact
// ********************************************************************************** // **********************************************************************************
// License // License
// ********************************************************************************** // **********************************************************************************
@ -33,7 +33,7 @@
#include <SPIFlash.h> //get it here: https://github.com/lowpowerlab/spiflash #include <SPIFlash.h> //get it here: https://github.com/lowpowerlab/spiflash
#include <SPI.h> //included in Arduino IDE (www.arduino.cc) #include <SPI.h> //included in Arduino IDE (www.arduino.cc)
#include <Wire.h> //included in Arduino IDE (www.arduino.cc) #include <Wire.h> //included in Arduino IDE (www.arduino.cc)
#include <SparkFunBME280.h>//get it here: https://github.com/sparkfun/SparkFun_BME280_Breakout_Board/tree/master/Libraries/Arduino/src #include <SparkFunBME280.h>//get it here: https://github.com/sparkfun/SparkFun_BME280_Arduino_Library/tree/master/src
#include <LowPower.h> //get it here: https://github.com/lowpowerlab/lowpower #include <LowPower.h> //get it here: https://github.com/lowpowerlab/lowpower
//writeup here: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/ //writeup here: http://www.rocketscream.com/blog/2011/07/04/lightweight-low-power-arduino-library/
@ -104,6 +104,7 @@ BME280 bme280;
char Pstr[10]; char Pstr[10];
char Fstr[10]; char Fstr[10];
char Hstr[10]; char Hstr[10];
double F,P,H;
char buffer[50]; char buffer[50];
void setup(void) void setup(void)
@ -130,15 +131,21 @@ void setup(void)
sprintf(buffer, "WeatherMote - transmitting at: %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915); sprintf(buffer, "WeatherMote - transmitting at: %d Mhz...", FREQUENCY==RF69_433MHZ ? 433 : FREQUENCY==RF69_868MHZ ? 868 : 915);
DEBUGln(buffer); DEBUGln(buffer);
Wire.begin();
Wire.setClock(400000); //Increase to fast I2C speed!
//initialize weather shield BME280 sensor //initialize weather shield BME280 sensor
bme280.settings.commInterface = I2C_MODE; bme280.setI2CAddress(0x77); //0x76,0x77 is valid.
bme280.settings.I2CAddress = 0x77; bme280.beginI2C();
bme280.settings.runMode = 3; //Normal mode bme280.setMode(MODE_SLEEP); //MODE_SLEEP, MODE_FORCED, MODE_NORMAL is valid. See 3.3
bme280.settings.tStandby = 0; bme280.setStandbyTime(0); //0 to 7 valid. Time between readings. See table 27.
bme280.settings.filter = 0; bme280.setFilter(0); //0 to 4 is valid. Filter coefficient. See 3.4.4
bme280.settings.tempOverSample = 1; bme280.setTempOverSample(1); //0 to 16 are valid. 0 disables temp sensing. See table 24.
bme280.settings.pressOverSample = 1; bme280.setPressureOverSample(1); //0 to 16 are valid. 0 disables pressure sensing. See table 23.
bme280.settings.humidOverSample = 1; 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();
radio.sendWithRetry(GATEWAYID, "START", 6); radio.sendWithRetry(GATEWAYID, "START", 6);
Blink(LED, 100);Blink(LED, 100);Blink(LED, 100); Blink(LED, 100);Blink(LED, 100);Blink(LED, 100);
@ -159,7 +166,6 @@ void setup(void)
unsigned long doorPulseCount = 0; unsigned long doorPulseCount = 0;
char input=0; char input=0;
double F,P,H;
byte sendLoops=0; byte sendLoops=0;
byte battReadLoops=0; byte battReadLoops=0;
float batteryVolts = 5; float batteryVolts = 5;
@ -179,12 +185,11 @@ void loop()
sendLoops = SEND_LOOPS-1; sendLoops = SEND_LOOPS-1;
//read BME sensor //read BME sensor
bme280.begin(); bme280.setMode(MODE_FORCED); //Wake up sensor and take reading
P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg P = bme280.readFloatPressure() * 0.0002953; //read Pa and convert to inHg
F = bme280.readTempF(); F = bme280.readTempF();
H = bme280.readFloatHumidity(); H = bme280.readFloatHumidity();
bme280.writeRegister(BME280_CTRL_MEAS_REG, 0x00); //sleep the BME280
dtostrf(F, 3,2, Fstr); dtostrf(F, 3,2, Fstr);
dtostrf(H, 3,2, Hstr); dtostrf(H, 3,2, Hstr);
dtostrf(P, 3,2, Pstr); dtostrf(P, 3,2, Pstr);