Skip to content

Commit 19d7984

Browse files
authored
Merge pull request #799 from adafruit/mlx90632
Mlx90632
2 parents e06ebab + 71b8dd4 commit 19d7984

File tree

6 files changed

+276
-12
lines changed

6 files changed

+276
-12
lines changed

library.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
name=Adafruit WipperSnapper
2-
version=1.0.0-beta.110
2+
version=1.0.0-beta.111
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Arduino application for Adafruit.io WipperSnapper
66
paragraph=Arduino application for Adafruit.io WipperSnapper
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_Wippersnapper_Arduino
99
architectures=*
10-
depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306
10+
depends=OmronD6T - Community Fork, SdFat - Adafruit Fork, Adafruit NeoPixel, Adafruit SPIFlash, ArduinoJson, Adafruit DotStar, Adafruit HDC302x, Adafruit INA219, Adafruit INA260 Library, Adafruit INA237 and INA238 Library, Adafruit LTR329 and LTR303, Adafruit LTR390 Library, Adafruit MCP3421, Adafruit MLX90632 Library, Adafruit NAU7802 Library, Adafruit SleepyDog Library, Adafruit TMP117, Adafruit TinyUSB Library, Adafruit AHTX0, Adafruit BME280 Library, Adafruit BMP280 Library, Adafruit BMP3XX Library, Adafruit DPS310, Adafruit DS248x, Adafruit SCD30, Adafruit SGP30 Sensor, Adafruit SGP40 Sensor, Sensirion I2C SCD4x, Sensirion I2C SEN5X, Sensirion I2C SEN66, arduino-sht, Adafruit Si7021 Library, Adafruit MQTT Library, Adafruit MS8607, Adafruit MCP9808 Library, Adafruit MCP9600 Library, Adafruit MPL115A2, Adafruit MPRLS Library, Adafruit TSL2591 Library, Adafruit_VL53L0X, Adafruit VL53L1X, STM32duino VL53L4CD, STM32duino VL53L4CX, Adafruit_VL6180X, Adafruit PM25 AQI Sensor, Adafruit VCNL4020 Library, Adafruit VCNL4040, Adafruit VCNL4200 Library, Adafruit VEML7700 Library, Adafruit LC709203F, Adafruit LPS2X, Adafruit LPS28, Adafruit LPS35HW, Adafruit seesaw Library, Adafruit BME680 Library, Adafruit MAX1704X, Adafruit ADT7410 Library, Adafruit HTS221, Adafruit HTU21DF Library, Adafruit HTU31D Library, Adafruit PCT2075, hp_BH1750, ENS160 - Adafruit Fork, Adafruit BusIO, Adafruit Unified Sensor, Sensirion Core, Adafruit GFX Library, Adafruit LED Backpack Library, Adafruit LiquidCrystal, Adafruit SH110X, Adafruit SSD1306

platformio.ini

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ lib_deps =
5757
adafruit/Adafruit MCP3421
5858
adafruit/Adafruit MCP9808 Library
5959
adafruit/Adafruit MCP9600 Library
60+
adafruit/Adafruit MLX90632 Library
6061
adafruit/Adafruit MPL115A2
6162
adafruit/Adafruit MPRLS Library
6263
adafruit/Adafruit MS8607
@@ -203,23 +204,23 @@ board_build.partitions = min_spiffs.csv
203204
extends = common:esp32
204205
board = featheresp32-s2
205206
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S2 -DBOARD_HAS_PSRAM
206-
board_build.partitions = tinyuf2-partitions-4MB.csv
207+
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
207208
extra_scripts = pre:rename_usb_config.py
208209

209210
; Adafruit Feather ESP32-S2 TFT
210211
[env:adafruit_feather_esp32s2_tft]
211212
extends = common:esp32
212213
board = adafruit_feather_esp32s2_tft
213214
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S2_TFT -DBOARD_HAS_PSRAM
214-
board_build.partitions = tinyuf2-partitions-4MB.csv
215+
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
215216
extra_scripts = pre:rename_usb_config.py
216217

