-
Notifications
You must be signed in to change notification settings - Fork 54
LPS28 branch I2c Fix for S2, BSP Arduino-ESP32 3.1.3 Earle Core RP2xxx 4.4.1 #702
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
Changes from all commits
36a4c89
df2b6b0
df71485
929eb9a
abf14e0
20d936d
6a8dee6
5087720
aac16e0
e47f79e
683a415
f89fb52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,22 +156,37 @@ WipperSnapper_Component_I2C::scanAddresses() { | |
|
||
// Scan all I2C addresses between 0x08 and 0x7F inclusive and return a list of | ||
// those that respond. | ||
uint8_t addresses_failed_count = 0, current_failed_count = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this all related to #700? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this branch/PR was to get the build passing for LPS28 (as related to RP2040) along with test i2c scan changes in relation to #700 |
||
WS_DEBUG_PRINTLN("EXEC: I2C Scan"); | ||
for (address = 0x08; address < 0x7F; address++) { | ||
start_scan: | ||
current_failed_count = 0; | ||
_i2c->beginTransmission(address); | ||
endTransmissionRC = _i2c->endTransmission(); | ||
|
||
#if defined(ARDUINO_ARCH_ESP32) | ||
// Check endTransmission()'s return code (Arduino-ESP32 ONLY) | ||
// https://github.com/espressif/arduino-esp32/blob/master/libraries/Wire/src/Wire.cpp | ||
if (endTransmissionRC == 5) { | ||
WS_DEBUG_PRINTLN("ESP_ERR_TIMEOUT: I2C Bus Busy"); | ||
addresses_failed_count++; | ||
current_failed_count++; | ||
WS_DEBUG_PRINT("ESP_ERR_TIMEOUT: I2C Bus Busy - (Address: 0x"); | ||
WS_DEBUG_PRINT(address, HEX); | ||
WS_DEBUG_PRINT(" - Error Count: "); | ||
WS_DEBUG_PRINT(current_failed_count); | ||
WS_DEBUG_PRINT(" of "); | ||
WS_DEBUG_PRINT(addresses_failed_count); | ||
WS_DEBUG_PRINT(")"); | ||
scanResp.bus_response = | ||
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_ERROR_HANG; | ||
// NOTE: ESP-IDF appears to handle this "behind the scenes" by | ||
// resetting/clearing the bus. The user should be prompted to | ||
// perform a bus scan again. | ||
break; | ||
// perform a bus scan again. Workaround for ESP32-S2 in v3.1.x | ||
if (current_failed_count > 5 || addresses_failed_count > 100) { | ||
WS_DEBUG_PRINTLN("ESP_ERR_TIMEOUT: Too many bus hangs"); | ||
break; | ||
} | ||
goto start_scan; | ||
} else if (endTransmissionRC == 7) { | ||
WS_DEBUG_PRINT("I2C_ESP_ERR: SDA/SCL shorted, requests queued: "); | ||
WS_DEBUG_PRINTLN(endTransmissionRC); | ||
|
@@ -709,6 +724,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice( | |
_lps25hb->configureDriver(msgDeviceInitReq); | ||
drivers.push_back(_lps25hb); | ||
WS_DEBUG_PRINTLN("LPS25HB Sensor Initialized Successfully!"); | ||
} 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!"); | ||
_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); | ||
|
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this driver require the changes to |
||
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert these changes and pull
main
, in favor of solution #706