-
Notifications
You must be signed in to change notification settings - Fork 54
Omron D6T thermal IR sensor (I2C) #769
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b35c2c2
Add OMRON D6T thermal sensor
tyeth 4e9d959
D6T: Swap to single read for both metrics
tyeth cfdbfd6
clang-format
tyeth 172646a
Correct D6T model name and privates usage
tyeth 275bede
D6T: Floats and Model name swap
tyeth f7c094c
D6T: specify cell/pixel for temp reading
tyeth 44024f6
Add missing private pointer for D6T-1A
tyeth b047125
8MB partitions for 8MB boards
tyeth 999bd73
Merge remote-tracking branch 'upstream/main' into omron-D6T
tyeth fe32ce6
clang format
tyeth 1c50e12
D6T-1A: Move initialisation values to constructor
tyeth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
139 changes: 139 additions & 0 deletions
139
src/components/i2c/drivers/WipperSnapper_I2C_Driver_D6T1A.h
This file contains hidden or 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,139 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_D6T1A.h | ||
* | ||
* Device driver for a D6T1A thermal 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) Tyeth Gundry 2025 for Adafruit Industries. | ||
* | ||
* MIT license, all text here must be included in any redistribution. | ||
* | ||
*/ | ||
|
||
#ifndef WipperSnapper_I2C_Driver_D6T1A_H | ||
#define WipperSnapper_I2C_Driver_D6T1A_H | ||
|
||
#include <OmronD6T.h> | ||
|
||
#include "WipperSnapper_I2C_Driver.h" | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that provides a sensor driver for the D6T1A temperature | ||
and pressure sensor. | ||
*/ | ||
/**************************************************************************/ | ||
class WipperSnapper_I2C_Driver_D6T1A : public WipperSnapper_I2C_Driver { | ||
public: | ||
/*******************************************************************************/ | ||
/*! | ||
@brief Constructor for an D6T1A sensor. | ||
@param i2c | ||
The I2C interface. | ||
@param sensorAddress | ||
7-bit device address. | ||
*/ | ||
/*******************************************************************************/ | ||
WipperSnapper_I2C_Driver_D6T1A(TwoWire *i2c, uint16_t sensorAddress) | ||
: WipperSnapper_I2C_Driver(i2c, sensorAddress) { | ||
_i2c = i2c; | ||
_sensorAddress = sensorAddress; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Destructor for an D6T1A sensor. | ||
*/ | ||
/*******************************************************************************/ | ||
~WipperSnapper_I2C_Driver_D6T1A() { delete _d6t1a; } | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Initializes the D6T1A sensor and begins I2C. | ||
@returns True if initialized successfully, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool begin() { | ||
_d6t1a = new OmronD6T(OmronD6T::D6T_1A, _i2c); | ||
// attempt to initialize D6T1A | ||
if (!_d6t1a->begin(_sensorAddress)) | ||
return false; | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Checks if sensor was read within last 1s, or is the first read. | ||
@returns True if the sensor was recently read, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool HasBeenReadInLast200ms() { | ||
return _lastRead != 0 && millis() - _lastRead < 200; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Reads the sensor. | ||
@returns True if the sensor was read successfully, False otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool ReadSensorData() { | ||
// dont read sensor more than once per 200ms | ||
if (HasBeenReadInLast200ms()) { | ||
return true; | ||
} | ||
|
||
_d6t1a->read(); | ||
_deviceTemp = (float)_d6t1a->ambientTempC(); | ||
_objectTemp = (float)_d6t1a->objectTempC(0, 0); | ||
_lastRead = millis(); | ||
return true; | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the D6T1A'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) { | ||
if (ReadSensorData() && _deviceTemp != NAN) { | ||
// if the sensor was read recently, return the cached temperature | ||
tempEvent->temperature = _deviceTemp; | ||
return true; | ||
} | ||
return false; // sensor not read recently, return false | ||
} | ||
|
||
/*******************************************************************************/ | ||
/*! | ||
@brief Gets the D6T1A's object temperature. | ||
@param tempEvent | ||
Pointer to an Adafruit_Sensor event. | ||
@returns True if the temperature was obtained successfully, False | ||
otherwise. | ||
*/ | ||
/*******************************************************************************/ | ||
bool getEventObjectTemp(sensors_event_t *tempEvent) { | ||
if (ReadSensorData() && _objectTemp != NAN) { | ||
// if the sensor was read recently, return the cached temperature | ||
tempEvent->temperature = _objectTemp; | ||
return true; | ||
} | ||
return false; // sensor not read recently, return false | ||
} | ||
|
||
protected: | ||
float _deviceTemp = NAN; ///< Device temperature in Celsius | ||
float _objectTemp = NAN; ///< Object temperature in Celsius | ||
uint32_t _lastRead = 0; ///< Last time the sensor was read in milliseconds | ||
OmronD6T *_d6t1a = nullptr; ///< D6T1A object | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_D6T1A |
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.
Uh oh!
There was an error while loading. Please reload this page.