Skip to content

Commit

Permalink
Add BMP388 / BMP3xx
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Aug 7, 2023
1 parent e79320a commit 553d2b8
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1 deletion.
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) {
_bmp388 = new WipperSnapper_I2C_Driver_BMP388(this->_i2c, i2cAddress);
if (!_bmp388->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize BMP388!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_bmp388->configureDriver(msgDeviceInitReq);
drivers.push_back(_bmp388);
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_BMP388.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_BMP388 *_bmp388 = 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_BMP388.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*!
* @file WipperSnapper_I2C_Driver_BMP388.h
*
* Device driver for an AHT Humidity and Temperature sensor.
*
* 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_BMP388_H
#define WipperSnapper_I2C_Driver_BMP388_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 BMP388 temperature
and pressure sensor.
*/
/**************************************************************************/
class WipperSnapper_I2C_Driver_BMP388 : public WipperSnapper_I2C_Driver {

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

/*******************************************************************************/
/*!
@brief Destructor for an BMP388 sensor.
*/
/*******************************************************************************/
~WipperSnapper_I2C_Driver_BMP388() { delete _bmp; }

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

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

return true;
}

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

/*******************************************************************************/
/*!
@brief Reads a the BMP388'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(!_bmp->performReading())
return false;
// TODO: update once we add an altitude sensor type
// see https://github.com/adafruit/Adafruit_Sensor/issues/52
altitudeEvent->data[0] = _bmp->readAltitude(SEALEVELPRESSURE_HPA);
return true;
}

protected:
Adafruit_BMP3XX *_bmp; ///< BMP388 object
};

#endif // WipperSnapper_I2C_Driver_BMP388

0 comments on commit 553d2b8

Please sign in to comment.