Skip to content

Commit 602bbd6

Browse files
committed
Add LPS28DFW
1 parent 19b58a8 commit 602bbd6

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ lib_deps =
6262
adafruit/Adafruit VEML7700 Library
6363
adafruit/Adafruit LC709203F
6464
adafruit/Adafruit LPS2X
65+
adafruit/Adafruit LPS28
6566
adafruit/Adafruit LPS35HW
6667
adafruit/Adafruit seesaw Library
6768
adafruit/Adafruit BME680 Library

src/components/i2c/controller.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ static const std::map<std::string, FnCreateI2CDriver> I2cFactory = {
158158
const char *driver_name) -> drvBase * {
159159
return new drvLps25hb(i2c, addr, mux_channel, driver_name);
160160
}},
161+
{"lps28dfw",
162+
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
163+
const char *driver_name) -> drvBase * {
164+
return new drvLps28dfw(i2c, addr, mux_channel, driver_name);
165+
}},
161166
{"ltr329",
162167
[](TwoWire *i2c, uint16_t addr, uint32_t mux_channel,
163168
const char *driver_name) -> drvBase * {

src/components/i2c/controller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "drivers/drvLc709203f.h"
3838
#include "drivers/drvLps22hb.h"
3939
#include "drivers/drvLps25hb.h"
40+
#include "drivers/drvLps28dfw.h"
4041
#include "drivers/drvLps3xhw.h"
4142
#include "drivers/drvLtr329_Ltr303.h"
4243
#include "drivers/drvLtr390.h"
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/*!
2+
* @file drvLps28dfw.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 DRV_LPS28DFW_H
17+
#define DRV_LPS28DFW_H
18+
19+
#include "drvBase.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 drvLps28dfw : public drvBase {
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+
@param mux_channel
39+
The I2C multiplexer channel.
40+
@param driver_name
41+
The name of the driver.
42+
*/
43+
/*******************************************************************************/
44+
drvLps28dfw(TwoWire *i2c, uint16_t sensorAddress, uint32_t mux_channel,
45+
const char *driver_name)
46+
: drvBase(i2c, sensorAddress, mux_channel, driver_name) {
47+
// Initialization handled by drvBase constructor
48+
}
49+
50+
/*******************************************************************************/
51+
/*!
52+
@brief Destructor for an LPS28DFW sensor.
53+
*/
54+
/*******************************************************************************/
55+
~drvLps28dfw() { delete _lps28; }
56+
57+
/*******************************************************************************/
58+
/*!
59+
@brief Initializes the LPS28DFW sensor and begins I2C.
60+
@returns True if initialized successfully, False otherwise.
61+
*/
62+
/*******************************************************************************/
63+
bool begin() {
64+
_lps28 = new Adafruit_LPS28();
65+
// attempt to initialize LPS28DFW
66+
if (!_lps28->begin(_i2c, _address))
67+
return false;
68+
69+
// Set up sample rate and filter initialization
70+
if (!_lps28->setDataRate(LPS28_ODR_ONESHOT)) {
71+
WS_DEBUG_PRINTLN("Failed to set data rate");
72+
return false;
73+
}
74+
if (!_lps28->setAveraging(LPS28_AVG_512)) {
75+
WS_DEBUG_PRINTLN("Failed to set averaging");
76+
return false;
77+
}
78+
if (!_lps28->setFullScaleMode(true)) {
79+
WS_DEBUG_PRINTLN("Failed to set 4060hPa max mode");
80+
return false;
81+
}
82+
83+
return true;
84+
}
85+
86+
/*******************************************************************************/
87+
/*!
88+
@brief Reads the sensor and stores the data in the object.
89+
@returns True if the sensor was read successfully, False otherwise.
90+
*/
91+
/*******************************************************************************/
92+
bool readSensor() {
93+
// grab one reading to seed the sensor
94+
if (!_lps28->triggerOneShot()) {
95+
return false;
96+
}
97+
98+
// Wait (block up to 100ms) until data is ready
99+
for (uint8_t i = 0; i < 100; i++) {
100+
if (_lps28->getStatus() & LPS28_STATUS_PRESS_READY) {
101+
if (_temp == NULL) {
102+
_temp = _lps28->getTemperatureSensor();
103+
}
104+
if (_pressure == NULL) {
105+
_pressure = _lps28->getPressureSensor();
106+
}
107+
return true;
108+
}
109+
delay(1);
110+
}
111+
return false;
112+
}
113+
114+
/*******************************************************************************/
115+
/*!
116+
@brief Gets the LPS28DFW's current temperature.
117+
@param tempEvent
118+
Pointer to an Adafruit_Sensor event.
119+
@returns True if the temperature was obtained successfully, False
120+
otherwise.
121+
*/
122+
/*******************************************************************************/
123+
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
124+
if (!readSensor())
125+
return false;
126+
_temp->getEvent(tempEvent);
127+
return true;
128+
}
129+
130+
/*******************************************************************************/
131+
/*!
132+
@brief Reads a pressure sensor and converts
133+
the reading into the expected SI unit.
134+
@param pressureEvent
135+
Pointer to an Adafruit_Sensor event.
136+
@returns True if the sensor event was obtained successfully, False
137+
otherwise.
138+
*/
139+
/*******************************************************************************/
140+
bool getEventPressure(sensors_event_t *pressureEvent) {
141+
if (!readSensor())
142+
return false;
143+
_pressure->getEvent(pressureEvent);
144+
return true;
145+
}
146+
147+
protected:
148+
Adafruit_LPS28 *_lps28 = nullptr; ///< LPS28DFW object
149+
Adafruit_Sensor *_temp =
150+
NULL; ///< Ptr to an adafruit_sensor representing the temperature
151+
Adafruit_Sensor *_pressure =
152+
NULL; ///< Ptr to an adafruit_sensor representing the pressure
153+
};
154+
155+
#endif // DRV_LPS28DFW_H

0 commit comments

Comments
 (0)