From e08bf4d64a59ab964cc48d666d94724277fa8bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cristiano=20Jos=C3=A9=20Sulzbach?= Date: Sun, 8 Dec 2019 09:58:12 -0200 Subject: [PATCH] Added support for Bosch BMP180 sensor --- README.md | 4 ++-- include/bmesensor.h | 2 ++ platformio.ini | 1 + src/bmesensor.cpp | 28 ++++++++++++++++++++++++++++ src/cyclic.cpp | 3 +++ src/hal/generic.h | 4 ++++ src/hal/heltecv2.h | 2 ++ src/main.cpp | 2 ++ 8 files changed, 44 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8a82a062..33a0b26c 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ Depending on board hardware following features are supported: - Silicon unique ID - Battery voltage monitoring - GPS (Generic serial NMEA, or Quectel L76 I2C) -- Environmental sensor (Bosch BME280/BME680 I2C) +- Environmental sensor (Bosch BMP180/BME280/BME680 I2C) - Real Time Clock (Maxim DS3231 I2C) - IF482 (serial) and DCF77 (gpio) time telegram generator - Switch external power / battery @@ -163,7 +163,7 @@ by pressing the button of the device. # Sensors and Peripherals -You can add up to 3 user defined sensors. Insert sensor's payload scheme in [*sensor.cpp*](src/sensor.cpp). Bosch BME280 / BME680 environment sensors are supported. Enable flag *lib_deps_sensors* for your board in [*platformio.ini*](src/platformio.ini) and configure BME in board's hal file before build. If you need Bosch's proprietary BSEC libraray (e.g. to get indoor air quality value from BME680) further enable *build_flags_sensors*, which comes on the price of reduced RAM and increased build size. RTC DS3231, generic serial NMEA GPS, I2C LoPy GPS are supported, and to be configured in board's hal file. See [*generic.h*](src/hal/generic.h) for all options and for proper configuration of BME280/BME680. +You can add up to 3 user defined sensors. Insert sensor's payload scheme in [*sensor.cpp*](src/sensor.cpp). Bosch BMP180 / BME280 / BME680 environment sensors are supported. Enable flag *lib_deps_sensors* for your board in [*platformio.ini*](src/platformio.ini) and configure BME in board's hal file before build. If you need Bosch's proprietary BSEC libraray (e.g. to get indoor air quality value from BME680) further enable *build_flags_sensors*, which comes on the price of reduced RAM and increased build size. RTC DS3231, generic serial NMEA GPS, I2C LoPy GPS are supported, and to be configured in board's hal file. See [*generic.h*](src/hal/generic.h) for all options and for proper configuration of BME280/BME680. Output of user sensor data can be switched by user remote control command 0x14 sent to Port 2. diff --git a/include/bmesensor.h b/include/bmesensor.h index 2d1ec9ce..eedb5e79 100644 --- a/include/bmesensor.h +++ b/include/bmesensor.h @@ -9,6 +9,8 @@ #elif defined HAS_BME280 #include #include +#elif defined HAS_BMP180 +#include #endif extern Ticker bmecycler; diff --git a/platformio.ini b/platformio.ini index 0057560b..956ff4bb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -70,6 +70,7 @@ lib_deps_gps = lib_deps_sensors = Adafruit Unified Sensor@>=1.0.3 Adafruit BME280 Library@>=1.0.10 + Adafruit BMP085 Library@>=1.0.1 lib_deps_basic = ArduinoJson@^5.13.1 76@>=1.2.2 ; #76 Timezone by Jack Christensen diff --git a/src/bmesensor.cpp b/src/bmesensor.cpp index 4a53bf89..a28f6005 100644 --- a/src/bmesensor.cpp +++ b/src/bmesensor.cpp @@ -36,6 +36,10 @@ Adafruit_BME280 bme; // I2C // Adafruit_BME280 bme(BME_CS); // hardware SPI // Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI +#elif defined HAS_BMP180 + +Adafruit_BMP085 bmp; // I2C + #endif void bmecycle() { xTaskNotify(irqHandlerTask, BME_IRQ, eSetBits); } @@ -105,8 +109,26 @@ int bme_init(void) { goto finish; } +#elif defined HAS_BMP180 + bool status; + // block i2c bus access + if (I2C_MUTEX_LOCK()) { + // Wire.begin(21, 22); + status = bmp.begin(); + if (!status) { + ESP_LOGE(TAG, "BMP180 sensor not found"); + rc = 0; + goto finish; + } + ESP_LOGI(TAG, "BMP180 sensor found and initialized"); + } else { + ESP_LOGE(TAG, "I2c bus busy - BMP180 initialization error"); + rc = 0; + goto finish; + } #endif + finish: I2C_MUTEX_UNLOCK(); // release i2c bus access if (rc) @@ -168,6 +190,12 @@ void bme_storedata(bmeStatus_t *bme_store) { // bme.readAltitude(SEALEVELPRESSURE_HPA); bme_store->humidity = bme.readHumidity(); bme_store->iaq = 0; // IAQ feature not present with BME280 +#elif defined HAS_BMP180 + bme_store->temperature = bmp.readTemperature(); + bme_store->pressure = (bmp.readPressure() / 100.0); // conversion Pa -> hPa + // bme.readAltitude(SEALEVELPRESSURE_HPA); + // bme_store->humidity = bme.readHumidity(); + bme_store->iaq = 0; // IAQ feature not present with BME280 #endif I2C_MUTEX_UNLOCK(); // release i2c bus access diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 569ed772..6a23c08d 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -81,6 +81,9 @@ void doHousekeeping() { #elif defined HAS_BME280 ESP_LOGI(TAG, "BME280 Temp: %.2f°C | Humidity: %.2f | Pressure: %.0f", bme_status.temperature, bme_status.humidity, bme_status.pressure); +#elif defined HAS_BMP180 + ESP_LOGI(TAG, "BMP180 Temp: %.2f°C | Pressure: %.0f", + bme_status.temperature, bme_status.pressure); #endif #endif diff --git a/src/hal/generic.h b/src/hal/generic.h index 909bef38..1990c736 100644 --- a/src/hal/generic.h +++ b/src/hal/generic.h @@ -36,6 +36,10 @@ //#define HAS_BME280 GPIO_NUM_21, GPIO_NUM_22 // SDA, SCL //#define BME280_ADDR 0x76 // change to 0x77 depending on your wiring +// BMP180 sensor on I2C bus +//#define HAS_BMP180 +//#define BMP180_ADDR 0x77 + // user defined sensors //#define HAS_SENSORS 1 // comment out if device has user defined sensors diff --git a/src/hal/heltecv2.h b/src/hal/heltecv2.h index 96024e38..efbb9526 100644 --- a/src/hal/heltecv2.h +++ b/src/hal/heltecv2.h @@ -12,6 +12,8 @@ //#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_BMP180 +//#define BMP180_ADDR 0x77 #define HAS_LORA 1 // comment out if device shall not send data via LoRa #define CFG_sx1276_radio 1 diff --git a/src/main.cpp b/src/main.cpp index 774a0b45..6418fb36 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -390,6 +390,8 @@ void setup() { strcat_P(features, " BME680"); #elif defined HAS_BME280 strcat_P(features, " BME280"); +#elif defined HAS_BMP180 + strcat_P(features, " BMP180"); #endif if (bme_init()) ESP_LOGI(TAG, "Starting BME sensor...");