Skip to content

Commit

Permalink
Merge pull request #468 from tyeth/add-MPL115A2
Browse files Browse the repository at this point in the history
Add MPL115A2
  • Loading branch information
brentru authored Aug 16, 2023
2 parents b13d677 + 134fe1b commit d5e9a70
Show file tree
Hide file tree
Showing 5 changed files with 115 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 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 LPS35HW, 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 MPL115A2, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit PM25 AQI Sensor, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS35HW, 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 @@ -34,6 +34,7 @@ lib_deps =
adafruit/Adafruit Si7021 Library
adafruit/Adafruit MCP9808 Library
adafruit/Adafruit MCP9600 Library
adafruit/Adafruit MPL115A2
adafruit/Adafruit TMP117
adafruit/Adafruit TSL2591 Library
adafruit/Adafruit_VL53L0X
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 @@ -348,6 +348,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
_mcp9808->configureDriver(msgDeviceInitReq);
drivers.push_back(_mcp9808);
WS_DEBUG_PRINTLN("MCP9808 Initialized Successfully!");
} else if (strcmp("mpl115a2", msgDeviceInitReq->i2c_device_name) == 0) {
_mpl115a2 = new WipperSnapper_I2C_Driver_MPL115A2(this->_i2c, i2cAddress);
if (!_mpl115a2->begin()) {
WS_DEBUG_PRINTLN("ERROR: Failed to initialize MPL115A2!");
_busStatusResponse =
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
return false;
}
_mpl115a2->configureDriver(msgDeviceInitReq);
drivers.push_back(_mpl115a2);
WS_DEBUG_PRINTLN("MPL115A2 Initialized Successfully!");
} else if (strcmp("tmp117", msgDeviceInitReq->i2c_device_name) == 0) {
_tmp117 = new WipperSnapper_I2C_Driver_TMP117(this->_i2c, i2cAddress);
if (!_tmp117->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 @@ -33,6 +33,7 @@
#include "drivers/WipperSnapper_I2C_Driver_LPS3XHW.h"
#include "drivers/WipperSnapper_I2C_Driver_MAX17048.h"
#include "drivers/WipperSnapper_I2C_Driver_MCP9808.h"
#include "drivers/WipperSnapper_I2C_Driver_MPL115A2.h"
#include "drivers/WipperSnapper_I2C_Driver_PCT2075.h"
#include "drivers/WipperSnapper_I2C_Driver_PM25.h"
#include "drivers/WipperSnapper_I2C_Driver_SCD30.h"
Expand Down Expand Up @@ -106,6 +107,7 @@ class WipperSnapper_Component_I2C {
WipperSnapper_I2C_Driver_BME680 *_bme680 = nullptr;
WipperSnapper_I2C_Driver_HTS221 *_hts221 = nullptr;
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
WipperSnapper_I2C_Driver_MPL115A2 *_mpl115a2 = nullptr;
WipperSnapper_I2C_Driver_TMP117 *_tmp117 = nullptr;
WipperSnapper_I2C_Driver_TSL2591 *_tsl2591 = nullptr;
WipperSnapper_I2C_Driver_VEML7700 *_veml7700 = nullptr;
Expand Down
100 changes: 100 additions & 0 deletions src/components/i2c/drivers/WipperSnapper_I2C_Driver_MPL115A2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*!
* @file WipperSnapper_I2C_Driver_MPL115A2.h
*
* Device driver for a MPL115A2 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_MPL115A2_H
#define WipperSnapper_I2C_Driver_MPL115A2_H

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

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

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

/*******************************************************************************/
/*!
@brief Destructor for an MPL115A2 sensor.
*/
/*******************************************************************************/
~WipperSnapper_I2C_Driver_MPL115A2() { delete _mpl115a2; }

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

/*******************************************************************************/
/*!
@brief Gets the MPL115A2'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) {
tempEvent->temperature = _mpl115a2->getTemperature();
return true;
}

/*******************************************************************************/
/*!
@brief Reads a pressure sensor and converts
the reading into the expected SI unit (hPa).
@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) {
pressureEvent->pressure = _mpl115a2->getPressure() * 10;
return true;
}

protected:
Adafruit_MPL115A2 *_mpl115a2; ///< MPL115A2 object
};

#endif // WipperSnapper_I2C_Driver_MPL115A2

0 comments on commit d5e9a70

Please sign in to comment.