Skip to content

Commit

Permalink
Add BMP280
Browse files Browse the repository at this point in the history
  • Loading branch information
tyeth committed Jul 31, 2023
1 parent be20401 commit 5bd91cb
Show file tree
Hide file tree
Showing 5 changed files with 154 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 TinyUSB Library, Adafruit AHTX0, Adafruit BME280 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 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
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ lib_deps =
adafruit/Adafruit SleepyDog Library
adafruit/Adafruit AHTX0
adafruit/Adafruit BME280 Library
adafruit/Adafruit BMP280 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 @@ -247,6 +247,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
_bme280->configureDriver(msgDeviceInitReq);
drivers.push_back(_bme280);
WS_DEBUG_PRINTLN("BME280 Initialized Successfully!");
} else if (strcmp("bmp280", msgDeviceInitReq->i2c_device_name) == 0) {
_bmp280 = new WipperSnapper_I2C_Driver_BMP280(this->_i2c, i2cAddress);
if (!_bmp280->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize BMP280!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_bmp280->configureDriver(msgDeviceInitReq);
drivers.push_back(_bmp280);
WS_DEBUG_PRINTLN("BMP280 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 @@ -24,6 +24,7 @@
#include "drivers/WipperSnapper_I2C_Driver_AHTX0.h"
#include "drivers/WipperSnapper_I2C_Driver_BH1750.h"
#include "drivers/WipperSnapper_I2C_Driver_BME280.h"
#include "drivers/WipperSnapper_I2C_Driver_BMP280.h"
#include "drivers/WipperSnapper_I2C_Driver_BME680.h"
#include "drivers/WipperSnapper_I2C_Driver_DPS310.h"
#include "drivers/WipperSnapper_I2C_Driver_HTS221.h"
Expand Down Expand Up @@ -97,6 +98,7 @@ class WipperSnapper_Component_I2C {
WipperSnapper_I2C_Driver_SCD30 *_scd30 = nullptr;
WipperSnapper_I2C_Driver_BH1750 *_bh1750 = nullptr;
WipperSnapper_I2C_Driver_BME280 *_bme280 = nullptr;
WipperSnapper_I2C_Driver_BMP280 *_bmp280 = nullptr;
WipperSnapper_I2C_Driver_BME680 *_bme680 = nullptr;
WipperSnapper_I2C_Driver_HTS221 *_hts221 = nullptr;
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
Expand Down
139 changes: 139 additions & 0 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_BMP280.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*!
* @file WipperSnapper_I2C_Driver_BMP280.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_BMP280_H
#define WipperSnapper_I2C_Driver_BMP280_H

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

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

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

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

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

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

// set up sampling as recommended in Adafruit library
_bmp->setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering. */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

// configure BMP280 device
_bmp_temp = _bmp->getTemperatureSensor();
_bmp_pressure = _bmp->getPressureSensor();
return true;
}

/*******************************************************************************/
/*!
@brief Gets the BMP280'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_temp == NULL)
return false;
_bmp_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 (_bmp_pressure == NULL)
return false;
_bmp_pressure->getEvent(pressureEvent);
return true;
}

/*******************************************************************************/
/*!
@brief Reads a the BMP280'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) {
// TODO: Note, this is a hack into Adafruit_Sensor, we should really add an
// altitude sensor type
altitudeEvent->data[0] = _bmp->readAltitude(SEALEVELPRESSURE_HPA);
return true;
}

protected:
Adafruit_BMP280 *_bmp; ///< BMP280 object
Adafruit_Sensor *_bmp_temp =
NULL; ///< Ptr to an adafruit_sensor representing the temperature
Adafruit_Sensor *_bmp_pressure =
NULL; ///< Ptr to an adafruit_sensor representing the pressure
Adafruit_Sensor *_bmp_humidity =
NULL; ///< Ptr to an adafruit_sensor representing the humidity
};

#endif // WipperSnapper_I2C_Driver_BMP280

0 comments on commit 5bd91cb

Please sign in to comment.