217218
; Adafruit Feather ESP32-S2 Reverse TFT
218219
[env:adafruit_feather_esp32s2_reversetft]
219220
extends = common:esp32
220221
board = adafruit_feather_esp32s2_reversetft
221222
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S2_REVTFT -DBOARD_HAS_PSRAM
222-
board_build.partitions = tinyuf2-partitions-4MB.csv
223+
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
223224
extra_scripts = pre:rename_usb_config.py
224225

225226
; Adafruit Feather ESP32-S3 2MB PSRAM
@@ -228,7 +229,7 @@ extends = common:esp32
228229
board = adafruit_feather_esp32s3
229230
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3 -DBOARD_HAS_PSRAM
230231
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
231-
board_build.partitions = tinyuf2-partitions-4MB.csv
232+
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
232233
extra_scripts = pre:rename_usb_config.py
233234

234235
; Adafruit Feather ESP32-S3 NO PSRAM
@@ -247,7 +248,7 @@ debug_tool = esp-builtin
247248
board = adafruit_feather_esp32s3_tft
248249
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3_TFT -DBOARD_HAS_PSRAM
249250
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
250-
board_build.partitions = tinyuf2-partitions-4MB.csv
251+
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
251252
extra_scripts = pre:rename_usb_config.py
252253

253254
; Adafruit Feather ESP32-S3 Reverse TFT
@@ -256,7 +257,7 @@ extends = common:esp32
256257
board = adafruit_feather_esp32s3_reversetft
257258
build_flags = -DARDUINO_ADAFRUIT_FEATHER_ESP32S3_REVTFT -DBOARD_HAS_PSRAM
258259
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
259-
board_build.partitions = tinyuf2-partitions-4MB.csv
260+
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
260261
extra_scripts = pre:rename_usb_config.py
261262

262263
; Adafruit Magtag ESP32-S2
@@ -265,7 +266,7 @@ extends = common:esp32
265266
board = adafruit_magtag29_esp32s2
266267
build_flags = -DARDUINO_MAGTAG29_ESP32S2 -DBOARD_HAS_PSRAM
267268
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
268-
board_build.partitions = tinyuf2-partitions-4MB.csv
269+
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
269270
extra_scripts = pre:rename_usb_config.py
270271

271272
; Adafruit Metro ESP32-S2
@@ -274,7 +275,7 @@ extends = common:esp32
274275
board = adafruit_metro_esp32s2
275276
build_flags = -DARDUINO_METRO_ESP32S2 -DBOARD_HAS_PSRAM
276277
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
277-
board_build.partitions = tinyuf2-partitions-4MB.csv
278+
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
278279
extra_scripts = pre:rename_usb_config.py
279280

280281
; Adafruit Metro ESP32-S3
@@ -363,7 +364,7 @@ extends = common:esp32
363364
board = adafruit_qtpy_esp32s2
364365
build_flags = -DARDUINO_ADAFRUIT_QTPY_ESP32S2 -DBOARD_HAS_PSRAM
365366
;set partition to tinyuf2-partitions-4MB.csv as of idf 5.1
366-
board_build.partitions = tinyuf2-partitions-4MB.csv
367+
board_build.partitions = tinyuf2-partitions-4MB-noota.csv
367368
extra_scripts = pre:rename_usb_config.py
368369

369370
; Adafruit QT Py ESP32-S3 NO PSRAM

src/Wippersnapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@
142142
#endif
143143

144144
#define WS_VERSION \
145-
"1.0.0-beta.110" ///< WipperSnapper app. version (semver-formatted)
145+
"1.0.0-beta.111" ///< WipperSnapper app. version (semver-formatted)
146146

147147
// Reserved Adafruit IO MQTT topics
148148
#define TOPIC_IO_THROTTLE "/throttle" ///< Adafruit IO Throttle MQTT Topic

