Skip to content

Commit 4ae8deb

Browse files
committed
Add MS8607 driver
1 parent 02e2bb9 commit 4ae8deb

File tree

5 files changed

+144
-1
lines changed

5 files changed

+144
-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 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
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 MS8607, 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
@@ -35,6 +35,7 @@ lib_deps =
3535
adafruit/Adafruit MCP9808 Library
3636
adafruit/Adafruit MCP9600 Library
3737
adafruit/Adafruit MPL115A2
38+
adafruit/Adafruit MS8607
3839
adafruit/Adafruit TMP117
3940
adafruit/Adafruit TSL2591 Library
4041
adafruit/Adafruit_VL53L0X

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,17 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
362362
_mpl115a2->configureDriver(msgDeviceInitReq);
363363
drivers.push_back(_mpl115a2);
364364
WS_DEBUG_PRINTLN("MPL115A2 Initialized Successfully!");
365+
} else if (strcmp("ms8607", msgDeviceInitReq->i2c_device_name) == 0) {
366+
_ms8607 = new WipperSnapper_I2C_Driver_MS8607(this->_i2c, i2cAddress);
367+
if (!_ms8607->begin()) {
368+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize MS8607!");
369+
_busStatusResponse =
370+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
371+
return false;
372+
}
373+
_ms8607->configureDriver(msgDeviceInitReq);
374+
drivers.push_back(_ms8607);
375+
WS_DEBUG_PRINTLN("MS8607 Initialized Successfully!");
365376
} else if (strcmp("tmp117", msgDeviceInitReq->i2c_device_name) == 0) {
366377
_tmp117 = new WipperSnapper_I2C_Driver_TMP117(this->_i2c, i2cAddress);
367378
if (!_tmp117->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "drivers/WipperSnapper_I2C_Driver_MAX17048.h"
3535
#include "drivers/WipperSnapper_I2C_Driver_MCP9808.h"
3636
#include "drivers/WipperSnapper_I2C_Driver_MPL115A2.h"
37+
#include "drivers/WipperSnapper_I2C_Driver_MS8607.h"
3738
#include "drivers/WipperSnapper_I2C_Driver_PCT2075.h"
3839
#include "drivers/WipperSnapper_I2C_Driver_PM25.h"
3940
#include "drivers/WipperSnapper_I2C_Driver_SCD30.h"
@@ -108,6 +109,7 @@ class WipperSnapper_Component_I2C {
108109
WipperSnapper_I2C_Driver_HTS221 *_hts221 = nullptr;
109110
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
110111
WipperSnapper_I2C_Driver_MPL115A2 *_mpl115a2 = nullptr;
112+
WipperSnapper_I2C_Driver_MS8607 *_ms8607 = nullptr;
111113
WipperSnapper_I2C_Driver_TMP117 *_tmp117 = nullptr;
112114
WipperSnapper_I2C_Driver_TSL2591 *_tsl2591 = nullptr;
113115
WipperSnapper_I2C_Driver_VEML7700 *_veml7700 = nullptr;
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_MS8607.h
3+
*
4+
* Device driver for an AHT Humidity and Temperature sensor.
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_MS8607_H
17+
#define WipperSnapper_I2C_Driver_MS8607_H
18+
19+
#include "WipperSnapper_I2C_Driver.h"
20+
#include <Adafruit_MS8607.h>
21+
22+
/**************************************************************************/
23+
/*!
24+
@brief Class that provides a sensor driver for the MS8607 PHT sensor.
25+
*/
26+
/**************************************************************************/
27+
class WipperSnapper_I2C_Driver_MS8607 : public WipperSnapper_I2C_Driver {
28+
29+
public:
30+
/*******************************************************************************/
31+
/*!
32+
@brief Constructor for an MS8607 sensor.
33+
@param i2c
34+
The I2C interface.
35+
@param sensorAddress
36+
7-bit device address.
37+
*/
38+
/*******************************************************************************/
39+
WipperSnapper_I2C_Driver_MS8607(TwoWire *i2c, uint16_t sensorAddress)
40+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
41+
_i2c = i2c;
42+
_sensorAddress = sensorAddress;
43+
}
44+
45+
/*******************************************************************************/
46+
/*!
47+
@brief Destructor for an MS8607 sensor.
48+
*/
49+
/*******************************************************************************/
50+
~WipperSnapper_I2C_Driver_MS8607() { delete _ms8607; }
51+
52+
/*******************************************************************************/
53+
/*!
54+
@brief Initializes the MS8607 sensor and begins I2C.
55+
@returns True if initialized successfully, False otherwise.
56+
*/
57+
/*******************************************************************************/
58+
bool begin() {
59+
_ms8607 = new Adafruit_MS8607();
60+
// attempt to initialize MS8607
61+
if (!_ms8607->begin(_i2c))
62+
return false;
63+
64+
_ms8607_temp = _ms8607->getTemperatureSensor();
65+
_ms8607_humidity = _ms8607->getHumiditySensor();
66+
_ms8607_pressure = _ms8607->getPressureSensor();
67+
return true;
68+
}
69+
70+
/*******************************************************************************/
71+
/*!
72+
@brief Gets the MS8607's current temperature.
73+
@param tempEvent
74+
Pointer to an Adafruit_Sensor event.
75+
@returns True if the temperature was obtained successfully, False
76+
otherwise.
77+
*/
78+
/*******************************************************************************/
79+
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
80+
if (_ms8607_temp == NULL)
81+
return false;
82+
_ms8607_temp->getEvent(tempEvent);
83+
return true;
84+
}
85+
86+
/*******************************************************************************/
87+
/*!
88+
@brief Gets the MS8607's current relative humidity reading.
89+
@param humidEvent
90+
Pointer to an Adafruit_Sensor event.
91+
@returns True if the humidity was obtained successfully, False
92+
otherwise.
93+
*/
94+
/*******************************************************************************/
95+
bool getEventRelativeHumidity(sensors_event_t *humidEvent) {
96+
if (_ms8607_humidity == NULL)
97+
return false;
98+
_ms8607_humidity->getEvent(humidEvent);
99+
return true;
100+
}
101+
102+
/*******************************************************************************/
103+
/*!
104+
@brief Reads a pressure sensor and converts
105+
the reading into the expected SI unit.
106+
@param pressureEvent
107+
Pointer to an Adafruit_Sensor event.
108+
@returns True if the sensor event was obtained successfully, False
109+
otherwise.
110+
*/
111+
/*******************************************************************************/
112+
bool getEventPressure(sensors_event_t *pressureEvent) {
113+
if (_ms8607_pressure == NULL)
114+
return false;
115+
_ms8607_pressure->getEvent(pressureEvent);
116+
return true;
117+
}
118+
119+
protected:
120+
Adafruit_MS8607 *_ms8607; ///< MS8607 object
121+
Adafruit_Sensor *_ms8607_temp =
122+
NULL; ///< Ptr to an adafruit_sensor representing the temperature
123+
Adafruit_Sensor *_ms8607_pressure =
124+
NULL; ///< Ptr to an adafruit_sensor representing the pressure
125+
Adafruit_Sensor *_ms8607_humidity =
126+
NULL; ///< Ptr to an adafruit_sensor representing the humidity
127+
};
128+
129+
#endif // WipperSnapper_I2C_Driver_MS8607

0 commit comments

Comments
 (0)