Go Down

Topic: Problem sending Heartbeat and spo2 data to Firebase using MAX30100_Minimal code (Read 167 times) previous topic - next topic

Sheraz_Siddiqui

Hello everyone!

I am using GY-MAX30100 sensor to measure HeartRate and spo2. I am getting proper readings from the sensor when I am not sending my readings to firebase but when I start sending my readings to firebase, my sensor stops measuring heart rate and spo2 reading and only sending 0 bpm and 0 spo2 readings to firebase and even to my serial monitor.

Here is my code, when I am sending my readings to Firebase:

Code: [Select]
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>

// Set these to run example.
#define FIREBASE_HOST "test-8bc5c.firebaseio.com"
#define FIREBASE_AUTH "JATYiyaws143Yd68A12wjlG38MBa3UjFAn4BZ2Rv"
#define WIFI_SSID "TP-LINK_8D8E"
#define WIFI_PASSWORD "qwerty1234"

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
float bpm = 0.0;
float oxygen = 0.0;

#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;
 
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
    Serial.println("Beat!");
}
 
void setup()
{
    Serial.begin(230400);
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    
 
    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);
    
    
    
    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
 
void 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) {
          bpm = pox.getHeartRate();
          oxygen = pox.getSpO2();
          Serial.print("Heart rate:");
          Serial.print(bpm);
          Serial.print("bpm / SpO2:");
          Serial.print(oxygen);
          Serial.println("%");
          
          delay(100);
          tsLastReport = millis();
                
      }
     Firebase.setInt("/heartbeat", bpm);            
     Firebase.setInt("/oxygen", oxygen);
  
}


Here are my readings when I am trying to send data to Firebase:

Code: [Select]
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%


I will be very thankful to you if you will look into my problem.
Thank You!

PS: I have also attached my sensor's picture:

blh64

Not really familiar with firebase but the example demo code has error checking which you do not
Code: [Select]

Firebase.setFloat("number", 42.0);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error()); 
      return;


That may help shed some light on what is going wrong.

You also make your firebase calls EVERY time through loop() - maybe put them inside your time delay loop like your serial output.

Sheraz_Siddiqui

Thank you blh64 for your help. Actually, the problem is with the code it generates the heartbeat and oxygen in a particular time so, if we add another code with it, it will add delay, which stops reading heart rate and oxygen from the sensor.

So far, I did not find any proper solution. What I did is just add
Code: [Select]
ESP.restart() command after sending data to firebase because I was getting zero reading after sending data to firebase.

Go Up