Go Down

Topic: RE: issues with I2c sensors MAX30100 and MLX96014 and MKR1000 (Read 52 times) previous topic - next topic

rlively

Hi All,
I am trying to incorporate a MLX96014 infrared temp sensor and MAX30100 pulse oximeter into a project using the arduino MKR1000. I want to take the readings from the sensors and display them on my phone using the blynk app both sets of test sketches for each sensor works perfect individually, but wen i try to incorporate them into the same sketch i am only getting a reading from the temp sensor. I have exhausted all avenues and would appreciate any guidance as the online information is limited. code attached and pasted any help would be greatlyappreciated

Code: [Select]


#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <Adafruit_MLX90614.h>
#define REPORTING_PERIOD_MS 1000


//////////////////////////////////////////////////// 

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
 
double temp_amb;
double temp_obj;
double calibration = 2.36;

////////////////////////////////////////////////////

PulseOximeter pox; 
float BPM, SpO2;
uint32_t tsLastReport = 0;


void onBeatDetected()
{
    Serial.println("Beat Detected!");
}

void setup()
{
    Serial.begin(115200);
    
    pinMode(1, OUTPUT);
  
    Serial.print("Initializing Pulse Oximeter..");
 
    if (!pox.begin())
    {
         Serial.println("FAILED");
         for(;;);
    }
    else
    {
         Serial.println("SUCCESS");
         pox.setOnBeatDetectedCallback(onBeatDetected);
    }
 
    // The default current for the IR LED is 50mA and it could be changed by uncommenting the following line.
        pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
     
    
     mlx.begin();         //Initialize MLX90614
     delay(2000);
     Serial.println("Temperature Sensor MLX90614");
     
 
}
 
void loop()
{
   
    
    pox.update();
    
    //Blynk.run();
    
    BPM = pox.getHeartRate();
    SpO2 = pox.getSpO2();
    if (millis() - tsLastReport > REPORTING_PERIOD_MS)
    {
       
        Serial.print("\nHeart rate:");
        Serial.print(BPM);
        Serial.print("\nSpO2:");
        Serial.print(SpO2);
        Serial.println(" %");

        tsLastReport = millis();
    }
    
    
    temp_amb = mlx.readAmbientTempC();
    temp_obj = mlx.readObjectTempC();
    
    delay(2000);
   
    Serial.print("\nRoom Temp = ");
    Serial.println(temp_amb);
    Serial.print("Object temp = ");
    Serial.println(temp_obj);
      
}



KASSIMSAMJI


get rid of this stupid  delay(2000); from main loop,


pox.update(); needs to execute as fast as possible and you blocked it with delay()

use millis() to do prints

MAX30100 has some design flaws and the issue is well addressed here

https://how2electronics.com/interfacing-max30100-pulse-oximeter-sensor-arduino/

you might want to fix the issue so as to get reliable results out of the module
Electrical Engineer

rlively

Hi, thanks for your fast response,
i have removed the delay from the loop where do you suggest i insert  millis()in the code, 
also the link you sent if my MAX30100 sensor is working within its test code should i have to add resistors when its combined with the MLX90614? 

rlively

I tried to add another millis() function for the MLX96014 temp sensor the code is below and both sensors are now giving output to the serial monitor my code is attached. 

do you think i am implementing the millis function correctly for this situation?

Code: [Select]

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <Adafruit_MLX90614.h>
#define REPORTING_PERIOD_MS 1000
#define temp_period 10000

//////////////////////////////////////////////////// 

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
 
double temp_amb;
double temp_obj;
double calibration = 2.36;

////////////////////////////////////////////////////

PulseOximeter pox; 
float BPM, SpO2;
uint32_t tsLastReport = 0;
uint32_t tempReport = 0;

/////////////////////////////////////////////////////

void onBeatDetected()
{
    Serial.println("Beat Detected!");
}

/////////////////////////////////////////////////////////

void setup()
{
    Serial.begin(115200);
    
    pinMode(1, OUTPUT);
  
    Serial.print("Initializing Pulse Oximeter..");
 
    if (!pox.begin())
    {
         Serial.println("FAILED");
         for(;;);
    }
    else
    {
         Serial.println("SUCCESS");
         pox.setOnBeatDetectedCallback(onBeatDetected);
    }
 
    // The default current for the IR LED is 50mA and it could be changed by uncommenting the following line.
        pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);     
    
     mlx.begin();         //Initialize MLX90614
     Serial.println("Temperature Sensor MLX90614");     
}

//////////////////////////////////////////////////////////////// 

void loop()
{
  pox.update();
    
  //Blynk.run();
    
    BPM = pox.getHeartRate();
    SpO2 = pox.getSpO2();
    if (millis() - tsLastReport > REPORTING_PERIOD_MS)
    {
       
        Serial.print("\nHeart rate:");
        Serial.print(BPM);
        Serial.print("\nSpO2:");
        Serial.print(SpO2);
        Serial.println(" %");

        tsLastReport = millis();
    }
    if (millis() - tempReport > temp_period)
    {
    
    temp_amb = mlx.readAmbientTempC();
    temp_obj = mlx.readObjectTempC();
    
    Serial.print("\nRoom Temp = ");
    Serial.println(temp_amb);
    Serial.print("Object temp = ");
    Serial.println(temp_obj);

    tempReport = millis();  
}
}

  

 

Go Up