//Max30101_M5StickC
#include <SparkFun_Bio_Sensor_Hub_Library.h>
#include <Wire.h>
// Reset pin, MFIO pin
int resPin = 26;
int mfioPin = 36;
// Possible widths: 69, 118, 215, 411us
int width = 411;
int samples = 400;
int pulseWidthVal;
int sampleVal;
// Takes address, reset pin, and MFIO pin.
SparkFun_Bio_Sensor_Hub bioHub(resPin, mfioPin);
bioData body;
void setup(){
Serial.begin(115200);
//Wire.begin();
Wire.begin(32,33); //M5StickC SDA,SCL
int result = bioHub.begin();
if (result == 0) // Zero errors!
Serial.println("Sensor started!");
Serial.println("Configuring Sensor....");
int error = bioHub.configSensorBpm(MODE_ONE); // Configure Sensor and BPM mode , MODE_TWO also available
if (error == 0){// Zero errors.
Serial.println("Sensor configured.");
}
else {
Serial.println("Error configuring sensor.");
Serial.print("Error: ");
Serial.println(error);
}
// Set pulse width.
error = bioHub.setPulseWidth(width);
if (error == 0){// Zero errors.
Serial.println("Pulse Width Set.");
}
else {
Serial.println("Could not set Pulse Width.");
Serial.print("Error: ");
Serial.println(error);
}
// Check that the pulse width was set.
pulseWidthVal = bioHub.readPulseWidth();
Serial.print("Pulse Width: ");
Serial.println(pulseWidthVal);
// Set sample rate per second. Remember that not every sample rate is
// available with every pulse width. Check hookup guide for more information.
error = bioHub.setSampleRate(samples);
if (error == 0){// Zero errors.
Serial.println("Sample Rate Set.");
}
else {
Serial.println("Could not set Sample Rate!");
Serial.print("Error: ");
Serial.println(error);
}
// Check sample rate.
sampleVal = bioHub.readSampleRate();
Serial.print("Sample rate is set to: ");
Serial.println(sampleVal);
// Data lags a bit behind the sensor, if you're finger is on the sensor when
// it's being configured this delay will give some time for the data to catch
// up.
Serial.println("Loading up the buffer with data....");
delay(4000);
}
void loop(){
// Information from the readSensor function will be saved to our "body"
// variable.
body = bioHub.readSensorBpm();
Serial.print(body.irLed);
Serial.print(",");
Serial.print(body.redLed);
Serial.print(",");
Serial.print(body.heartRate);
Serial.print(",");
Serial.print(body.confidence);
Serial.print(",");
Serial.print(body.oxygen);
Serial.print(",");
Serial.print(body.status);
Serial.println();
// Slow it down or your heart rate will go up trying to keep up
// with the flow of numbers
delay(500);
}