From 4b65a345dab329f7969ac93b07ccf842e88d3949 Mon Sep 17 00:00:00 2001 From: tyeth Date: Wed, 27 Aug 2025 13:51:26 +0100 Subject: [PATCH 1/6] add(bmp581): initial work --- library.properties | 2 +- platformio.ini | 1 + src/components/i2c/WipperSnapper_I2C.cpp | 17 ++- src/components/i2c/WipperSnapper_I2C.h | 2 + .../drivers/WipperSnapper_I2C_Driver_BMP5XX.h | 132 ++++++++++++++++++ 5 files changed, 151 insertions(+), 3 deletions(-) create mode 100644 src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h diff --git a/library.properties b/library.properties index 9ef6dc4a2..d033bfe67 100644 --- a/library.properties +++ b/library.properties @@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper category=Communication url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino architectures=* -depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306 +depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit BMP5xx Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306 diff --git a/platformio.ini b/platformio.ini index 28f065116..1e46f57fb 100644 --- a/platformio.ini +++ b/platformio.ini @@ -35,6 +35,7 @@ lib_deps = adafruit/Adafruit BME280 Library adafruit/Adafruit BMP280 Library adafruit/Adafruit BMP3XX Library + adafruit/Adafruit BMP5XX Library adafruit/Adafruit DPS310 adafruit/Adafruit DS248x adafruit/Adafruit INA219 diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index a074e7f74..948c83800 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -272,14 +272,27 @@ bool WipperSnapper_Component_I2C::initI2CDevice( (strcmp("bmp390", msgDeviceInitReq->i2c_device_name) == 0)) { _bmp3xx = new WipperSnapper_I2C_Driver_BMP3XX(this->_i2c, i2cAddress); if (!_bmp3xx->begin()) { - WS_DEBUG_PRINTLN("ERROR: Failed to initialize BMP388!"); + WS_DEBUG_PRINTLN("ERROR: Failed to initialize BMP3xx!"); _busStatusResponse = wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; return false; } _bmp3xx->configureDriver(msgDeviceInitReq); drivers.push_back(_bmp3xx); - WS_DEBUG_PRINTLN("BMP388 Initialized Successfully!"); + WS_DEBUG_PRINTLN("BMP3xx Initialized Successfully!"); + } else if ((strcmp("bmp580", msgDeviceInitReq->i2c_device_name) == 0) || + (strcmp("bmp581", msgDeviceInitReq->i2c_device_name) == 0) || + (strcmp("bmp585", msgDeviceInitReq->i2c_device_name) == 0)) { + _bmp5xx = new WipperSnapper_I2C_Driver_BMP5XX(this->_i2c, i2cAddress); + if (!_bmp5xx->begin()) { + WS_DEBUG_PRINTLN("ERROR: Failed to initialize BMP5xx!"); + _busStatusResponse = + wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; + return false; + } + _bmp5xx->configureDriver(msgDeviceInitReq); + drivers.push_back(_bmp5xx); + WS_DEBUG_PRINTLN("BMP5xx Initialized Successfully!"); } else if ((strcmp("bme680", msgDeviceInitReq->i2c_device_name) == 0) || (strcmp("bme688", msgDeviceInitReq->i2c_device_name) == 0)) { _bme680 = new WipperSnapper_I2C_Driver_BME680(this->_i2c, i2cAddress); diff --git a/src/components/i2c/WipperSnapper_I2C.h b/src/components/i2c/WipperSnapper_I2C.h index c594e0bf5..e75cb47c4 100644 --- a/src/components/i2c/WipperSnapper_I2C.h +++ b/src/components/i2c/WipperSnapper_I2C.h @@ -27,6 +27,7 @@ #include "drivers/WipperSnapper_I2C_Driver_BME680.h" #include "drivers/WipperSnapper_I2C_Driver_BMP280.h" #include "drivers/WipperSnapper_I2C_Driver_BMP3XX.h" +#include "drivers/WipperSnapper_I2C_Driver_BMP5XX.h" #include "drivers/WipperSnapper_I2C_Driver_D6T1A.h" #include "drivers/WipperSnapper_I2C_Driver_DPS310.h" #include "drivers/WipperSnapper_I2C_Driver_DS2484.h" @@ -166,6 +167,7 @@ class WipperSnapper_Component_I2C { WipperSnapper_I2C_Driver_BME280 *_bme280 = nullptr; WipperSnapper_I2C_Driver_BMP280 *_bmp280 = nullptr; WipperSnapper_I2C_Driver_BMP3XX *_bmp3xx = nullptr; + WipperSnapper_I2C_Driver_BMP5XX *_bmp5xx = nullptr; WipperSnapper_I2C_Driver_BME680 *_bme680 = nullptr; WipperSnapper_I2C_Driver_HDC302X *_hdc302x = nullptr; WipperSnapper_I2C_Driver_HTS221 *_hts221 = nullptr; diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h new file mode 100644 index 000000000..2e1afc42b --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h @@ -0,0 +1,132 @@ +/*! + * @file WipperSnapper_I2C_Driver_BMP5XX.h + * + * Device driver for a BMP5XX precision pressure sensor breakout. + * + * Adafruit invests time and resources providing this open source code, + * please support Adafruit and open-source hardware by purchasing + * products from Adafruit! + * + * Copyright (c) Tyeth Gundry 2025 for Adafruit Industries. + * + * MIT license, all text here must be included in any redistribution. + * + */ + +#ifndef WipperSnapper_I2C_Driver_BMP5XX_H +#define WipperSnapper_I2C_Driver_BMP5XX_H + +#include "WipperSnapper_I2C_Driver.h" +#include + +#define SEALEVELPRESSURE_HPA (1013.25) ///< Default sea level pressure, in hPa + +/**************************************************************************/ +/*! + @brief Class that provides a sensor driver for the BMP5XX temperature + and pressure sensor. +*/ +/**************************************************************************/ +class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { + +public: + /*******************************************************************************/ + /*! + @brief Constructor for an BMP5XX sensor. + @param i2c + The I2C interface. + @param sensorAddress + 7-bit device address. + */ + /*******************************************************************************/ + WipperSnapper_I2C_Driver_BMP5XX(TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress) { + _bmp5xx = nullptr; + } + + /*******************************************************************************/ + /*! + @brief Destructor for an BMP5XX sensor. + */ + /*******************************************************************************/ + ~WipperSnapper_I2C_Driver_BMP5XX() { + if (_bmp5xx) { + delete _bmp5xx; + _bmp5xx = nullptr; + } + } + + /*******************************************************************************/ + /*! + @brief Initializes the BMP5XX sensor and begins I2C. + @returns True if initialized successfully, False otherwise. + */ + /*******************************************************************************/ + bool begin() { + _bmp5xx = new Adafruit_BMP5xx(); + if (!_bmp5xx->begin(_sensorAddress, _i2c)) + return false; + + // Set up oversampling and filter initialization + _bmp5xx->setTemperatureOversampling(BMP5XX_OVERSAMPLING_8X); + _bmp5xx->setPressureOversampling(BMP5XX_OVERSAMPLING_4X); + _bmp5xx->setIIRFilterCoeff(BMP5XX_IIR_FILTER_COEFF_3); + _bmp5xx->setOutputDataRate(BMP5XX_ODR_50_HZ); + + return true; + } + + /*******************************************************************************/ + /*! + @brief Gets the BMP5XX's current temperature. + @param tempEvent + Pointer to an Adafruit_Sensor event. + @returns True if the temperature was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + bool getEventAmbientTemp(sensors_event_t *tempEvent) { + if (!_bmp5xx->performReading()) + return false; + tempEvent->temperature = _bmp5xx->temperature; + return true; + } + + /*******************************************************************************/ + /*! + @brief Reads a pressure sensor and converts + the reading into the expected SI unit. + @param pressureEvent + Pointer to an Adafruit_Sensor event. + @returns True if the sensor event was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + bool getEventPressure(sensors_event_t *pressureEvent) { + if (!_bmp5xx->performReading()) + return false; + pressureEvent->pressure = _bmp5xx->pressure / 10.0F; + return true; + } + + /*******************************************************************************/ + /*! + @brief Reads a the BMP5XX's altitude sensor into an event. + @param altitudeEvent + Pointer to an adafruit sensor event. + @returns True if the sensor event was obtained successfully, False + otherwise. + */ + /*******************************************************************************/ + bool getEventAltitude(sensors_event_t *altitudeEvent) { + if (!_bmp5xx->performReading()) + return false; + altitudeEvent->altitude = _bmp5xx->readAltitude(SEALEVELPRESSURE_HPA); + return true; + } + +protected: + Adafruit_BMP5xx *_bmp5xx; ///< BMP5xx object +}; + +#endif // WipperSnapper_I2C_Driver_BMP5XX \ No newline at end of file From 905db7a475ab0468148752206e4c880215084b93 Mon Sep 17 00:00:00 2001 From: tyeth Date: Wed, 27 Aug 2025 19:11:16 +0100 Subject: [PATCH 2/6] fix(bmp581): Correct to hPa + clang format --- .../drivers/WipperSnapper_I2C_Driver_BMP5XX.h | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h index 2e1afc42b..10dd30c8a 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h @@ -16,10 +16,11 @@ #ifndef WipperSnapper_I2C_Driver_BMP5XX_H #define WipperSnapper_I2C_Driver_BMP5XX_H -#include "WipperSnapper_I2C_Driver.h" #include -#define SEALEVELPRESSURE_HPA (1013.25) ///< Default sea level pressure, in hPa +#include "WipperSnapper_I2C_Driver.h" + +#define SEALEVELPRESSURE_HPA (1013.25) ///< Default sea level pressure, in hPa /**************************************************************************/ /*! @@ -28,8 +29,7 @@ */ /**************************************************************************/ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { - -public: + public: /*******************************************************************************/ /*! @brief Constructor for an BMP5XX sensor. @@ -49,9 +49,9 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { @brief Destructor for an BMP5XX sensor. */ /*******************************************************************************/ - ~WipperSnapper_I2C_Driver_BMP5XX() { + ~WipperSnapper_I2C_Driver_BMP5XX() { if (_bmp5xx) { - delete _bmp5xx; + delete _bmp5xx; _bmp5xx = nullptr; } } @@ -64,8 +64,11 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { /*******************************************************************************/ bool begin() { _bmp5xx = new Adafruit_BMP5xx(); - if (!_bmp5xx->begin(_sensorAddress, _i2c)) + if (!_bmp5xx->begin(_sensorAddress, _i2c)) { + delete _bmp5xx; + _bmp5xx = nullptr; return false; + } // Set up oversampling and filter initialization _bmp5xx->setTemperatureOversampling(BMP5XX_OVERSAMPLING_8X); @@ -86,8 +89,9 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { */ /*******************************************************************************/ bool getEventAmbientTemp(sensors_event_t *tempEvent) { - if (!_bmp5xx->performReading()) + if (!_bmp5xx->performReading()) { return false; + } tempEvent->temperature = _bmp5xx->temperature; return true; } @@ -103,9 +107,10 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { */ /*******************************************************************************/ bool getEventPressure(sensors_event_t *pressureEvent) { - if (!_bmp5xx->performReading()) + if (!_bmp5xx->performReading()) { return false; - pressureEvent->pressure = _bmp5xx->pressure / 10.0F; + } + pressureEvent->pressure = _bmp5xx->pressure; return true; } @@ -119,14 +124,15 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { */ /*******************************************************************************/ bool getEventAltitude(sensors_event_t *altitudeEvent) { - if (!_bmp5xx->performReading()) + if (!_bmp5xx->performReading()) { return false; + } altitudeEvent->altitude = _bmp5xx->readAltitude(SEALEVELPRESSURE_HPA); return true; } -protected: - Adafruit_BMP5xx *_bmp5xx; ///< BMP5xx object + protected: + Adafruit_BMP5xx *_bmp5xx; ///< BMP5xx object }; -#endif // WipperSnapper_I2C_Driver_BMP5XX \ No newline at end of file +#endif // WipperSnapper_I2C_Driver_BMP5XX \ No newline at end of file From 7898c26a1c5d5417fd9f1aace3e6c8045065cbf8 Mon Sep 17 00:00:00 2001 From: tyeth Date: Thu, 28 Aug 2025 14:22:03 +0100 Subject: [PATCH 3/6] fix(bmp581): include casing fix --- src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h index 10dd30c8a..09687c684 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h @@ -16,7 +16,7 @@ #ifndef WipperSnapper_I2C_Driver_BMP5XX_H #define WipperSnapper_I2C_Driver_BMP5XX_H -#include +#include #include "WipperSnapper_I2C_Driver.h" From 72b895599c0df7d7709eef24d39937342c7e36b6 Mon Sep 17 00:00:00 2001 From: tyeth Date: Thu, 28 Aug 2025 14:35:21 +0100 Subject: [PATCH 4/6] chore(clang): format manually for CI --- .../i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h index 09687c684..a6c4ab36f 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h @@ -20,7 +20,7 @@ #include "WipperSnapper_I2C_Driver.h" -#define SEALEVELPRESSURE_HPA (1013.25) ///< Default sea level pressure, in hPa +#define SEALEVELPRESSURE_HPA (1013.25) ///< Default sea level pressure, in hPa /**************************************************************************/ /*! @@ -29,7 +29,7 @@ */ /**************************************************************************/ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { - public: +public: /*******************************************************************************/ /*! @brief Constructor for an BMP5XX sensor. @@ -131,8 +131,8 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { return true; } - protected: - Adafruit_BMP5xx *_bmp5xx; ///< BMP5xx object +protected: + Adafruit_BMP5xx *_bmp5xx; ///< BMP5xx object }; #endif // WipperSnapper_I2C_Driver_BMP5XX \ No newline at end of file From 094c4dc4d8a2da7ec595181b46959ec82b00f0ed Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Fri, 29 Aug 2025 20:38:46 +0100 Subject: [PATCH 5/6] chore(clang): Fix header guard formatting in BMP5XX driver --- src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h index a6c4ab36f..3e2a61d6f 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h @@ -135,4 +135,4 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { Adafruit_BMP5xx *_bmp5xx; ///< BMP5xx object }; -#endif // WipperSnapper_I2C_Driver_BMP5XX \ No newline at end of file +#endif // WipperSnapper_I2C_Driver_BMP5XX From 37f8480717c4af67f165d9745c6ac138785e308e Mon Sep 17 00:00:00 2001 From: tyeth Date: Fri, 29 Aug 2025 23:10:36 +0100 Subject: [PATCH 6/6] fix(bmp5xx): return result of setup commands --- .../i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h index a6c4ab36f..378018da7 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP5XX.h @@ -71,12 +71,12 @@ class WipperSnapper_I2C_Driver_BMP5XX : public WipperSnapper_I2C_Driver { } // Set up oversampling and filter initialization - _bmp5xx->setTemperatureOversampling(BMP5XX_OVERSAMPLING_8X); - _bmp5xx->setPressureOversampling(BMP5XX_OVERSAMPLING_4X); - _bmp5xx->setIIRFilterCoeff(BMP5XX_IIR_FILTER_COEFF_3); - _bmp5xx->setOutputDataRate(BMP5XX_ODR_50_HZ); - - return true; + return _bmp5xx->setTemperatureOversampling(BMP5XX_OVERSAMPLING_8X) && + _bmp5xx->setPressureOversampling(BMP5XX_OVERSAMPLING_16X) && + _bmp5xx->setIIRFilterCoeff(BMP5XX_IIR_FILTER_COEFF_3) && + _bmp5xx->setOutputDataRate(BMP5XX_ODR_50_HZ) && + _bmp5xx->setPowerMode(BMP5XX_POWERMODE_NORMAL) && + _bmp5xx->enablePressure(true); } /*******************************************************************************/