Skip to content

Commit b2ebe93

Browse files
authored
Merge pull request #461 from tyeth/add-bmp388
Add BMP388 / BMP3xx
2 parents e79320a + a69b1e8 commit b2ebe93

File tree

5 files changed

+146
-1
lines changed

5 files changed

+146
-1
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=Arduino client for Adafruit.io WipperSnapper
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_IO_Arduino
99
architectures=*
10-
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
10+
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

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ lib_deps =
2525
adafruit/Adafruit AHTX0
2626
adafruit/Adafruit BME280 Library
2727
adafruit/Adafruit BMP280 Library
28+
adafruit/Adafruit BMP3XX Library
2829
adafruit/Adafruit DPS310
2930
adafruit/Adafruit HTS221
3031
adafruit/Adafruit PCT2075

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
258258
_bmp280->configureDriver(msgDeviceInitReq);
259259
drivers.push_back(_bmp280);
260260
WS_DEBUG_PRINTLN("BMP280 Initialized Successfully!");
261+
} else if (strcmp("bmp388", msgDeviceInitReq->i2c_device_name) == 0) {
262+
_bmp3xx = new WipperSnapper_I2C_Driver_BMP3XX(this->_i2c, i2cAddress);
263+
if (!_bmp3xx->begin()) {
264+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize BMP388!");
265+
_busStatusResponse =
266+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
267+
return false;
268+
}
269+
_bmp3xx->configureDriver(msgDeviceInitReq);
270+
drivers.push_back(_bmp3xx);
271+
WS_DEBUG_PRINTLN("BMP388 Initialized Successfully!");
261272
} else if (strcmp("bme680", msgDeviceInitReq->i2c_device_name) == 0) {
262273
_bme680 = new WipperSnapper_I2C_Driver_BME680(this->_i2c, i2cAddress);
263274
if (!_bme680->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "drivers/WipperSnapper_I2C_Driver_BME280.h"
2727
#include "drivers/WipperSnapper_I2C_Driver_BME680.h"
2828
#include "drivers/WipperSnapper_I2C_Driver_BMP280.h"
29+
#include "drivers/WipperSnapper_I2C_Driver_BMP3XX.h"
2930
#include "drivers/WipperSnapper_I2C_Driver_DPS310.h"
3031
#include "drivers/WipperSnapper_I2C_Driver_HTS221.h"
3132
#include "drivers/WipperSnapper_I2C_Driver_LC709203F.h"
@@ -100,6 +101,7 @@ class WipperSnapper_Component_I2C {
100101
WipperSnapper_I2C_Driver_BH1750 *_bh1750 = nullptr;
101102
WipperSnapper_I2C_Driver_BME280 *_bme280 = nullptr;
102103
WipperSnapper_I2C_Driver_BMP280 *_bmp280 = nullptr;
104+
WipperSnapper_I2C_Driver_BMP3XX *_bmp3xx = nullptr;
103105
WipperSnapper_I2C_Driver_BME680 *_bme680 = nullptr;
104106
WipperSnapper_I2C_Driver_HTS221 *_hts221 = nullptr;
105107
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_BMP3XX.h
3+
*
4+
* Device driver for a BMP3XX precision pressure sensor breakout.
5+
*
6+
* Adafruit invests time and resources providing this open source code,
7+
* please support Adafruit and open-source hardware by purchasing
8+
* products from Adafruit!
9+
*
10+
* Copyright (c) Tyeth Gundry 2023 for Adafruit Industries.
11+
*
12+
* MIT license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
16+
#ifndef WipperSnapper_I2C_Driver_BMP3XX_H
17+
#define WipperSnapper_I2C_Driver_BMP3XX_H
18+
19+
#include "WipperSnapper_I2C_Driver.h"
20+
#include <Adafruit_BMP3XX.h>
21+
22+
#define SEALEVELPRESSURE_HPA (1013.25) ///< Default sea level pressure, in hPa
23+
24+
/**************************************************************************/
25+
/*!
26+
@brief Class that provides a sensor driver for the BMP3XX temperature
27+
and pressure sensor.
28+
*/
29+
/**************************************************************************/
30+
class WipperSnapper_I2C_Driver_BMP3XX : public WipperSnapper_I2C_Driver {
31+
32+
public:
33+
/*******************************************************************************/
34+
/*!
35+
@brief Constructor for an BMP3XX sensor.
36+
@param i2c
37+
The I2C interface.
38+
@param sensorAddress
39+
7-bit device address.
40+
*/
41+
/*******************************************************************************/
42+
WipperSnapper_I2C_Driver_BMP3XX(TwoWire *i2c, uint16_t sensorAddress)
43+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
44+
_i2c = i2c;
45+
_sensorAddress = sensorAddress;
46+
}
47+
48+
/*******************************************************************************/
49+
/*!
50+
@brief Destructor for an BMP3XX sensor.
51+
*/
52+
/*******************************************************************************/
53+
~WipperSnapper_I2C_Driver_BMP3XX() { delete _bmp3xx; }
54+
55+
/*******************************************************************************/
56+
/*!
57+
@brief Initializes the BMP3XX sensor and begins I2C.
58+
@returns True if initialized successfully, False otherwise.
59+
*/
60+
/*******************************************************************************/
61+
bool begin() {
62+
_bmp3xx = new Adafruit_BMP3XX();
63+
// attempt to initialize BMP3XX
64+
if (!_bmp3xx->begin_I2C(_sensorAddress, _i2c))
65+
return false;
66+
67+
// Set up oversampling and filter initialization
68+
_bmp3xx->setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
69+
_bmp3xx->setPressureOversampling(BMP3_OVERSAMPLING_4X);
70+
_bmp3xx->setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
71+
_bmp3xx->setOutputDataRate(BMP3_ODR_50_HZ);
72+
73+
return true;
74+
}
75+
76+
/*******************************************************************************/
77+
/*!
78+
@brief Gets the BMP3XX's current temperature.
79+
@param tempEvent
80+
Pointer to an Adafruit_Sensor event.
81+
@returns True if the temperature was obtained successfully, False
82+
otherwise.
83+
*/
84+
/*******************************************************************************/
85+
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
86+
if (!_bmp3xx->performReading())
87+
return false;
88+
tempEvent->temperature = _bmp3xx->temperature;
89+
return true;
90+
}
91+
92+
/*******************************************************************************/
93+
/*!
94+
@brief Reads a pressure sensor and converts
95+
the reading into the expected SI unit.
96+
@param pressureEvent
97+
Pointer to an Adafruit_Sensor event.
98+
@returns True if the sensor event was obtained successfully, False
99+
otherwise.
100+
*/
101+
/*******************************************************************************/
102+
bool getEventPressure(sensors_event_t *pressureEvent) {
103+
if (!_bmp3xx->performReading())
104+
return false;
105+
pressureEvent->pressure = _bmp3xx->pressure / 100.0F;
106+
return true;
107+
}
108+
109+
/*******************************************************************************/
110+
/*!
111+
@brief Reads a the BMP3XX's altitude sensor into an event.
112+
@param altitudeEvent
113+
Pointer to an adafruit sensor event.
114+
@returns True if the sensor event was obtained successfully, False
115+
otherwise.
116+
*/
117+
/*******************************************************************************/
118+
bool getEventAltitude(sensors_event_t *altitudeEvent) {
119+
if (!_bmp3xx->performReading())
120+
return false;
121+
// TODO: update once we add an altitude sensor type
122+
// see https://github.com/adafruit/Adafruit_Sensor/issues/52
123+
altitudeEvent->data[0] = _bmp3xx->readAltitude(SEALEVELPRESSURE_HPA);
124+
return true;
125+
}
126+
127+
protected:
128+
Adafruit_BMP3XX *_bmp3xx; ///< BMP3XX object
129+
};
130+
131+
#endif // WipperSnapper_I2C_Driver_BMP3XX

0 commit comments

Comments
 (0)