From 680278da6b891f9899c383ded084b52afcc5f3b9 Mon Sep 17 00:00:00 2001 From: Alexandre B Date: Sun, 7 Jul 2024 13:54:49 -0400 Subject: [PATCH] . --- ESP32-BME280/platformio.ini | 4 ++-- ESP32-BME280/src/main.cpp | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ESP32-BME280/platformio.ini b/ESP32-BME280/platformio.ini index eaa725cc8..73541d115 100644 --- a/ESP32-BME280/platformio.ini +++ b/ESP32-BME280/platformio.ini @@ -13,9 +13,9 @@ platform = espressif32 board = esp32dev framework = arduino monitor_speed = 115200 - lib_deps = - adafruit/Adafruit BME280 Library@^2.2.2 + adafruit/Adafruit BME280 Library@^2.2.2 + adafruit/Adafruit BMP280 Library@^2.6.8 [platformio] description = ESP32 Sensors node diff --git a/ESP32-BME280/src/main.cpp b/ESP32-BME280/src/main.cpp index 661b90c52..0d6659870 100644 --- a/ESP32-BME280/src/main.cpp +++ b/ESP32-BME280/src/main.cpp @@ -1,10 +1,14 @@ #include #include +#include #include -// BME280 +#define BMP280 + Adafruit_BME280 bme; +Adafruit_BMP280 bmp; + struct { float humidity = 0.0; float pressure = 0.0; @@ -20,11 +24,12 @@ void setup() { sensors_values.pressure = 0.0; sensors_values.temperature = 0.0; - // WaveShare BME280 + #ifdef BME280 + // BME280 unsigned status = bme.begin(0x76); // I2C slave address 0x76 (SDO set to GND) if (!status) { Serial.println("Could not find a valid BME/BMP280 sensor, check wiring!"); - Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16); + Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(), 16); Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); Serial.print(" ID of 0x60 represents a BME 280.\n"); @@ -36,6 +41,20 @@ void setup() { sensors_values.pressure = bme.readPressure() / 100.0F; sensors_values.temperature = bme.readTemperature(); } + #endif + #ifdef BMP280 + unsigned status = bmp.begin(); + if (!status) { + Serial.println("Could not find a valid BME/BMP280 sensor, check wiring!"); + Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(), 16); + Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n"); + Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n"); + Serial.print(" ID of 0x60 represents a BME 280.\n"); + Serial.print(" ID of 0x61 represents a BME 680.\n"); + while (1); + } + else {} + #endif } void loop() {