MAX30100 code not matching DS18B20 code

Hi all
I'm working on a project that involves the pulseoximeter MAX30100 and temperature sensor DS18B20. I'm also using an Arduino Nano. However, I can't seem to make the code work for both sensors. I'm using the folloing code:

#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS     1000
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
PulseOximeter pox;

uint32_t tsLastReport = 0;
float Celcius=0;void onBeatDetected()
{
   // Serial.println("Beat!");
}
 
void setup()
{
    Serial.begin(115200);
   // Serial.print("Initializing pulse oximeter..");
       sensors.begin();
    // Initialize the PulseOximeter instance
    // Failures are generally due to an improper I2C wiring, missing power supply
    // or wrong target chip
    if (!pox.begin()) {
        //Serial.println("FAILED");
        for(;;);
    } else {
       // Serial.println("SUCCESS");
    }
     pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
 
    // Register a callback for the beat detection
    pox.setOnBeatDetectedCallback(onBeatDetected);
}
 
void loop()
{
    // Make sure to call update as fast as possible
   pox.update();
   if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
      Serial.print("Heart rate:");
      Serial.print(pox.getHeartRate());
       sensors.requestTemperatures();
        Celcius=sensors.getTempCByIndex(0);
        Serial.print(",");
        Serial.print("bpm / SpO2:");
        Serial.print(pox.getSpO2());
   
        
         Serial.print(Celcius);
         Serial.print("    ");
         tsLastReport = millis();
    }
    }

When I run the code, I get the value 0 from the MAX30100 sensor. When I run the code only for MAX30100 it works just fine.

Thank you!

Hi @useremib

Please post a schematic of your project.
RV mineirin


The pulseoximeter is MAX30100, but not from sparkfun

You have the ds18b20 on pin 2 and one wire on pin 5

Have a look at the Dallas examples

@useremib
In the sketch the Oniwirebus is defined as pin 5, but in the schematic it is connected to pin 2.
RV mineirin

Sorry, there was a mistake in the schematic. The pins are assigned corectly and the problem still persists. I wonder if there's something that doesn't match between the two libraries?


#include <OneWire.h> 
#include <DallasTemperature.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
/********************************************************************/

#define ONE_WIRE_BUS 5
#define REPORTING_PERIOD_MS     1000
PulseOximeter pox;

uint32_t tsLastReport = 0;

OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

void onBeatDetected()
{
    Serial.println("Beat!");
}
void setup(void) 
{
    Serial.begin(115200);

    Serial.print("Initializing pulse oximeter..");
    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }

    pox.setOnBeatDetectedCallback(onBeatDetected);
}
   void pulse(){
      pox.update();
   
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
     //   Serial.print("Heart rate:");
        Serial.print(pox.getHeartRate());
        Serial.print("bpm / SpO2:");
        Serial.print(pox.getSpO2());
        Serial.println("%");

        tsLastReport = millis();
        
    }}
    void temperature(){

 sensors.requestTemperatures(); 
 float tempC = sensors.getTempCByIndex(0);
 Serial.print("Temperature is: "); 
 Serial.print(tempC); // Why "byIndex"?  
 delay(1000);
   }
void loop() 
{ pulse();
temperature();
}

I separated the code a bit, the pulseoximeter isn't working if both functions are called in the loop function. If I comment the calling of temperature function in loop it functions well. The temperature sensor is always working, so I think the wiring is fine, the problem is in the code.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.