Snorktracker
 All Data Structures Files Functions Variables Macros Pages
Public Member Functions | Protected Attributes
MyBME280 Class Reference

#include <BME280.h>

Public Member Functions

 MyBME280 (MyOptions &options, MyData &data, int pin, uint8_t addr)
 
bool begin ()
 
bool readValues ()
 

Protected Attributes

MyOptionsmyOptions
 Reference to global options.
 
MyDatamyData
 Reference to global data.
 
int pinGrnd
 Ground-Pin connection to switch on the BME280 module.
 
uint8_t portAddr
 Port address of the bme280.
 
Adafruit_BME280 bme280
 Adafruit BME280 helper interface.
 

Detailed Description

Communication with the BME280 modul to read temperature, humidity and pressure

Definition at line 32 of file BME280.h.

Constructor & Destructor Documentation

MyBME280::MyBME280 ( MyOptions options,
MyData data,
int  pin,
uint8_t  addr 
)

Constructor

Definition at line 52 of file BME280.h.

53  : pinGrnd(pin)
54  , myOptions(options)
55  , myData(data)
56  , portAddr(addr)
57 {
58 }
int pinGrnd
Ground-Pin connection to switch on the BME280 module.
Definition: BME280.h:37
MyOptions & myOptions
Reference to global options.
Definition: BME280.h:35
uint8_t portAddr
Port address of the bme280.
Definition: BME280.h:38
MyData & myData
Reference to global data.
Definition: BME280.h:36

Member Function Documentation

bool MyBME280::begin ( )

Switch off the module at startup to safe power.

Definition at line 61 of file BME280.h.

References pinGrnd.

Referenced by setup().

62 {
63  pinMode(D1, INPUT); // I2C SCL Open state to safe power
64  pinMode(D2, INPUT); // I2C SDA Open state to safe power
65  pinMode(pinGrnd, OUTPUT);
66  digitalWrite(pinGrnd, HIGH);
67 }
int pinGrnd
Ground-Pin connection to switch on the BME280 module.
Definition: BME280.h:37
bool MyBME280::readValues ( )

Switch on the modul, read the values and switch off the modul to save power. Do this only every bme280CheckIntervalSec

Definition at line 73 of file BME280.h.

References BARO_CORR_HPA, bme280, MyOptions::bme280CheckIntervalSec, MyData::humidity, MyData::RtcData::lastBme280ReadSec, myData, MyDbg(), myOptions, pinGrnd, portAddr, MyData::pressure, MyData::rtcData, secondsElapsedAndUpdate(), TEMP_CORR_DEGREE, and MyData::temperature.

Referenced by loop().

74 {
76  digitalWrite(pinGrnd, LOW);
77  delay(100); // Short delay after power on
78  if (!bme280.begin(portAddr)) {
79  myData.temperature = 0;
80  myData.humidity = 0;
81  myData.pressure = 0;
82  MyDbg("No valid BME280 sensor, check wiring!");
83  } else {
84  myData.temperature = bme280.readTemperature() + TEMP_CORR_DEGREE;
85  myData.humidity = bme280.readHumidity();
86  myData.pressure = (bme280.readPressure() / 100.0F) + BARO_CORR_HPA;
87  MyDbg("Temperature: " + String(myData.temperature) + "°C");
88  MyDbg("Humidity: " + String(myData.humidity) + "%");
89  MyDbg("Pressure: " + String(myData.pressure) + "hPa");
90  }
91  digitalWrite(pinGrnd, HIGH);
92  pinMode(D1, INPUT); // I2C SCL Open state to safe power
93  pinMode(D2, INPUT); // I2C SDA Open state to safe power
94  }
95 }
class MyData::RtcData rtcData
Data to store in the RTC memory.
#define TEMP_CORR_DEGREE
The BME280 measure 2 degrees too high.
Definition: BME280.h:27
void MyDbg(String info, bool fromWebServer=false, bool newline=true)
Definition: Utils.h:94
Adafruit_BME280 bme280
Adafruit BME280 helper interface.
Definition: BME280.h:39
int pinGrnd
Ground-Pin connection to switch on the BME280 module.
Definition: BME280.h:37
double temperature
Current BME280 temperature.
Definition: Data.h:75
double pressure
Current BME280 pressure.
Definition: Data.h:77
MyOptions & myOptions
Reference to global options.
Definition: BME280.h:35
uint8_t portAddr
Port address of the bme280.
Definition: BME280.h:38
long bme280CheckIntervalSec
Time interval to read the temp, hum and pressure.
Definition: Options.h:40
#define BARO_CORR_HPA
Correction for 289m above sea level.
Definition: BME280.h:26
MyData & myData
Reference to global data.
Definition: BME280.h:36
double humidity
Current BME280 humidity.
Definition: Data.h:76
long lastBme280ReadSec
Timestamp of the last BME280 read.
Definition: Data.h:45
bool secondsElapsedAndUpdate(long &lastCheckSec, const long &intervalSec)
Definition: Utils.h:63

The documentation for this class was generated from the following file: