EdOliver
Created October 29, 2019 © MIT

MatrixHealth: Voice First Glucose and Vital Signs Monitor

Perhaps the first vital signs and glucose monitor made entirely on the MATRIX Creator using the Snips voice assistant.

AdvancedFull instructions provided10 hours186

Things used in this project

Story

Read more

Custom parts and enclosures

Custom CAD enclosure

Adjust accordingly on your slicer. Use at your own discretion.

Schematics

MQTT relay diagram

Code

Pulse Oxymeter code

C/C++
The code for the Node-MCU esp8266 that runs the MAX30100
#include <ESP8266WiFi.h>
#include <PubSubClient.h>

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"

#define REPORTING_PERIOD_MS     1000

// PulseOximeter is the higher level interface to the sensor
// it offers:
//  * beat detection reporting
//  * heart rate calculation
//  * SpO2 (oxidation level) calculation
PulseOximeter pox;

uint32_t tsLastReport = 0;

int counter=0;
 
const char* ssid = "Your ssid";
const char* password =  "Your_PW";
const char* mqttServer = "HOSTNAME/IP";
const int mqttPort = 1883;// Mosquitto port
/* 
const char* mqttUser = "YourMqttUser";
const char* mqttPassword = "YourMqttUserPassword";
*/
 
WiFiClient espClient;
PubSubClient client(espClient);
 
void setup() {
 
  pinMode(D3, OUTPUT);
  Wire.begin(D1, D2); // sda, scl
  Serial.begin(115200);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
  }
  Serial.println("Connected to the WiFi network");
 
  client.setServer(mqttServer, mqttPort);
  client.setCallback(callback);
 
  while (!client.connected()) {
    Serial.println("Connecting to MQTT...");
 
    if (client.connect("ESP8266Client")) 
    //if (client.connect("ESP8266Client", mqttUser, mqttPassword )) // Usa este si vas a usar User y Pass
    {
 
      Serial.println("connected");  
 
    } else {
 
      Serial.print("failed with state ");
      Serial.print(client.state());
      delay(2000);
 
    }
  }

  Serial.print("Initializing pulse oximeter..");

    // 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");
    }

    // The default current for the IR LED is 50mA and it could be changed
    //   by uncommenting the following line. Check MAX30100_Registers.h for all the
    //   available options.
    // pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

    // Register a callback for the beat detection
    pox.setOnBeatDetectedCallback(onBeatDetected);
 
  
}

// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
    Serial.println("Beat!");
    counter=counter+1;
    Serial.println(counter);
}

//  Call back MQTT

void callback(char* topic, byte* payload, unsigned int length) {
 
  Serial.print("Message arrived in topic: ");
  Serial.println(topic);
 
  Serial.print("Message:");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
 
  Serial.println();
  Serial.println("-----------------------");
 
}
 
void loop() {
  client.loop();

  // Make sure to call update as fast as possible
  pox.update();

    // Asynchronously dump heart rate and oxidation levels to the serial
    // For both, a value of 0 means "invalid"
  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 (counter>=16){
    counter=0;
    Serial.println("Does it work??");
    digitalWrite(D3, HIGH);
    client.publish("Your chosen Topic", "Your info, yeah preferably heart rate or spO2 lol");
    client.subscribe("Your topic");
  }
}

Credits

EdOliver

EdOliver

18 projects • 23 followers
Engineer, Scientist, Maker. Entrepreneur and Futurist.
Thanks to Victor Altamirano.

Comments