This page contains the description of the IoT device built to collect medical information about Heart, blood oxygenation and temperature.
If you need additional specific information about this topic or if you want to look it personally please write an email
#include "MAX30105.h"
#include "spo2_algorithm.h"
Now declare the following global variables:
uint32_t irBuffer[100]; //infrared LED sensor data
uint32_t redBuffer[100]; //red LED sensor data
int32_t bufferLength; //data length
int32_t spo2; //SPO2 value
int8_t validSPO2; //indicator to show if the SPO2 calculation is valid
int32_t heartRate; //heart rate value
int8_t validHeartRate; //indicator to show if the heart rate calculation is valid
In the setup function you need now to init the sensor with the following easy lines. The values you will see are the optimal values I identified for my device. Honestly I cannot imagine a big variation
on similar device
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
{
Serial.println("MAX30105 was not found. Please check wiring/power. ");
while (1);
}
Serial.println("Place your index finger on the sensor with steady pressure. and press the button");
byte ledBrightness = 60; //Options: 0=Off to 255=50mA
byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
byte sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
int pulseWidth = 411; //Options: 69, 118, 215, 411
int adcRange = 4096; //Options: 2048, 4096, 8192, 16384
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
Now the most important part. In the loop cycle you will read values and will display results both on the display or sending them to the Miniservice infrastructure. Be carefull to optimise this piece of code more
than possible in order to speed up the sensor reading phase
bufferLength = 100; //buffer length of 100 stores 4 seconds of samples running at 25sps
//read the first 100 samples, and determine the signal range
for (byte i = 0; i < bufferLength; i++)
{
while (particleSensor.available() == false) //do we have new data?
particleSensor.check(); //Check the sensor for new data
redBuffer[i] = particleSensor.getRed();
irBuffer[i] = particleSensor.getIR();
particleSensor.nextSample(); //We're finished with this sample so move to next sample
Serial.print(F("red="));
Serial.print(redBuffer[i], DEC);
Serial.print(F(", ir="));
Serial.println(irBuffer[i], DEC);
}
//calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples)
maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
//Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second
while (1)
{
bool FingerFound=false;
//dumping the first 25 sets of samples in the memory and shift the last 75 sets of samples to the top
for (byte i = 25; i < 100; i++)
{
redBuffer[i - 25] = redBuffer[i];
irBuffer[i - 25] = irBuffer[i];
}
//take 25 sets of samples before calculating the heart rate.
for (byte i = 75; i < 100; i++)
{
while (particleSensor.available() == false) //do we have new data?
particleSensor.check(); //Check the sensor for new data
redBuffer[i] = particleSensor.getRed();
irBuffer[i] = particleSensor.getIR();
particleSensor.nextSample(); //We're finished with this sample so move to next sample
if (irBuffer[i] > 50000)
FingerFound = true;
}
//After gathering 25 new samples recalculate HR and SP02
maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
//print on the LCD Display
//do something here to display results ...
if (!FingerFound){
sprintf(ScreenOutput, "finger not found");
break; //reset and out from the loop
}
else
sprintf(ScreenOutput, "HR:%l, PO2:%l", heartRate, spo2);
//put the string on your display ...
if ((millis() - time) > SEND_INTERVALL) {
BVReturnString = BVAuthenticate(SVCBiomedical, ObjectCode, (String)WiFi.localIP());
Token = xmlTakeParam(BVReturnString, "Message");
if ((Token != "Not Authorized") && (Token != "not found")) {
SendBioMedicalValues(Token, 0 ,heartRate, spo2);
}
time = millis();
}
}
As you can see in order to connect to the bvrobotics.com miniservice infrastructure I've used some basic functions provided by the Miniservices library.