Interfacing multiple i2c sensors error sending values to blynk

#include <Wire.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <MAX30100_PulseOximeter.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_TEMPLATE_ID "TMPL38diIpwMe"
#define BLYNK_TEMPLATE_NAME "Health monitor "
#define BLYNK_AUTH_TOKEN "NH7vhv1hsxCQ3Sigdou9TODZ0IrudXeN"
#define BLYNK_PRINT Serial
char auth[] = "NH7vhv1hsxCQ3Sigdou9TODZ0IrudXeN"; //Blynk Authentication Token 
#include <Adafruit_MLX90614.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define OLED_ADDRESS 0x3C
uint8_t max30100_address = 0x57;
uint8_t irmlx90614_address = 0x5A;
 
/* WiFi credentials */
char ssid[] = "NANDANAM AST"; //Your WiFi SSID
char pass[] = "sanil1969"; //Your WiFi Password
 
#define REPORTING_PERIOD_MS     2000
//#define REPORTING_PERIOD_MS2     4000
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
Adafruit_SSD1306 display(128, 64, &Wire, -1);
PulseOximeter pox;
uint32_t tsLastReport = 0;
double temp_obj;
double calibration = 2.36;

void setup()
{
    Serial.begin(9600);
    Blynk.begin(auth, ssid, pass);
    Serial.print("Initializing pulse oximeter..");
   
     Wire.begin();
     mlx.begin();
     display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDRESS);
  display.clearDisplay();
  display.setCursor(25,15);  
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.println("Health monitor");
  display.setCursor(25,35);
  display.setTextSize(1);
  display.print("Initializing,...");
  display.display();
  delay(2500);
 
    // 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");
        digitalWrite(1,HIGH);
    }
     pox.setIRLedCurrent(MAX30100_LED_CURR_24MA);
}



void loop()
{
  Blynk.run();
  sendata();
}
void sendata(){

    pox.update();
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        // to computer serial monitor
        Serial.print("BPM: ");
        Serial.print(pox.getHeartRate());
        Serial.print("    SpO2: ");
        Serial.print(pox.getSpO2());
        Serial.print("%");
        Serial.println("\n");
        
        temp_obj = mlx.readObjectTempC();
        Blynk.virtualWrite(V9,temp_obj + calibration);

         display.clearDisplay();
    
   display.setCursor(10,10);
  display.setTextSize(1);
  display.print("Object: ");
  display.print(temp_obj + calibration);
  display.print((char)247);
  display.print("C");
  
        display.display();

        display.setCursor(10, 30);//pulseoximeter
        display.print("Heartrate: " );
        display.print(pox.getHeartRate());
        display.println("bpm");
        display.setCursor(10,50);
        display.print("SpO2: ");
        display.print(pox.getSpO2());
        display.println(" % ");
        display.display();

      
      
        Blynk.virtualWrite(V7,pox.getHeartRate() );
        Blynk.virtualWrite(V8,pox.getSpO2());
        
        
        tsLastReport = millis();
    


   
      }
      
      }


iam making a project to measure the spo2 heart rate and temperatures using MAX30100 and mlx90614 sensor with esp8266 and oled display. i need to display the values on blynk aswell as in oled but the probelm is whenver i comment the " Blynk.virtualWrite(V9,temp_obj + calibration);" part in the code the max30100 stops reading and sending data only the mlx90614 works when i uncommect the above lines all works perfect except sending the mlx90614 values to blynk .help me

I’m assuming that you meant to say “un-comment” here rather than “comment”?

You seem to be getting your sensors mixed-up in this sentence.

Which sensor (and which pieces of data) is it that stops working when this line is allowed to execute (un-commented)?

Pete.

1 Like

i am using different i2c address for each modules the problem is only with the data sent to blynk from mlx90614 module when i put Blynk.virtualWrite(V9,temp_obj + calibration); this in code the max30100 sensor get blocked from displaying values in serial monitor blynk and oled that time only mlx90614 values are displayed alone ,help me

So, just to be 100% clear, are you saying that the Heartrate and Sp02 data does not appear unless you comment-out the Blynk.virtualWrite(V9,temp_obj + calibration); line of code, like this…

// Blynk.virtualWrite(V9,temp_obj + calibration);

Pete.

Yes but I need all 3 data to be displayed on blynk server what can I do sir

I realise that, but the first step is to understand EXACTLY what the issue is, because your initial description was contradictory and your follow-ups haven’t been as clear as I would have liked.

I’ve never used the max30100 sensor or studied the Adafruit library for the device, but some things look wrong to me. First of all, you aren’t using BlynkTimer to call the sendata function. Instead it’s being called from the void loop…

This wouldn’t be too bad if the first thing that the sendata function did was to do a millis() check to see if it’s time to take some readings, but that’s not how it’s structured. Instead, it calls pox.update() first, which means that this command is executing every time the void loop executes, which should be hundreds if not thousands of times per second.

Then, when the mills() check shows that it’s time to take the teadsings and send them to the LCD, serial monitor and Blynk you do that in a very clunky way…
Instead of interrogating the max30100 sensor once to obtain the heartrate and Sp02 values then sending the result to the three locations, you are taking fresh (and therefore potentially different) readings readings for each location…

I suspect that some of your issues are related to these code structure issues.

Pete.

1 Like

Max30100 code looks strange and this sensor easily get blocked I tried timer but I get only values from mlx90614 .idk what could be the reason help me

Impossible to say unless you share your code and explain in a clear and understandable way what sort of results you are seeing.

Pete.

Code is same a above I will explain my esp8266 I’d connected to the i2c interface common for oled pulse oximeter and mlx90614 ir temperature sensor all are connectes to sda scl of esp. in OLED it display 3 values temperature heart rate and sp02 and in blynk app too. The problem is I aml getting only pulse oximeter values . When I put blynk code to display temperature value the app shows only temperature even in OLED other two values will stay on 0 and not starts counting . But in serial monitor it’s shows the pulse oximeter is initiated successfully. But not measuring the values.when I remove the blynk virtual.write. Code of temperature sensor the pulse oximeter works . What. Could be the reasons.sir

I don’t see any timer code in any of the code you’ve posted.

I take it that you’ve dismissed the issues with your code that I raised earlier?

Pete.

Sir I am getting pulse oximeter values on oled and blynk app only if I remove the Blynk virtual write command to display temperature. At this instance I will get 3 values on oled and 2 values of oximeter on blynk app . Stilll not getting temperature 8f I add this it will.block the oximeter

Okay, if you don’t like my suggestions then I’ll take a step back and let someone else try to help.
Good luck with your project.

Pete.

No sir I need your help

The first change I would do is remove sendata() from your void loop() and use a timer to run it.
It looks like you are sending data to the Blynk server a thousand times a second, flooding the Blynk server. Keep your void loop() clean, use a timer.

My doubt is if I use mills along with a timer cause any problem