-
Notifications
You must be signed in to change notification settings - Fork 54
Add LPS28DFW #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Add LPS28DFW #695
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
36a4c89
Add LPS28DFW
tyeth df2b6b0
LPS28DFW: log reasons for failures
tyeth df71485
Fix: use correct short name for LPS28DFW
tyeth 929eb9a
Update WipperSnapper_I2C_Driver_LPS28DFW.h
tyeth abf14e0
Update LPS28DFW to use extreme range of 260-4060hPa
tyeth 20d936d
Switch LPS28 to full range
tyeth 547d46c
Merge branch 'main' into add-lps28
tyeth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/*! | ||
* @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 <Adafruit_LPS28.h> | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@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 | ||
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; | ||
} | ||
if (!_lps28->setFullScaleMode(true)) { | ||
WS_DEBUG_PRINTLN("Failed to set 4060hPa max mode"); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@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 = 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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.