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.
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?
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.