src/components/i2c/WipperSnapper_I2C.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,33 @@ bool WipperSnapper_Component_I2C::initI2CDevice(
537537
_mcp9808->configureDriver(msgDeviceInitReq);
538538
drivers.push_back(_mcp9808);
539539
WS_DEBUG_PRINTLN("MCP9808 Initialized Successfully!");
540+
} else if (strcmp("mlx90632b", msgDeviceInitReq->i2c_device_name) == 0 ||
541+
strcmp("mlx90632d_med", msgDeviceInitReq->i2c_device_name) == 0) {
542+
_mlx90632d = new WipperSnapper_I2C_Driver_MLX90632D(this->_i2c, i2cAddress);
543+
if (!_mlx90632d->begin()) {
544+
WS_DEBUG_PRINTLN("ERROR: Failed to initialize MLX90632!");
545+
_busStatusResponse =
546+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
547+
return false;
548+
}
549+
_mlx90632d->configureDriver(msgDeviceInitReq);
550+
drivers.push_back(_mlx90632d);
551+
WS_DEBUG_PRINTLN("MLX90632 Initialized Successfully!");
552+
} else if (strcmp("mlx90632d_ext", msgDeviceInitReq->i2c_device_name) == 0) {
553+
_mlx90632d_ext =
554+
new WipperSnapper_I2C_Driver_MLX90632D(this->_i2c, i2cAddress);
555+
// set extended range
556+
if (!_mlx90632d_ext->begin() ||
557+
!_mlx90632d_ext->ConfigureAndPrintSensorInfo(true)) {
558+
WS_DEBUG_PRINTLN(
559+
"ERROR: Failed to initialize MLX90632D with extended range!");
560+
_busStatusResponse =
561+
wippersnapper_i2c_v1_BusResponse_BUS_RESPONSE_DEVICE_INIT_FAIL;
562+
return false;
563+
}
564+
_mlx90632d_ext->configureDriver(msgDeviceInitReq);
565+
drivers.push_back(_mlx90632d_ext);
566+
WS_DEBUG_PRINTLN("MLX90632D_EXT Initialized Successfully!");
540567
} else if (strcmp("mpl115a2", msgDeviceInitReq->i2c_device_name) == 0) {
541568
_mpl115a2 = new WipperSnapper_I2C_Driver_MPL115A2(this->_i2c, i2cAddress);
542569
if (!_mpl115a2->begin()) {

src/components/i2c/WipperSnapper_I2C.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "drivers/WipperSnapper_I2C_Driver_MAX17048.h"
5151
#include "drivers/WipperSnapper_I2C_Driver_MCP3421.h"
5252
#include "drivers/WipperSnapper_I2C_Driver_MCP9808.h"
53+
#include "drivers/WipperSnapper_I2C_Driver_MLX90632D.h"
5354
#include "drivers/WipperSnapper_I2C_Driver_MPL115A2.h"
5455
#include "drivers/WipperSnapper_I2C_Driver_MPRLS.h"
5556
#include "drivers/WipperSnapper_I2C_Driver_MS8607.h"
@@ -180,6 +181,8 @@ class WipperSnapper_Component_I2C {
180181
WipperSnapper_I2C_Driver_LTR390 *_ltr390 = nullptr;
181182
WipperSnapper_I2C_Driver_MCP3421 *_mcp3421 = nullptr;
182183
WipperSnapper_I2C_Driver_MCP9808 *_mcp9808 = nullptr;
184+
WipperSnapper_I2C_Driver_MLX90632D *_mlx90632d = nullptr;
185+
WipperSnapper_I2C_Driver_MLX90632D *_mlx90632d_ext = nullptr;
183186
WipperSnapper_I2C_Driver_MPL115A2 *_mpl115a2 = nullptr;
184187
WipperSnapper_I2C_Driver_MPRLS *_mprls = nullptr;
185188
WipperSnapper_I2C_Driver_MS8607 *_ms8607 = nullptr;
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
/*!
2+
* @file WipperSnapper_I2C_Driver_MLX90632D.h
3+
*
4+
* Device driver for a Melexis MLX90632-D (medical) thermal FIR 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 2025 for Adafruit Industries.
11+
*
12+
* MIT license, all text here must be included in any redistribution.
13+
*
14+
*/
15+
16+
#ifndef WipperSnapper_I2C_Driver_MLX90632D_H
17+
#define WipperSnapper_I2C_Driver_MLX90632D_H
18+
19+
#include <Adafruit_MLX90632.h>
20+
21+
#include "WipperSnapper_I2C_Driver.h"
22+
23+
/**************************************************************************/
24+
/*!
25+
@brief Sensor driver for the Melexis MLX90632-D temperature sensor.
26+
*/
27+
/**************************************************************************/
28+
class WipperSnapper_I2C_Driver_MLX90632D : public WipperSnapper_I2C_Driver {
29+
public:
30+
/*******************************************************************************/
31+
/*!
32+
@brief Constructor for an MLX90632 sensor.
33+
@param i2c
34+
The I2C interface.
35+
@param sensorAddress
36+
7-bit device address.
37+
*/
38+
/*******************************************************************************/
39+
WipperSnapper_I2C_Driver_MLX90632D(TwoWire *i2c, uint16_t sensorAddress)
40+
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {
41+
_i2c = i2c;
42+
_sensorAddress = sensorAddress;
43+
_mlx90632 = nullptr;
44+
_deviceTemp = NAN;
45+
_objectTemp = NAN;
46+
_lastRead = 0;
47+
}
48+
49+
/*******************************************************************************/
50+
/*!
51+
@brief Destructor for an MLX90632 sensor.
52+
*/
53+
/*******************************************************************************/
54+
~WipperSnapper_I2C_Driver_MLX90632D() {
55+
if (_mlx90632) {
56+
delete _mlx90632;
57+
_mlx90632 = nullptr;
58+
}
59+
}
60+
61+
/*******************************************************************************/
62+
/*!
63+
@brief Initializes the MLX90632 sensor and begins I2C.
64+
@returns True if initialized successfully, False otherwise.
65+
*/
66+
/*******************************************************************************/
67+
bool begin() {
68+
if (_mlx90632) {
69+
delete _mlx90632;
70+
_mlx90632 = nullptr;
71+
}
72+
_mlx90632 = new Adafruit_MLX90632();
73+
// attempt to initialize MLX90632
74+
if (!_mlx90632->begin(_sensorAddress, _i2c))
75+
return false;
76+
77+
return ConfigureAndPrintSensorInfo();
78+
}
79+
80+
/*******************************************************************************/
81+
/*!
82+
@brief Configures the MLX90632 sensor and prints its information.
83+
@param extendedInsteadOfMedicalRange
84+
If true, configures the sensor for extended temperature
85+
range/acc.
86+
@returns True if configuration fetching and setting were successful.
87+
*/
88+
/*******************************************************************************/
89+
bool ConfigureAndPrintSensorInfo(bool extendedInsteadOfMedicalRange = false) {
90+
// Reset the device
91+
if (!_mlx90632->reset()) {
92+
WS_DEBUG_PRINTLN(F("Device reset failed"));
93+
return false;
94+
}
95+
96+
uint16_t productCode = _mlx90632->getProductCode();
97+
// Decode product code bits
98+
uint8_t fov = (productCode >> 8) & 0x3;
99+
uint8_t package = (productCode >> 5) & 0x7;
100+
uint8_t accuracy = productCode & 0x1F;
101+
102+
if (!_mlx90632->setMode(MLX90632_MODE_CONTINUOUS)) {
103+
WS_DEBUG_PRINTLN(F("Failed to set mode"));
104+
return false;
105+
}
106+
107+
// set accuracy mode based on medical if detected
108+
if (accuracy == 1) {
109+
// Set and get measurement select (medical)
110+
if (!extendedInsteadOfMedicalRange &&
111+
!_mlx90632->setMeasurementSelect(MLX90632_MEAS_MEDICAL)) {
112+
WS_DEBUG_PRINTLN(F("Failed to set measurement select to Medical"));
113+
return false;
114+
} else if (extendedInsteadOfMedicalRange &&
115+
!_mlx90632->setMeasurementSelect(
116+
MLX90632_MEAS_EXTENDED_RANGE)) {
117+
WS_DEBUG_PRINTLN(
118+
F("Failed to set measurement select to Extended Range"));
119+
return false;
120+
}
121+
}
122+
123+
// Set and get refresh rate (default to 2Hz)
124+
if (!_mlx90632->setRefreshRate(MLX90632_REFRESH_2HZ)) {
125+
WS_DEBUG_PRINTLN(F("Failed to set refresh rate to 2Hz"));
126+
return false;
127+
}
128+
129+
if (!_mlx90632->resetNewData()) {
130+
WS_DEBUG_PRINTLN(F("Failed to reset new data flag"));
131+
return false;
132+
}
133+
return true;
134+
}
135+
136+
/*******************************************************************************/
137+
/*!
138+
@brief Checks if sensor was read within last 1s, or is the first read.
139+
@returns True if the sensor was recently read, False otherwise.
140+
*/
141+
/*******************************************************************************/
142+
bool HasBeenReadInLast200ms() {
143+
return _lastRead != 0 && millis() - _lastRead < 200;
144+
}
145+
146+
/*******************************************************************************/
147+
/*!
148+
@brief Reads the sensor.
149+
@returns True if the sensor was read successfully, False otherwise.
150+
*/
151+
/*******************************************************************************/
152+
bool ReadSensorData() {
153+
bool result = false;
154+
if (HasBeenReadInLast200ms()) {
155+
WS_DEBUG_PRINTLN(F("Sensor was read recently, using cached data"));
156+
return true;
157+
}
158+
159+
// Check if we need to trigger a new measurement for step modes
160+
mlx90632_mode_t currentMode = _mlx90632->getMode();
161+
if (currentMode == MLX90632_MODE_STEP ||
162+
currentMode == MLX90632_MODE_SLEEPING_STEP) {
163+
// Trigger single measurement (SOC bit) for step modes
164+
if (!_mlx90632->startSingleMeasurement()) {
165+
WS_DEBUG_PRINTLN(F("Failed to start single measurement"));
166+
return false;
167+
}
168+
delay(510); // Wait for measurement to complete @ 2Hz
169+
}
170+
171+
// Only check new data flag - much more efficient for continuous mode
172+
if (_mlx90632->isNewData()) {
173+
_deviceTemp = _mlx90632->getAmbientTemperature();
174+
_objectTemp = _mlx90632->getObjectTemperature();
175+
if (isnan(_objectTemp)) {
176+
WS_DEBUG_PRINTLN(F("NaN (invalid cycle position)"));
177+
return false;
178+
}
179+
result = true;
180+
_lastRead = millis();
181+
// Reset new data flag after reading
182+
if (!_mlx90632->resetNewData()) {
183+
WS_DEBUG_PRINTLN(F("Failed to reset new data flag"));
184+
}
185+
} else {
186+
WS_DEBUG_PRINTLN(F("No new data available, skipping read"));
187+
}
188+
189+
return result;
190+
}
191+
192+
/*******************************************************************************/
193+
/*!
194+
@brief Gets the MLX90632's current temperature.
195+
@param tempEvent
196+
Pointer to an Adafruit_Sensor event.
197+
@returns True if the temperature was obtained successfully, False
198+
otherwise.
199+
*/
200+
/*******************************************************************************/
201+
bool getEventAmbientTemp(sensors_event_t *tempEvent) {
202+
if (ReadSensorData() && _deviceTemp != NAN) {
203+
tempEvent->temperature = _deviceTemp;
204+
return true;
205+
}
206+
return false; // sensor not read recently, return false
207+
}
208+
209+
/*******************************************************************************/
210+
/*!
211+
@brief Gets the MLX90632's object temperature.
212+
@param tempEvent
213+
Pointer to an Adafruit_Sensor event.
214+
@returns True if the temperature was obtained successfully, False
215+
otherwise.
216+
*/
217+
/*******************************************************************************/
218+
bool getEventObjectTemp(sensors_event_t *tempEvent) {
219+
if (ReadSensorData() && _objectTemp != NAN) {
220+
tempEvent->temperature = _objectTemp;
221+
return true;
222+
}
223+
return false; // sensor not read recently, return false
224+
}
225+
226+
protected:
227+
double _deviceTemp; ///< Device temperature in Celsius
228+
double _objectTemp; ///< Object temperature in Celsius
229+
uint32_t _lastRead; ///< Last time the sensor was read in milliseconds
230+
Adafruit_MLX90632 *_mlx90632 = nullptr; ///< MLX90632 object
231+
};
232+
233+
#endif // WipperSnapper_I2C_Driver_MLX90632D_H

0 commit comments

Comments
 (0)