-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MCP9601 with K-Type Thermocouple #565
Draft
tyeth
wants to merge
2
commits into
adafruit:main
Choose a base branch
from
tyeth:add-MCP9601
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
111 changes: 111 additions & 0 deletions
111
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,111 @@ | ||
/*! | ||
* @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 | ||
7-bit device address. | ||
*/ | ||
/*******************************************************************************/ | ||
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, _i2c)) { | ||
return false; | ||
} | ||
_MCP9601->setADCresolution(MCP9600_ADCRESOLUTION_18); | ||
_MCP9601->setThermocoupleType(MCP9600_TYPE_K); | ||
_MCP9601->setFilterCoefficient(3); | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the MCP9601's current ambient 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 = _MCP9601->readAmbient(); | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the MCP9601's current thermocouple temperature. | ||
@param rawEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the temperature was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventRaw(sensors_event_t *rawEvent) { | ||
uint8_t status = _MCP9601->getStatus(); | ||
if (status & MCP9601_STATUS_OPENCIRCUIT) { | ||
WS_DEBUG_PRINTLN("Thermocouple open!"); | ||
return false; | ||
} | ||
if (status & MCP9601_STATUS_SHORTCIRCUIT) { | ||
WS_DEBUG_PRINTLN("Thermocouple shorted to ground!"); | ||
return false; | ||
} | ||
rawEvent->data[0] = _MCP9601->readThermocouple(); | ||
return true; | ||
} | ||
|
||
protected: | ||
Adafruit_MCP9601 *_MCP9601; ///< Pointer to MCP9601 temperature sensor object | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_MCP9601 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add your name and current year here