From 36a4c89fce7c69285f23946c40ee76c74356d894 Mon Sep 17 00:00:00 2001 From: tyeth Date: Wed, 19 Feb 2025 13:25:35 +0000 Subject: [PATCH 1/5] Add LPS28DFW --- library.properties | 2 +- platformio.ini | 1 + src/components/i2c/WipperSnapper_I2C.cpp | 11 ++ src/components/i2c/WipperSnapper_I2C.h | 2 + .../WipperSnapper_I2C_Driver_LPS28DFW.h | 141 ++++++++++++++++++ 5 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h diff --git a/library.properties b/library.properties index 2200ce7f9..ba7878696 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=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, 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 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 +depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, 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 diff --git a/platformio.ini b/platformio.ini index a9bc5e7e0..8bdf6d7ce 100644 --- a/platformio.ini +++ b/platformio.ini @@ -70,6 +70,7 @@ lib_deps = adafruit/Adafruit VEML7700 Library adafruit/Adafruit LC709203F adafruit/Adafruit LPS2X + adafruit/Adafruit LPS28 adafruit/Adafruit LPS35HW adafruit/Adafruit seesaw Library adafruit/Adafruit BME680 Library diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index dfae4db42..32dc1e166 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -709,6 +709,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice( _lps25hb->configureDriver(msgDeviceInitReq); drivers.push_back(_lps25hb); WS_DEBUG_PRINTLN("LPS25HB Sensor Initialized Successfully!"); + } else if (strcmp("lps28hb", msgDeviceInitReq->i2c_device_name) == 0) { + _lps28hb = new WipperSnapper_I2C_Driver_LPS28DFW(this->_i2c, i2cAddress); + if (!_lps28hb->begin()) { + WS_DEBUG_PRINTLN("ERROR: Failed to initialize LPS28DFW Sensor!"); + _busStatusResponse = + wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL; + return false; + } + _lps28hb->configureDriver(msgDeviceInitReq); + drivers.push_back(_lps28hb); + WS_DEBUG_PRINTLN("LPS28HB Sensor Initialized Successfully!"); } else if ((strcmp("lps33hw", msgDeviceInitReq->i2c_device_name) == 0) || (strcmp("lps35hw", msgDeviceInitReq->i2c_device_name)) == 0) { _lps3xhw = new WipperSnapper_I2C_Driver_LPS3XHW(this->_i2c, i2cAddress); diff --git a/src/components/i2c/WipperSnapper_I2C.h b/src/components/i2c/WipperSnapper_I2C.h index 0c514b813..7998fc015 100644 --- a/src/components/i2c/WipperSnapper_I2C.h +++ b/src/components/i2c/WipperSnapper_I2C.h @@ -38,6 +38,7 @@ #include "drivers/WipperSnapper_I2C_Driver_LC709203F.h" #include "drivers/WipperSnapper_I2C_Driver_LPS22HB.h" #include "drivers/WipperSnapper_I2C_Driver_LPS25HB.h" +#include "drivers/WipperSnapper_I2C_Driver_LPS28DFW.h" #include "drivers/WipperSnapper_I2C_Driver_LPS3XHW.h" #include "drivers/WipperSnapper_I2C_Driver_LTR329_LTR303.h" #include "drivers/WipperSnapper_I2C_Driver_LTR390.h" @@ -177,6 +178,7 @@ class WipperSnapper_Component_I2C { WipperSnapper_I2C_Driver_LC709203F *_lc = nullptr; WipperSnapper_I2C_Driver_LPS22HB *_lps22hb = nullptr; WipperSnapper_I2C_Driver_LPS25HB *_lps25hb = nullptr; + WipperSnapper_I2C_Driver_LPS28DFW *_lps28hb = nullptr; WipperSnapper_I2C_Driver_LPS3XHW *_lps3xhw = nullptr; WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor *_ss = nullptr; WipperSnapper_I2C_Driver_VL53L0X *_vl53l0x = nullptr; diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h new file mode 100644 index 000000000..0816bf1a3 --- /dev/null +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h @@ -0,0 +1,141 @@ +/*! + * @file WipperSnapper_I2C_Driver_LPS28DFW.h + * + * Device driver for a LPS28DFW 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_LPS28DFW_H +#define WipperSnapper_I2C_Driver_LPS28DFW_H + +#include "WipperSnapper_I2C_Driver.h" +#include + +/**************************************************************************/ +/*! + @brief Class that provides a sensor driver for the LPS28DFW temperature + and pressure sensor. +*/ +/**************************************************************************/ +class WipperSnapper_I2C_Driver_LPS28DFW : public WipperSnapper_I2C_Driver { + +public: + /*******************************************************************************/ + /*! + @brief Constructor for an LPS28DFW sensor. + @param i2c + The I2C interface. + @param sensorAddress + 7-bit device address. + */ + /*******************************************************************************/ + WipperSnapper_I2C_Driver_LPS28DFW(TwoWire *i2c, uint16_t sensorAddress) + : WipperSnapper_I2C_Driver(i2c, sensorAddress) { + _i2c = i2c; + _sensorAddress = sensorAddress; + } + + /*******************************************************************************/ + /*! + @brief Destructor for an LPS28DFW sensor. + */ + /*******************************************************************************/ + ~WipperSnapper_I2C_Driver_LPS28DFW() { delete _lps28; } + + /*******************************************************************************/ + /*! + @brief Initializes the LPS28DFW sensor and begins I2C. + @returns True if initialized successfully, False otherwise. + */ + /*******************************************************************************/ + bool begin() { + _lps28 = new Adafruit_LPS28(); + // attempt to initialize LPS28DFW + if (!_lps28->begin(_i2c, _sensorAddress)) + return false; + + // Set up sample rate and filter initialization + _lps28->setDataRate(LPS28_ODR_ONESHOT); + _lps28->setAveraging(LPS28_AVG_512); + + return readSensor(); + } + + /*******************************************************************************/ + /*! + @brief Reads the sensor and stores the data in the object. + @returns True if the sensor was read successfully, False otherwise. + */ + /*******************************************************************************/ + bool readSensor() { + // grab one reading to seed the sensor + if (!_lps28->triggerOneShot()) { + return false; + } + + // Wait (block up to 100ms) until data is ready + for (uint8_t i = 0; i < 100; i++) { + if (_lps28->getStatus() & LPS28_STATUS_PRESS_READY) { + if (_temp == NULL) { + _temp = _lps28->getTemperatureSensor(); + } + if (_pressure == NULL) { + _pressure = _lps28->getPressureSensor(); + } + return true; + } + delay(1); + } + return false; + } + + /*******************************************************************************/ + /*! + @brief Gets the LPS28DFW'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 (!readSensor()) + return false; + _temp->getEvent(tempEvent); + 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 (!readSensor()) + return false; + _pressure->getEvent(pressureEvent); + return true; + } + +protected: + Adafruit_LPS28 *_lps28; ///< LPS28DFW object + Adafruit_Sensor *_temp = + NULL; ///< Ptr to an adafruit_sensor representing the temperature + Adafruit_Sensor *_pressure = + NULL; ///< Ptr to an adafruit_sensor representing the pressure +}; + +#endif // WipperSnapper_I2C_Driver_LPS28DFW \ No newline at end of file From df2b6b06f4aee69677b0de2e641e15c79640cc27 Mon Sep 17 00:00:00 2001 From: tyeth Date: Wed, 19 Feb 2025 14:30:10 +0000 Subject: [PATCH 2/5] LPS28DFW: log reasons for failures --- .../i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h index 0816bf1a3..24ae47601 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h @@ -63,10 +63,16 @@ class WipperSnapper_I2C_Driver_LPS28DFW : public WipperSnapper_I2C_Driver { return false; // Set up sample rate and filter initialization - _lps28->setDataRate(LPS28_ODR_ONESHOT); - _lps28->setAveraging(LPS28_AVG_512); + if (!_lps28->setDataRate(LPS28_ODR_ONESHOT)) { + WS_DEBUG_PRINTLN("Failed to set data rate"); + return false; + } + if (!_lps28->setAveraging(LPS28_AVG_512)) { + WS_DEBUG_PRINTLN("Failed to set averaging"); + return false; + } - return readSensor(); + return true; } /*******************************************************************************/ From df714851554ef3ba26a20392feb22c23bab27681 Mon Sep 17 00:00:00 2001 From: tyeth Date: Wed, 19 Feb 2025 14:36:49 +0000 Subject: [PATCH 3/5] Fix: use correct short name for LPS28DFW --- src/components/i2c/WipperSnapper_I2C.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/i2c/WipperSnapper_I2C.cpp b/src/components/i2c/WipperSnapper_I2C.cpp index 32dc1e166..a07a99f34 100644 --- a/src/components/i2c/WipperSnapper_I2C.cpp +++ b/src/components/i2c/WipperSnapper_I2C.cpp @@ -709,7 +709,7 @@ bool WipperSnapper_Component_I2C::initI2CDevice( _lps25hb->configureDriver(msgDeviceInitReq); drivers.push_back(_lps25hb); WS_DEBUG_PRINTLN("LPS25HB Sensor Initialized Successfully!"); - } else if (strcmp("lps28hb", msgDeviceInitReq->i2c_device_name) == 0) { + } else if (strcmp("lps28dfw", msgDeviceInitReq->i2c_device_name) == 0) { _lps28hb = new WipperSnapper_I2C_Driver_LPS28DFW(this->_i2c, i2cAddress); if (!_lps28hb->begin()) { WS_DEBUG_PRINTLN("ERROR: Failed to initialize LPS28DFW Sensor!"); From 929eb9a83ab4ae5d9ae19f268332d13307f99ea5 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Wed, 19 Feb 2025 21:08:47 +0000 Subject: [PATCH 4/5] Update WipperSnapper_I2C_Driver_LPS28DFW.h --- .../i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h index 24ae47601..f05eb6a86 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h @@ -137,11 +137,11 @@ class WipperSnapper_I2C_Driver_LPS28DFW : public WipperSnapper_I2C_Driver { } protected: - Adafruit_LPS28 *_lps28; ///< LPS28DFW object + Adafruit_LPS28 *_lps28 = nullptr; ///< LPS28DFW object Adafruit_Sensor *_temp = NULL; ///< Ptr to an adafruit_sensor representing the temperature Adafruit_Sensor *_pressure = NULL; ///< Ptr to an adafruit_sensor representing the pressure }; -#endif // WipperSnapper_I2C_Driver_LPS28DFW \ No newline at end of file +#endif // WipperSnapper_I2C_Driver_LPS28DFW From abf14e0252f6eb475fbce00344a1768c995faf91 Mon Sep 17 00:00:00 2001 From: Tyeth Gundry Date: Wed, 19 Feb 2025 21:40:21 +0000 Subject: [PATCH 5/5] Update LPS28DFW to use extreme range of 260-4060hPa param mode true for FS_MODE=1 (1/2048 hPa/LSB), false for FS_MODE=0 (1/4096 hPa/LSB) --- .../i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h index f05eb6a86..9c4146540 100644 --- a/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h +++ b/src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h @@ -71,6 +71,10 @@ class WipperSnapper_I2C_Driver_LPS28DFW : public WipperSnapper_I2C_Driver { WS_DEBUG_PRINTLN("Failed to set averaging"); return false; } + if (!_lps28->setFullScaleMode(false)) { + WS_DEBUG_PRINTLN("Failed to set 4060hPa max mode"); + return false; + } return true; }