MAX30100,MLX90614 AND Oled display not working together

My senosors MAX30100,MLX90614 and OLED display not working Together while connecting to arduino iot cloud
Here's the code please anyone help me

/* 
  Sketch generated by the Arduino IoT Cloud Thing "IOT Based Remote Patient Monitoring system"
  https://create.arduino.cc/cloud/things/d638babb-7f2b-448c-89f6-08093a79e06a 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float ecg;
  float hrv;
  CloudHeartRate hr;
  CloudPercentage spo2;
  CloudTemperature object;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include "MAX30100.h"
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <U8x8lib.h>
#define REPORTING_PERIOD_MS     1000   //update rate of hr, spo2, ambient, object, hrv, etc parameters in milli seconds 
#define DISPLAY_INTERVAL        5     //update rate for the i2c display = REPORTING_PERIOD_MS*DISPLAY_INTERVAL
#define COMPENSATION            5     //compensation in object temperature. Different body parts have different temperatures. Fingers are around 5 degF lower than core body temperature

// objects
PulseOximeter pox;    //this offers spo2 and hr calculation 
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
U8X8_SH1106_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
MAX30100 sensor;
//variables
uint32_t tsLastReport = 0;
int count = 0, flag = 0, PatientID = 0;
float ambient;
long time1 = 0, time2 = 0; 
uint16_t ir = 0, red = 0; ;
char str_hrv[10], str_object[10], str_ambient[10];
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
    time1 = micros() - time2;
    time2 = micros();
}
void setup() {
  // Initialize serial and wait for port to open:
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
//display connected
    u8x8.begin();
    u8x8.setPowerSave(0);
    u8x8.setFont(u8x8_font_chroma48medium8_r);
    //pinMode(10, INPUT); // Setup for leads off detection LO +
    //pinMode(11, INPUT); // Setup for leads off detection LO -
    Serial.begin(115200);
    /*
    while (!Serial) {
      ; // wait for serial port to connect. Needed for native USB port only
    }
    */
    // 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);
    mlx.begin();
    time2 = micros();
  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  // Make sure to call update as fast as possible
    pox.update();
    //reading continuous functions (signals) every loop
    ecg = analogRead(A0);
    delay(1);
    // Asynchronously calculate other variables every REPORTING_PERIOD_MS
    // For hr and spo2, a value of 0 means "invalid", for object and ambient temperatures a value less than 70 degF or higher than 110 degF can be considered abnormal
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        hr = pox.getHeartRate();
        spo2 = pox.getSpO2();
        ambient = mlx.readAmbientTempF();
        object = mlx.readObjectTempF() + COMPENSATION;
        hrv = (60000000/hr - (float)time1)/1000;
        //send_serial();
        tsLastReport = millis();
        count++;
        flag = 0;
    }
    //Display all variables on the display after DISPLAY_INTERVAL seconds
    if ((count%DISPLAY_INTERVAL == 0) && (flag != 1)) {
      flag = 1;   //This flag makes sure the display is updated only once every DISPLAY_INTERVAL seconds
      Wire.end();
      send_display();
      Wire.begin();     
    }
}
void send_display() {
  u8x8.clearDisplay();
  u8x8.setCursor(0,1);
  u8x8.print("HRV:"); 
  u8x8.print(hrv);
  u8x8.print(" ms");
  u8x8.setCursor(0,2);
  u8x8.print("SpO2:");
  u8x8.print(spo2);
  u8x8.print(" %");
  u8x8.setCursor(0,3);
  u8x8.print("HR:");
  u8x8.print(hr);
  u8x8.print(" bpm");
  u8x8.setCursor(0,4);
  u8x8.print("Temp:");
  u8x8.print(object);
  u8x8.print(" degF");
  u8x8.setCursor(0,5);
  u8x8.print("ecg:");
  u8x8.print(ecg);
  //delay(200); 
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.