Skip to content

Commit 36a4c89

Browse files
committed
Add LPS28DFW
1 parent 7ab9e78 commit 36a4c89

5 files changed

+156
-1
lines changed

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=Arduino application for Adafruit.io WipperSnapper
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino
99
architectures=*
10-
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
10+
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

platformio.ini

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ lib_deps =
7070
adafruit/Adafruit VEML7700 Library
7171
adafruit/Adafruit LC709203F
7272
adafruit/Adafruit LPS2X
73+
adafruit/Adafruit LPS28
7374
adafruit/Adafruit LPS35HW
7475
adafruit/Adafruit seesaw Library
7576
adafruit/Adafruit BME680 Library

src/components/i2c/WipperSnapper_I2C.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
709709
_lps25hb->configureDriver(msgDeviceInitReq);
710710
drivers.push_back(_lps25hb);
711711
WS_DEBUG_PRINTLN("LPS25HB Sensor Initialized Successfully!");
712+
} else if (strcmp("lps28hb", msgDeviceInitReq->i2c_device_name) == 0) {
713+
_lps28hb = new WipperSnapper_I2C_Driver_LPS28DFW(this->_i2c, i2cAddress);
714+
if (!_lps28hb->begin()) {
715+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize LPS28DFW Sensor!");
716+
_busStatusResponse =
717+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
718+
return false;
719+
}
720+
_lps28hb->configureDriver(msgDeviceInitReq);
721+
drivers.push_back(_lps28hb);
722+
WS_DEBUG_PRINTLN("LPS28HB Sensor Initialized Successfully!");
712723
} else if ((strcmp("lps33hw", msgDeviceInitReq->i2c_device_name) == 0) ||
713724
(strcmp("lps35hw", msgDeviceInitReq->i2c_device_name)) == 0) {
714725
_lps3xhw = new WipperSnapper_I2C_Driver_LPS3XHW(this->_i2c, i2cAddress);

src/components/i2c/WipperSnapper_I2C.h

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "drivers/WipperSnapper_I2C_Driver_LC709203F.h"
3939
#include "drivers/WipperSnapper_I2C_Driver_LPS22HB.h"
4040
#include "drivers/WipperSnapper_I2C_Driver_LPS25HB.h"
41+
#include "drivers/WipperSnapper_I2C_Driver_LPS28DFW.h"
4142
#include "drivers/WipperSnapper_I2C_Driver_LPS3XHW.h"
4243
#include "drivers/WipperSnapper_I2C_Driver_LTR329_LTR303.h"
4344
#include "drivers/WipperSnapper_I2C_Driver_LTR390.h"
@@ -177,6 +178,7 @@ class WipperSnapper_Component_I2C {
177178
WipperSnapper_I2C_Driver_LC709203F *_lc = nullptr;
178179
WipperSnapper_I2C_Driver_LPS22HB *_lps22hb = nullptr;
179180
WipperSnapper_I2C_Driver_LPS25HB *_lps25hb = nullptr;
181+
WipperSnapper_I2C_Driver_LPS28DFW *_lps28hb = nullptr;
180182
WipperSnapper_I2C_Driver_LPS3XHW *_lps3xhw = nullptr;
181183
WipperSnapper_I2C_Driver_STEMMA_Soil_Sensor *_ss = nullptr;
182184
WipperSnapper_I2C_Driver_VL53L0X *_vl53l0x = nullptr;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_LPS28DFW.h
3+
*
4+
* Device driver for a LPS28DFW precision pressure sensor breakout.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Tyeth Gundry 2025 for Adafruit Industries.
11+
*
12+
* MIT license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
16+
#ifndef WipperSnapper_I2C_Driver_LPS28DFW_H
17+
#define WipperSnapper_I2C_Driver_LPS28DFW_H
18+
19+
#include "WipperSnapper_I2C_Driver.h"
20+
#include <Adafruit_LPS28.h>
21+
22+
/**************************************************************************/
23+
/*!
24+
@brief Class that provides a sensor driver for the LPS28DFW temperature
25+
and pressure sensor.
26+
*/
27+
/**************************************************************************/
28+
class WipperSnapper_I2C_Driver_LPS28DFW : public WipperSnapper_I2C_Driver {
29+
30+
public:
31+
/*******************************************************************************/
32+
/*!
33+
@brief Constructor for an LPS28DFW sensor.
34+
@param i2c
35+
The I2C interface.
36+
@param sensorAddress
37+
7-bit device address.
38+
*/
39+
/*******************************************************************************/
40+
WipperSnapper_I2C_Driver_LPS28DFW(TwoWire *i2c, uint16_t sensorAddress)
41+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
42+
_i2c = i2c;
43+
_sensorAddress = sensorAddress;
44+
}
45+
46+
/*******************************************************************************/
47+
/*!
48+
@brief Destructor for an LPS28DFW sensor.
49+
*/
50+
/*******************************************************************************/
51+
~WipperSnapper_I2C_Driver_LPS28DFW() { delete _lps28; }
52+
53+
/*******************************************************************************/
54+
/*!
55+
@brief Initializes the LPS28DFW sensor and begins I2C.
56+
@returns True if initialized successfully, False otherwise.
57+
*/
58+
/*******************************************************************************/
59+
bool begin() {
60+
_lps28 = new Adafruit_LPS28();
61+
// attempt to initialize LPS28DFW
62+
if (!_lps28->begin(_i2c, _sensorAddress))
63+
return false;
64+
65+
// Set up sample rate and filter initialization
66+
_lps28->setDataRate(LPS28_ODR_ONESHOT);
67+
_lps28->setAveraging(LPS28_AVG_512);
68+
69+
return readSensor();
70+
}
71+
72+
/*******************************************************************************/
73+
/*!
74+
@brief Reads the sensor and stores the data in the object.
75+
@returns True if the sensor was read successfully, False otherwise.
76+
*/
77+
/*******************************************************************************/
78+
bool readSensor() {
79+
// grab one reading to seed the sensor
80+
if (!_lps28->triggerOneShot()) {
81+
return false;
82+
}
83+
84+
// Wait (block up to 100ms) until data is ready
85+
for (uint8_t i = 0; i < 100; i++) {
86+
if (_lps28->getStatus() & LPS28_STATUS_PRESS_READY) {
87+
if (_temp == NULL) {
88+
_temp = _lps28->getTemperatureSensor();
89+
}
90+
if (_pressure == NULL) {
91+
_pressure = _lps28->getPressureSensor();
92+
}
93+
return true;
94+
}
95+
delay(1);
96+
}
97+
return false;
98+
}
99+
100+
/*******************************************************************************/
101+
/*!
102+
@brief Gets the LPS28DFW's current temperature.
103+
@param tempEvent
104+
Pointer to an Adafruit_Sensor event.
105+
@returns True if the temperature was obtained successfully, False
106+
otherwise.
107+
*/
108+
/*******************************************************************************/
109+
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
110+
if (!readSensor())
111+
return false;
112+
_temp->getEvent(tempEvent);
113+
return true;
114+
}
115+
116+
/*******************************************************************************/
117+
/*!
118+
@brief Reads a pressure sensor and converts
119+
the reading into the expected SI unit.
120+
@param pressureEvent
121+
Pointer to an Adafruit_Sensor event.
122+
@returns True if the sensor event was obtained successfully, False
123+
otherwise.
124+
*/
125+
/*******************************************************************************/
126+
bool getEventPressure(sensors_event_t *pressureEvent) {
127+
if (!readSensor())
128+
return false;
129+
_pressure->getEvent(pressureEvent);
130+
return true;
131+
}
132+
133+
protected:
134+
Adafruit_LPS28 *_lps28; ///< LPS28DFW object
135+
Adafruit_Sensor *_temp =
136+
NULL; ///< Ptr to an adafruit_sensor representing the temperature
137+
Adafruit_Sensor *_pressure =
138+
NULL; ///< Ptr to an adafruit_sensor representing the pressure
139+
};
140+
141+
#endif // WipperSnapper_I2C_Driver_LPS28DFW

0 commit comments

Comments
 (0)