MAX30100 I2C problem with another I2C sensor such as the BME280

Dear Arduino-fellows,

I'd like to get two I2C sensors connected to one Arduino UNO to work, namely the MAX30100 pulsoximeter and the Bosch BME280 sensor. I have purchased the components here:

Max30100:
https://www.amazon.de/Dosige-MAX30100-Herzfrequenz-Sensor-Modul-Raspberry/dp/B07D2Y55LG/ref=sr_1_2?__mk_de_DE=ÅMÅŽÕÑ&keywords=max30100&qid=1575983444&sr=8-2

with following library:

and the Bosch BME280:
https://www.ebay.de/itm/BME280-Temperatur-Sensor-Luftdruck-Feuchtigkeit-I2C-5V-Barometer-Arduino-Digital/253107395109?hash=item3aee605a25:g:Ol8AAOSwHWtb3znL

with the adafruit library:

Both sensors work flawlessly with the provided test sketches. However, when I merge the sketches, the Max30100 only displays 0 bpm and 0 spo2. I can kind of solve this problem by resetting the I2C connection after measuring with the MAX30100 but then I only manage to get one reasonable reading of the MAX30100 sensor.

Please see a part of the sketch below:

  float heart_rate = 0;
  float spO2 = 0;
  if (!pox.begin()) {
    Serial.println("FAILED");
    for (;;);
  } else {
    Serial.println("SUCCESS");
  }
  while (1) {
    pox.update();
    heart_rate = 0;
    spO2 = 0;
    heart_rate = pox.getHeartRate();
    spO2 = pox.getSpO2();
    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();
    }
    if (heart_rate > 70 && spO2 > 90) {
      break;
    }
  }
  TWCR = 0;
  bme.begin(0x76);
  uint16_t temperature = bme.readTemperature();
  uint16_t humidity = bme.readHumidity();
  uint16_t pressure = bme.readPressure() / 100.0F;
  uint16_t alt = bme.readAltitude(SEALEVELPRESSURE_HPA);
  TWCR = 0;

The output of the I2C scanner reports following register addresses for the sensors:
I2C device found at address 0x57 ! (MAX30100)
I2C device found at address 0x76 ! (BME280)

Thank you a lot!

Always post complete code!

My guess is that the heart rate sensor library depends on the 400kHz I2C frequency to work correctly but the BME280 library resets it to 100kHz.

Have you tried initializing the BME before the MAX30100?

pylon:
Always post complete code!

My guess is that the heart rate sensor library depends on the 400kHz I2C frequency to work correctly but the BME280 library resets it to 100kHz.

Have you tried initializing the BME before the MAX30100?

Dear pylon,

Thank you a lot for your help. I've tried to initialize the BME280 first, please see the full sketch below. The Serial.print of the Max30100 sensor is still 0 for heart rate and 0 for SpO2

#include <Arduino.h>
#include <math.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define SEALEVELPRESSURE_HPA (1013.25)
#define REPORTING_PERIOD_MS     1000

Adafruit_BME280 bme;
PulseOximeter pox;
//Variable definitions

//heart rate and spo2
uint32_t tsLastReport = 0;

void setup()
{
  pinMode(1, OUTPUT);
  digitalWrite(1, HIGH);
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop()
{
  bme.begin(0x76);
  uint16_t temperature = bme.readTemperature();
  uint16_t humidity = bme.readHumidity();
  uint16_t pressure = bme.readPressure() / 100.0F;
  uint16_t alt = bme.readAltitude(SEALEVELPRESSURE_HPA);
  float heart_rate = 0;
  float spO2 = 0;
  pox.update();
  Serial.println(pox.getHeartRate());
  Serial.print("bpm / SpO2:");
  Serial.println(pox.getSpO2());
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" C");
  Serial.print("Humidity: ");
  Serial.print(humidity);
  Serial.println(" %");
  Serial.print("Pressure: ");
  Serial.print(pressure);
  Serial.println(" hPa");
  Serial.print("Altitude ");
  Serial.print(alt);
  Serial.println(" m");
  delay(15000);
}

If you leave both sensors connected but use code that only reads the heart rate sensor, does that work?