Skip to content

Commit

Permalink
Merge branch 'main' into scd30-scd4x-others-poll-min-1sec
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth authored Mar 7, 2025
2 parents 272c1fc + 712e434 commit ba1f09f
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 13 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, SdFat - Adafruit Fork, Adafruit GFX Library
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, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, SdFat - Adafruit Fork, Adafruit GFX Library
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Wippersnapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2502,11 +2502,11 @@ void Wippersnapper::runNetFSM() {
*/
/**************************************************************************/
void Wippersnapper::haltError(String error, ws_led_status_t ledStatusColor,
uint8_t seconds_until_reboot) {
int seconds_until_reboot) {
#ifdef ARDUINO_ARCH_ESP8266
uint8_t wdt_timeout_ms = 3200;
int wdt_timeout_ms = 3200;
#else
uint8_t wdt_timeout_ms = 5000;
int wdt_timeout_ms = 5000;
#endif
int seconds_until_wdt_enable =
seconds_until_reboot - (int)(wdt_timeout_ms / 1000);
Expand Down
2 changes: 1 addition & 1 deletion src/Wippersnapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class Wippersnapper {
// Error handling helpers
void haltError(String error,
ws_led_status_t ledStatusColor = WS_LED_STATUS_ERROR_RUNTIME,
uint8_t seconds_until_reboot = 25);
int seconds_until_reboot = 25);
void errorWriteHang(String error);

// MQTT topic callbacks //
Expand Down
15 changes: 13 additions & 2 deletions src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("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);
Expand Down Expand Up @@ -1072,8 +1083,8 @@ void WipperSnapper_Component_I2C::update() {
// Number of events which occured for this driver
msgi2cResponse.payload.resp_i2c_device_event.sensor_event_count = 0;

// Event struct
sensors_event_t event;
// Event struct - zero-initialise on each iteration
sensors_event_t event = {0};

// AMBIENT_TEMPERATURE sensor (°C)
sensorEventRead(
Expand Down
2 changes: 2 additions & 0 deletions src/components/i2c/WipperSnapper_I2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
151 changes: 151 additions & 0 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_LPS28DFW.h
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
8 changes: 4 additions & 4 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_PM25.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class WipperSnapper_I2C_Driver_PM25 : public WipperSnapper_I2C_Driver {
*/
/*******************************************************************************/
bool getEventPM10_STD(sensors_event_t *pm10StdEvent) {
PM25_AQI_Data data;
PM25_AQI_Data data = {0};
if (!_pm25->read(&data))
return false; // couldn't read data

Expand All @@ -89,7 +89,7 @@ class WipperSnapper_I2C_Driver_PM25 : public WipperSnapper_I2C_Driver {
*/
/*******************************************************************************/
bool getEventPM25_STD(sensors_event_t *pm25StdEvent) {
PM25_AQI_Data data;
PM25_AQI_Data data = {0};
if (!_pm25->read(&data))
return false; // couldn't read data

Expand All @@ -107,7 +107,7 @@ class WipperSnapper_I2C_Driver_PM25 : public WipperSnapper_I2C_Driver {
*/
/*******************************************************************************/
bool getEventPM100_STD(sensors_event_t *pm100StdEvent) {
PM25_AQI_Data data;
PM25_AQI_Data data = {0};
if (!_pm25->read(&data))
return false; // couldn't read data

Expand All @@ -116,7 +116,7 @@ class WipperSnapper_I2C_Driver_PM25 : public WipperSnapper_I2C_Driver {
}

protected:
Adafruit_PM25AQI *_pm25; ///< PM25 driver object
Adafruit_PM25AQI *_pm25 = nullptr; ///< PM25 driver object
};

#endif // WipperSnapper_I2C_Driver_PM25
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class WipperSnapper_I2C_Driver_VL53L4CD : public WipperSnapper_I2C_Driver {
/*******************************************************************************/
bool getEventProximity(sensors_event_t *proximityEvent) {
uint8_t NewDataReady = 0;
VL53L4CD_Result_t results;
VL53L4CD_Result_t results = {0};
uint8_t status;
// Start fresh reading, seemed to be accepting stale value
_VL53L4CD->VL53L4CD_ClearInterrupt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class WipperSnapper_I2C_Driver_VL53L4CX : public WipperSnapper_I2C_Driver {
*/
/*******************************************************************************/
bool getProximity(sensors_event_t *proximityEvent, int whichObject = 0) {
VL53L4CX_MultiRangingData_t MultiRangingData;
VL53L4CX_MultiRangingData_t MultiRangingData = {0};
VL53L4CX_MultiRangingData_t *pMultiRangingData = &MultiRangingData;
uint8_t NewDataReady = 0;
int status;
Expand Down

0 comments on commit ba1f09f

Please sign in to comment.