Protothread problem with MAX30205 and MAX30100

Hi everyone.

I have a problem with my code.

I want to put the code of temperature sensor MAX30205 and heart rate sesnor MAX30100 together.

At first,I put two code directly,and it can show the result of MAX30205.

MAX30100 can print Heart rate and SpO2,but the value always be 0.

Next, I consult with this website for protothread.

But it shows the same result to me.

This is my code.

#include <Wire.h>
#include <pt.h>
#include "Protocentral_MAX30205.h"
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS     1000
static struct pt pt1, pt2; 
MAX30205 tempSensor;
PulseOximeter pox;


uint32_t tsLastReport = 0;
void onBeatDetected()
{
    Serial.println("Beat!");
}

void setup() {
  Serial.flush(); // wait for last transmitted data to be sent
  Serial.begin(115200);
  while(Serial.available()) Serial.read(); // empty  out possible garbage from input buffer
  // if the device was sending data while you changed the baud rate, the info in the input buffer
  // is corrupted.
  Wire.begin();
  tempSensor.begin();   // set continuos mode, active mode
  pox.begin();
  pox.setOnBeatDetectedCallback(onBeatDetected);
  PT_INIT(&pt1);
  PT_INIT(&pt2);
}

static int protothread1(struct pt *pt, int interval) {
  static unsigned long timestamp = 0;
  PT_BEGIN(pt);
  while(1) { // never stop 
    /* each time the function is called the second boolean
    *  argument "millis() - timestamp > interval" is re-evaluated
    *  and if false the function exits after that. */
    PT_WAIT_UNTIL(pt, millis() - timestamp > interval );
    timestamp = millis(); // take a new timestamp
  }
  PT_END(pt);
}
/* exactly the same as the protothread1 function */
static int protothread2(struct pt *pt, int interval) {
  static unsigned long timestamp = 0;
  PT_BEGIN(pt);
  while(1) {
    PT_WAIT_UNTIL(pt, millis() - timestamp > interval );
    timestamp = millis();
  }
  PT_END(pt);
}

void loop() {
  pox.update();
	float temp = tempSensor.getTemperature(); // read temperature for every 100ms
	Serial.print(temp ,2);
	Serial.println("'c" );
	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();
        protothread1(&pt1, 900);
        protothread2(&pt2, 1000);
    }
	delay(3000);
}

Thank you for help.

Hi everyone.

I have a problem with my code.I'm not sure how to ask this question so I will try to explain the best I can.

I have a temperature sensor MAX30205 and a heart rate sesnor MAX30100.

I put the code together and it can show temperature result,but there is a problem in heart rate result.

At first,the result was 0,but few minutes later,it can show some value,but those value is too small.

Normal person's bpm is at 55~70,but my value is at 19~31,so there must be something wrong.

Thank you for help.

This is my code.

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

ClosedCube_MAX30205 max30205;
PulseOximeter pox;

uint32_t tsLastReport = 0;

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

void setup() {
  Serial.flush(); // wait for last transmitted data to be sent
  Serial.begin(115200);
  while(Serial.available()) Serial.read();
  Serial.println("ClosedCube MAX30205 Arduino Demo");
  max30205.begin(0x48);
  Serial.print("Initializing pulse oximeter..");
 if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }
    pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop() {
  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();
    }
   Serial.print("T=");
   Serial.print(max30205.readTemperature());
   Serial.println("C");
   delay(300);
}