Skip to content

Commit 3e4a9d7

Browse files
committed
Change how we readTemperature(). Updated Temp Sense example.
Fix for issue 19.
1 parent 1fff93a commit 3e4a9d7

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

examples/Example3_Temperature_Sense/Example3_Temperature_Sense.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@
1919
*/
2020

2121
#include <Wire.h>
22-
#include "MAX30105.h"
23-
24-
#include "heartRate.h"
2522

23+
#include "MAX30105.h" //Get it here: http://librarymanager/All#SparkFun_MAX30105
2624
MAX30105 particleSensor;
2725

2826
void setup()
2927
{
30-
Serial.begin(115200);
28+
Serial.begin(9600);
3129
Serial.println("Initializing...");
3230

3331
// Initialize sensor
34-
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
32+
if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false) //Use default I2C port, 400kHz speed
3533
{
3634
Serial.println("MAX30105 was not found. Please check wiring/power. ");
3735
while (1);
@@ -41,6 +39,8 @@ void setup()
4139
//you may want to turn off the LEDs to avoid any local heating
4240
particleSensor.setup(0); //Configure sensor. Turn off LEDs
4341
//particleSensor.setup(); //Configure sensor. Use 25mA for LED drive
42+
43+
particleSensor.enableDIETEMPRDY(); //Enable the temp ready interrupt. This is required.
4444
}
4545

4646
void loop()

src/MAX30105.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ boolean MAX30105::begin(TwoWire &wirePort, uint32_t i2cSpeed, uint8_t i2caddr) {
158158

159159
// Populate revision ID
160160
readRevisionID();
161-
161+
162162
return true;
163163
}
164164

@@ -364,6 +364,10 @@ uint8_t MAX30105::getReadPointer(void) {
364364
// Die Temperature
365365
// Returns temp in C
366366
float MAX30105::readTemperature() {
367+
368+
//DIE_TEMP_RDY interrupt must be enabled
369+
//See issue 19: https://github.com/sparkfun/SparkFun_MAX3010x_Sensor_Library/issues/19
370+
367371
// Step 1: Config die temperature register to take 1 temperature sample
368372
writeRegister8(_i2caddr, MAX30105_DIETEMPCONFIG, 0x01);
369373

@@ -372,16 +376,20 @@ float MAX30105::readTemperature() {
372376
unsigned long startTime = millis();
373377
while (millis() - startTime < 100)
374378
{
375-
uint8_t response = readRegister8(_i2caddr, MAX30105_DIETEMPCONFIG);
376-
if ((response & 0x01) == 0) break; //We're done!
379+
//uint8_t response = readRegister8(_i2caddr, MAX30105_DIETEMPCONFIG); //Original way
380+
//if ((response & 0x01) == 0) break; //We're done!
381+
382+
//Check to see if DIE_TEMP_RDY interrupt is set
383+
uint8_t response = readRegister8(_i2caddr, MAX30105_INTSTAT2);
384+
if ((response & MAX30105_INT_DIE_TEMP_RDY_ENABLE) > 0) break; //We're done!
377385
delay(1); //Let's not over burden the I2C bus
378386
}
379387
//TODO How do we want to fail? With what type of error?
380388
//? if(millis() - startTime >= 100) return(-999.0);
381389

382390
// Step 2: Read die temperature register (integer)
383391
int8_t tempInt = readRegister8(_i2caddr, MAX30105_DIETEMPINT);
384-
uint8_t tempFrac = readRegister8(_i2caddr, MAX30105_DIETEMPFRAC);
392+
uint8_t tempFrac = readRegister8(_i2caddr, MAX30105_DIETEMPFRAC); //Causes the clearing of the DIE_TEMP_RDY interrupt
385393

386394
// Step 3: Calculate temperature (datasheet pg. 23)
387395
return (float)tempInt + ((float)tempFrac * 0.0625);

0 commit comments

Comments
 (0)