Support for BME280

This commit is contained in:
Gregor Wolf committed 2019-03-08 18:13:51 +01:00
1 parent a6663d44b5
commit 91cc9dba0c
15 files changed
+151 -27

No files matched your search

+63
View File
@@ -0,0 +1,63 @@
#ifdef HAS_BME280
#include "bme280.h"
// Local logging tag
static const char TAG[] = __FILE__;
bmeStatus_t bme_status;
TaskHandle_t Bme280Task;
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
// initialize BME280 sensor
int bme280_init(void) {
bool status;
// return = 0 -> error / return = 1 -> success
// block i2c bus access
if (I2C_MUTEX_LOCK()) {
status = bme.begin(BME280_ADDR);
if (!status) {
ESP_LOGE(TAG, "BME280 sensor not found");
goto error;
}
ESP_LOGI(TAG, "BME280 sensor found and initialized");
} else {
ESP_LOGE(TAG, "I2c bus busy - BME280 initialization error");
goto error;
}
I2C_MUTEX_UNLOCK(); // release i2c bus access
return 1;
error:
I2C_MUTEX_UNLOCK(); // release i2c bus access
return 0;
} // bme_init()
// loop function which reads and processes data based on sensor settings
void bme280_loop(void *pvParameters) {
#ifdef HAS_BME280
while (1) {
if (I2C_MUTEX_LOCK()) {
bme_status.temperature = bme.readTemperature();
bme_status.pressure = (bme.readPressure() / 100.0); // conversion Pa -> hPa
// bme.readAltitude(SEALEVELPRESSURE_HPA);
bme_status.humidity = bme.readHumidity();
I2C_MUTEX_UNLOCK();
}
}
#endif
ESP_LOGE(TAG, "BME task ended");
vTaskDelete(Bme280Task); // should never be reached
} // bme_loop()
#endif // HAS_BME280
+5 -5
View File
@@ -1,4 +1,4 @@
#ifdef HAS_BME
#ifdef HAS_BME680
#include "bme680mems.h"
@@ -34,8 +34,8 @@ int bme_init(void) {
// block i2c bus access
if (I2C_MUTEX_LOCK()) {
Wire.begin(HAS_BME);
iaqSensor.begin(BME_ADDR, Wire);
Wire.begin(HAS_BME680);
iaqSensor.begin(BME680_ADDR, Wire);
ESP_LOGI(TAG, "BSEC v%d.%d.%d.%d", iaqSensor.version.major,
iaqSensor.version.minor, iaqSensor.version.major_bugfix,
@@ -103,7 +103,7 @@ void bme_loop(void *pvParameters) {
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
#ifdef HAS_BME
#ifdef HAS_BME680
while (1) {
// block i2c bus access
if (I2C_MUTEX_LOCK()) {
@@ -168,4 +168,4 @@ void updateState(void) {
}
}
#endif // HAS_BME
#endif // HAS_BME680
+12 -2
View File
@@ -36,10 +36,14 @@ void doHousekeeping() {
ESP_LOGD(TAG, "Gpsloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(GpsTask), eTaskGetState(GpsTask));
#endif
#ifdef HAS_BME
#ifdef HAS_BME680
ESP_LOGD(TAG, "Bmeloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(BmeTask), eTaskGetState(BmeTask));
#endif
#ifdef HAS_BME280
ESP_LOGD(TAG, "Bme280loop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(Bme280Task), eTaskGetState(Bme280Task));
#endif
#ifdef HAS_DCF77
ESP_LOGD(TAG, "Clockloop %d bytes left | Taskstate = %d",
uxTaskGetStackHighWaterMark(ClockTask), eTaskGetState(ClockTask));
@@ -58,11 +62,17 @@ void doHousekeeping() {
#endif
// display BME sensor data
#ifdef HAS_BME
#ifdef HAS_BME680
ESP_LOGI(TAG, "BME680 Temp: %.2f°C | IAQ: %.2f | IAQacc: %d",
bme_status.temperature, bme_status.iaq, bme_status.iaq_accuracy);
#endif
// display BME280 sensor data
#ifdef HAS_BME280
ESP_LOGI(TAG, "BME680 Temp: %.2f°C | Humidity: %.2f | Pressure: %.0f",
bme_status.temperature, bme_status.humidity, bme_status.pressure);
#endif
// check free heap memory
if (ESP.getMinFreeHeap() <= MEM_LOW) {
ESP_LOGI(TAG,
+3 -2
View File
@@ -18,8 +18,9 @@
// enable only if device has these sensors, otherwise comment these lines
// BME680 sensor on I2C bus
#define HAS_BME GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
#define BME_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
#define HAS_BME 1 // Enable BME sensors in general
#define HAS_BME680 GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
#define BME680_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
// user defined sensors
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
+3 -2
View File
@@ -7,8 +7,9 @@
// Hardware related definitions for Heltec V2 LoRa-32 Board
//#define HAS_BME GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
//#define BME_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
//#define HAS_BME 1 // Enable BME sensors in general
//#define HAS_BME680 GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
//#define BME680_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define CFG_sx1276_radio 1
+3 -2
View File
@@ -7,8 +7,9 @@
// Hardware related definitions for Heltec V2 LoRa-32 Board
//#define HAS_BME GPIO_NUM_4, GPIO_NUM_15 // SDA, SCL
//#define BME_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
//#define HAS_BME 1 // Enable BME sensors in general
//#define HAS_BME680 GPIO_NUM_4, GPIO_NUM_15 // SDA, SCL
//#define BME680_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define CFG_sx1276_radio 1
+3 -2
View File
@@ -12,8 +12,9 @@
#define DISABLE_BROWNOUT 1 // comment out if you want to keep brownout feature
// Octopus32 has a pre-populated BME680 on i2c addr 0x76
#define HAS_BME GPIO_NUM_23, GPIO_NUM_22 // SDA, SCL
#define BME_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
#define HAS_BME 1 // Enable BME sensors in general
#define HAS_BME680 GPIO_NUM_23, GPIO_NUM_22 // SDA, SCL
#define BME680_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
// user defined sensors
//#define HAS_SENSORS 1 // comment out if device has user defined sensors
+3 -2
View File
@@ -31,8 +31,9 @@
// enable only if device has these sensors, otherwise comment these lines
// BME680 sensor on I2C bus
#define HAS_BME SDA, SCL
#define BME_ADDR BME680_I2C_ADDR_PRIMARY // !! connect SDIO of BME680 to GND !!
#define HAS_BME 1 // Enable BME sensors in general
#define HAS_BME680 SDA, SCL
#define BME680_ADDR BME680_I2C_ADDR_PRIMARY // !! connect SDIO of BME680 to GND !!
// display (if connected)
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
+6
View File
@@ -13,6 +13,12 @@
#define HAS_LORA 1 // comment out if device shall not send data via LoRa
#define CFG_sx1276_radio 1 // HPD13A LoRa SoC
// enable only if device has these sensors, otherwise comment these lines
// BME680 sensor on I2C bus
#define HAS_BME 1 // Enable BME sensors in general
#define HAS_BME280 GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL
#define BME280_ADDR BME680_I2C_ADDR_PRIMARY // connect SDIO of BME680 to GND
#define HAS_DISPLAY U8X8_SSD1306_128X64_NONAME_HW_I2C
#define HAS_LED (25) // green on board LED
#define HAS_BATTERY_PROBE ADC1_GPIO35_CHANNEL // battery probe GPIO pin -> ADC1_CHANNEL_7
+19 -4
View File
@@ -358,11 +358,11 @@ void setup() {
&irqHandlerTask, // task handle
1); // CPU core
// initialize bme
#ifdef HAS_BME
strcat_P(features, " BME");
// initialize bme680
#ifdef HAS_BME680
strcat_P(features, " BME280");
if (bme_init()) {
ESP_LOGI(TAG, "Starting BME sensor...");
ESP_LOGI(TAG, "Starting BME280 sensor...");
xTaskCreatePinnedToCore(bme_loop, // task function
"bmeloop", // name of task
2048, // stack size of task
@@ -373,6 +373,21 @@ void setup() {
}
#endif
// initialize BME280
#ifdef HAS_BME280
strcat_P(features, " BME280");
if (bme280_init()) {
ESP_LOGI(TAG, "Starting BME280 sensor...");
xTaskCreatePinnedToCore(bme280_loop, // task function
"bme280loop", // name of task
2048, // stack size of task
(void *)1, // parameter of the task
1, // priority of the task
&Bme280Task, // task handle
1); // CPU core
}
#endif
// starting timers and interrupts
assert(irqHandlerTask != NULL); // has interrupt handler task started?
ESP_LOGI(TAG, "Starting Timers...");
+1 -1
View File
@@ -262,7 +262,7 @@ void get_gps(uint8_t val[]) {
void get_bme(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get bme680 sensor data");
#ifdef HAS_BME
#ifdef HAS_BME680
payload.reset();
payload.addBME(bme_status);
SendPayload(BMEPORT, prio_high);