Skip to content

Commit 134fe1b

Browse files
committed
Add MPL115A2
1 parent e680d3a commit 134fe1b

File tree

5 files changed

+115
-1
lines changed

5 files changed

+115
-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 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
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 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

platformio.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ lib_deps =
3434
adafruit/Adafruit Si7021 Library
3535
adafruit/Adafruit MCP9808 Library
3636
adafruit/Adafruit MCP9600 Library
37+
adafruit/Adafruit MPL115A2
3738
adafruit/Adafruit TMP117
3839
adafruit/Adafruit TSL2591 Library
3940
adafruit/Adafruit_VL53L0X

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
348348
_mcp9808->configureDriver(msgDeviceInitReq);
349349
drivers.push_back(_mcp9808);
350350
WS_DEBUG_PRINTLN("MCP9808 Initialized Successfully!");
351+
} else if (strcmp("mpl115a2", msgDeviceInitReq->i2c_device_name) == 0) {
352+
_mpl115a2 = new WipperSnapper_I2C_Driver_MPL115A2(this->_i2c, i2cAddress);
353+
if (!_mpl115a2->begin()) {
354+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize MPL115A2!");
355+
_busStatusResponse =
356+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
357+
return false;
358+
}
359+
_mpl115a2->configureDriver(msgDeviceInitReq);
360+
drivers.push_back(_mpl115a2);
361+
WS_DEBUG_PRINTLN("MPL115A2 Initialized Successfully!");
351362
} else if (strcmp("tmp117", msgDeviceInitReq->i2c_device_name) == 0) {
352363
_tmp117 = new WipperSnapper_I2C_Driver_TMP117(this->_i2c, i2cAddress);
353364
if (!_tmp117->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "drivers/WipperSnapper_I2C_Driver_LPS3XHW.h"
3434
#include "drivers/WipperSnapper_I2C_Driver_MAX17048.h"
3535
#include "drivers/WipperSnapper_I2C_Driver_MCP9808.h"
36+
#include "drivers/WipperSnapper_I2C_Driver_MPL115A2.h"
3637
#include "drivers/WipperSnapper_I2C_Driver_PCT2075.h"
3738
#include "drivers/WipperSnapper_I2C_Driver_PM25.h"
3839
#include "drivers/WipperSnapper_I2C_Driver_SCD30.h"
@@ -106,6 +107,7 @@ class WipperSnapper_Component_I2C {
106107
WipperSnapper_I2C_Driver_BME680 *_bme680 = nullptr;
107108
WipperSnapper_I2C_Driver_HTS221 *_hts221 = nullptr;
108109
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
110+
WipperSnapper_I2C_Driver_MPL115A2 *_mpl115a2 = nullptr;
109111
WipperSnapper_I2C_Driver_TMP117 *_tmp117 = nullptr;
110112
WipperSnapper_I2C_Driver_TSL2591 *_tsl2591 = nullptr;
111113
WipperSnapper_I2C_Driver_VEML7700 *_veml7700 = nullptr;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_MPL115A2.h
3+
*
4+
* Device driver for a MPL115A2 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_MPL115A2_H
17+
#define WipperSnapper_I2C_Driver_MPL115A2_H
18+
19+
#include "WipperSnapper_I2C_Driver.h"
20+
#include <Adafruit_MPL115A2.h>
21+
22+
/**************************************************************************/
23+
/*!
24+
@brief Class that provides a sensor driver for the MPL115A2 temperature
25+
and pressure sensor.
26+
*/
27+
/**************************************************************************/
28+
class WipperSnapper_I2C_Driver_MPL115A2 : public WipperSnapper_I2C_Driver {
29+
30+
public:
31+
/*******************************************************************************/
32+
/*!
33+
@brief Constructor for an MPL115A2 sensor.
34+
@param i2c
35+
The I2C interface.
36+
@param sensorAddress
37+
7-bit device address.
38+
*/
39+
/*******************************************************************************/
40+
WipperSnapper_I2C_Driver_MPL115A2(TwoWire *i2c, uint16_t sensorAddress)
41+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
42+
_i2c = i2c;
43+
_sensorAddress = sensorAddress;
44+
}
45+
46+
/*******************************************************************************/
47+
/*!
48+
@brief Destructor for an MPL115A2 sensor.
49+
*/
50+
/*******************************************************************************/
51+
~WipperSnapper_I2C_Driver_MPL115A2() { delete _mpl115a2; }
52+
53+
/*******************************************************************************/
54+
/*!
55+
@brief Initializes the MPL115A2 sensor and begins I2C.
56+
@returns True if initialized successfully, False otherwise.
57+
*/
58+
/*******************************************************************************/
59+
bool begin() {
60+
_mpl115a2 = new Adafruit_MPL115A2();
61+
// attempt to initialize MPL115A2
62+
if (!_mpl115a2->begin(_sensorAddress, _i2c))
63+
return false;
64+
return true;
65+
}
66+
67+
/*******************************************************************************/
68+
/*!
69+
@brief Gets the MPL115A2's current temperature.
70+
@param tempEvent
71+
Pointer to an Adafruit_Sensor event.
72+
@returns True if the temperature was obtained successfully, False
73+
otherwise.
74+
*/
75+
/*******************************************************************************/
76+
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
77+
tempEvent->temperature = _mpl115a2->getTemperature();
78+
return true;
79+
}
80+
81+
/*******************************************************************************/
82+
/*!
83+
@brief Reads a pressure sensor and converts
84+
the reading into the expected SI unit (hPa).
85+
@param pressureEvent
86+
Pointer to an Adafruit_Sensor event.
87+
@returns True if the sensor event was obtained successfully, False
88+
otherwise.
89+
*/
90+
/*******************************************************************************/
91+
bool getEventPressure(sensors_event_t *pressureEvent) {
92+
pressureEvent->pressure = _mpl115a2->getPressure() * 10;
93+
return true;
94+
}
95+
96+
protected:
97+
Adafruit_MPL115A2 *_mpl115a2; ///< MPL115A2 object
98+
};
99+
100+
#endif // WipperSnapper_I2C_Driver_MPL115A2

0 commit comments

Comments
 (0)