-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from brentru/add-mcp9601
Add MCP9601 Sensor
- Loading branch information
Showing
7 changed files
with
276 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
name=Adafruit WipperSnapper Beta | ||
version=1.0.0-beta.25 | ||
version=1.0.0-beta.27 | ||
author=Adafruit | ||
maintainer=Adafruit <[email protected]> | ||
sentence=Arduino client for Adafruit.io WipperSnapper | ||
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, Sensirion I2C SCD4x, Adafruit MCP9808 Library | ||
depends=Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit SleepyDog Library, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit DPS310, Adafruit SCD30, Sensirion I2C SCD4x, Adafruit MCP9808 Library, Adafruit MCP9600 Library |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
src/components/i2c/drivers/WipperSnapper_I2C_Driver_MCP9601.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_MCP9601.h | ||
* | ||
* Device driver for the MCP9601 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) Brent Rubell 2022 for Adafruit Industries. | ||
* | ||
* MIT license, all text here must be included in any redistribution. | ||
* | ||
*/ | ||
#ifndef WipperSnapper_I2C_Driver_MCP9601_H | ||
#define WipperSnapper_I2C_Driver_MCP9601_H | ||
|
||
#include "WipperSnapper_I2C_Driver.h" | ||
#include <Adafruit_MCP9601.h> | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that provides a driver interface for a MCP9601 sensor. | ||
*/ | ||
/**************************************************************************/ | ||
class WipperSnapper_I2C_Driver_MCP9601 : public WipperSnapper_I2C_Driver { | ||
public: | ||
/*******************************************************************************/ | ||
/*! | ||
@brief Constructor for a MCP9601 sensor. | ||
@param i2c | ||
The I2C interface. | ||
@param sensorAddress | ||
The 7-bit I2C address of the sensor. | ||
*/ | ||
/*******************************************************************************/ | ||
WipperSnapper_I2C_Driver_MCP9601(TwoWire *i2c, uint16_t sensorAddress) | ||
: WipperSnapper_I2C_Driver(i2c, sensorAddress) { | ||
_i2c = i2c; | ||
_sensorAddress = sensorAddress; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Destructor for an MCP9601 sensor. | ||
*/ | ||
/*******************************************************************************/ | ||
~WipperSnapper_I2C_Driver_MCP9601() { | ||
// Called when a MCP9601 component is deleted. | ||
delete _MCP9601; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Initializes the MCP9601 sensor and begins I2C. | ||
@returns True if initialized successfully, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool begin() { | ||
_MCP9601 = new Adafruit_MCP9601(); | ||
if (!_MCP9601->begin((uint8_t)_sensorAddress)) | ||
return false; | ||
|
||
// Configure MCP9601's settings | ||
// Set resolution | ||
_MCP9601->setADCresolution(MCP9600_ADCRESOLUTION_18); | ||
// Set thermocouple type (NOTE: We do not have advanced settings in WS, set | ||
// to 'K'-type for now) | ||
_MCP9601->setThermocoupleType(MCP9600_TYPE_K); | ||
// Set filter coefficient | ||
_MCP9601->setFilterCoefficient(3); | ||
// Enable sensor | ||
_MCP9601->enable(true); | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the MCP9601's current temperature. | ||
@param tempEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the temperature was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventAmbientTemperature(sensors_event_t *tempEvent) { | ||
uint8_t status = _MCP9601->getStatus(); | ||
if (status & MCP9601_STATUS_OPENCIRCUIT) { | ||
return false; // don't continue, since there's no thermocouple | ||
} | ||
if (status & MCP9601_STATUS_SHORTCIRCUIT) { | ||
return false; // don't continue, since the sensor is not working | ||
} | ||
|
||
tempEvent->temperature = _MCP9601->readAmbient(); | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the MCP9601's current object temperature (thermocouple). | ||
@param objectTempEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the object temperature was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventObjectTemp(sensors_event_t *objectTempEvent) { | ||
uint8_t status = _MCP9601->getStatus(); | ||
if (status & MCP9601_STATUS_OPENCIRCUIT) { | ||
return false; // don't continue, since there's no thermocouple | ||
} | ||
if (status & MCP9601_STATUS_SHORTCIRCUIT) { | ||
return false; // don't continue, since the sensor is not working | ||
} | ||
|
||
objectTempEvent->temperature = _MCP9601->readThermocouple(); | ||
return true; | ||
} | ||
|
||
protected: | ||
Adafruit_MCP9601 *_MCP9601; ///< Pointer to MCP9601 temperature sensor object | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_MCP9601 |