Skip to content
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

Add BMP388 / BMP3xx #461

Merged
merged 6 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 client for Adafruit.io WipperSnapper
category=Communication
url=https://github.com/adafruit/Adafruit_IO_Arduino
architectures=*
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit DPS310, Adafruit SCD30, Adafruit SGP30 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit PM25 AQI Sensor, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit PCT2075, hp_BH1750
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit SCD30, Adafruit SGP30 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit PM25 AQI Sensor, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit PCT2075, hp_BH1750
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lib_deps =
adafruit/Adafruit AHTX0
adafruit/Adafruit BME280 Library
adafruit/Adafruit BMP280 Library
adafruit/Adafruit BMP3XX Library
adafruit/Adafruit DPS310
adafruit/Adafruit HTS221
adafruit/Adafruit PCT2075
Expand Down
11 changes: 11 additions & 0 deletions src/components/i2c/WipperSnapper_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
_bmp280->configureDriver(msgDeviceInitReq);
drivers.push_back(_bmp280);
WS_DEBUG_PRINTLN("BMP280 Initialized Successfully!");
} else if (strcmp("bmp388", msgDeviceInitReq->i2c_device_name) == 0) {
_bmp3xx = new WipperSnapper_I2C_Driver_BMP3XX(this->_i2c, i2cAddress);
if (!_bmp3xx->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize BMP388!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_bmp3xx->configureDriver(msgDeviceInitReq);
drivers.push_back(_bmp3xx);
WS_DEBUG_PRINTLN("BMP388 Initialized Successfully!");
} else if (strcmp("bme680", msgDeviceInitReq->i2c_device_name) == 0) {
_bme680 = new WipperSnapper_I2C_Driver_BME680(this->_i2c, i2cAddress);
if (!_bme680->begin()) {
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 @@ -26,6 +26,7 @@
#include "drivers/WipperSnapper_I2C_Driver_BME280.h"
#include "drivers/WipperSnapper_I2C_Driver_BME680.h"
#include "drivers/WipperSnapper_I2C_Driver_BMP280.h"
#include "drivers/WipperSnapper_I2C_Driver_BMP3XX.h"
#include "drivers/WipperSnapper_I2C_Driver_DPS310.h"
#include "drivers/WipperSnapper_I2C_Driver_HTS221.h"
#include "drivers/WipperSnapper_I2C_Driver_LC709203F.h"
Expand Down Expand Up @@ -100,6 +101,7 @@ class WipperSnapper_Component_I2C {
WipperSnapper_I2C_Driver_BH1750 *_bh1750 = nullptr;
WipperSnapper_I2C_Driver_BME280 *_bme280 = nullptr;
WipperSnapper_I2C_Driver_BMP280 *_bmp280 = nullptr;
WipperSnapper_I2C_Driver_BMP3XX *_bmp3xx = nullptr;
WipperSnapper_I2C_Driver_BME680 *_bme680 = nullptr;
WipperSnapper_I2C_Driver_HTS221 *_hts221 = nullptr;
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
Expand Down
131 changes: 131 additions & 0 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP3XX.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*!
* @file WipperSnapper_I2C_Driver_BMP3XX.h
*
* Device driver for a BMP3XX 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 2023 for Adafruit Industries.
*
* MIT license, all text here must be included in any redistribution.
*
*/

#ifndef WipperSnapper_I2C_Driver_BMP3XX_H
#define WipperSnapper_I2C_Driver_BMP3XX_H

#include "WipperSnapper_I2C_Driver.h"
#include <Adafruit_BMP3XX.h>

#define SEALEVELPRESSURE_HPA (1013.25) ///< Default sea level pressure, in hPa

/**************************************************************************/
/*!
@brief Class that provides a sensor driver for the BMP3XX temperature
and pressure sensor.
*/
/**************************************************************************/
class WipperSnapper_I2C_Driver_BMP3XX : public WipperSnapper_I2C_Driver {

public:
/*******************************************************************************/
/*!
@brief Constructor for an BMP3XX sensor.
@param i2c
The I2C interface.
@param sensorAddress
7-bit device address.
*/
/*******************************************************************************/
WipperSnapper_I2C_Driver_BMP3XX(TwoWire *i2c, uint16_t sensorAddress)
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
_i2c = i2c;
_sensorAddress = sensorAddress;
}

/*******************************************************************************/
/*!
@brief Destructor for an BMP3XX sensor.
*/
/*******************************************************************************/
~WipperSnapper_I2C_Driver_BMP3XX() { delete _bmp3xx; }

/*******************************************************************************/
/*!
@brief Initializes the BMP3XX sensor and begins I2C.
@returns True if initialized successfully, False otherwise.
*/
/*******************************************************************************/
bool begin() {
_bmp3xx = new Adafruit_BMP3XX();
// attempt to initialize BMP3XX
if (!_bmp3xx->begin_I2C(_sensorAddress, _i2c))
return false;

// Set up oversampling and filter initialization
_bmp3xx->setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
_bmp3xx->setPressureOversampling(BMP3_OVERSAMPLING_4X);
_bmp3xx->setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
_bmp3xx->setOutputDataRate(BMP3_ODR_50_HZ);

return true;
}

/*******************************************************************************/
/*!
@brief Gets the BMP3XX'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 (!_bmp3xx->performReading())
return false;
tempEvent->temperature = _bmp3xx->temperature;
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 (!_bmp3xx->performReading())
return false;
pressureEvent->pressure = _bmp3xx->pressure / 100.0F;
return true;
}

/*******************************************************************************/
/*!
@brief Reads a the BMP3XX's altitude sensor into an event.
@param altitudeEvent
Pointer to an adafruit sensor event.
@returns True if the sensor event was obtained successfully, False
otherwise.
*/
/*******************************************************************************/
bool getEventAltitude(sensors_event_t *altitudeEvent) {
if (!_bmp3xx->performReading())
return false;
// TODO: update once we add an altitude sensor type
// see https://github.com/adafruit/Adafruit_Sensor/issues/52
altitudeEvent->data[0] = _bmp3xx->readAltitude(SEALEVELPRESSURE_HPA);
return true;
}

protected:
Adafruit_BMP3XX *_bmp3xx; ///< BMP3XX object
};

#endif // WipperSnapper_I2C_Driver_BMP3XX
Loading