Need Help !! having trouble with this code and cant figure out why.

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
LLAMAFTW01
 
Posts: 10
Joined: Wed Nov 30, 2022 8:05 am

Need Help !! having trouble with this code and cant figure out why.

Post by LLAMAFTW01 »

Hi I have question why is it when error checking is doesn't show any errors but when running the code using ESP32 with all three of the sensors MAX30100, MPU6050 and MLX90614 is only shows data for MPU6050 sensor but not the other two sensors.

All the sensors are connected to SCL and SDA.

There wasn't any error when uploading the code.

Checked using I2C scanner all addresses are different.

When using two sensors only the combination of MAX30100 and MPU6050 doesn't show any data on the serial monitor.

Code: Select all

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <Adafruit_MLX90614.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>

#define REPORTING_PERIOD_MS     1000

Adafruit_MLX90614 mlx = Adafruit_MLX90614(); 
Adafruit_MPU6050 mpu;                        
PulseOximeter pox;                           

// Time at which the last beat occurred
uint32_t tsLastReport = 0;

// Callback routine is executed when a pulse is detected
void onBeatDetected() {
    Serial.println("♥ Beat!");
}

void setup() {
    Serial.begin(115200);
   
    pox.begin();
    pox.setOnBeatDetectedCallback(onBeatDetected);
    mlx.begin();
    mpu.begin(); 
        mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
        Serial.print("Accelerometer range set to: ");
        switch (mpu.getAccelerometerRange()) {
        case MPU6050_RANGE_2_G:
          Serial.println("+-2G");
          break;
        case MPU6050_RANGE_4_G:
          Serial.println("+-4G");
          break;
        case MPU6050_RANGE_8_G:
          Serial.println("+-8G");
          break;
        case MPU6050_RANGE_16_G:
          Serial.println("+-16G");
          break; 
        }
        mpu.setGyroRange(MPU6050_RANGE_500_DEG);
        Serial.print("Gyro range set to: ");
        switch (mpu.getGyroRange()) {
        case MPU6050_RANGE_250_DEG:
          Serial.println("+- 250 deg/s");
          break;
        case MPU6050_RANGE_500_DEG:
          Serial.println("+- 500 deg/s");
          break;
        case MPU6050_RANGE_1000_DEG:
          Serial.println("+- 1000 deg/s");
          break;
        case MPU6050_RANGE_2000_DEG:
          Serial.println("+- 2000 deg/s");
          break;
        }
      
        mpu.setFilterBandwidth(MPU6050_BAND_5_HZ);
        Serial.print("Filter bandwidth set to: ");
        switch (mpu.getFilterBandwidth()) {
        case MPU6050_BAND_260_HZ:
          Serial.println("260 Hz");
          break;
        case MPU6050_BAND_184_HZ:
          Serial.println("184 Hz");
          break;
        case MPU6050_BAND_94_HZ:
          Serial.println("94 Hz");
          break;
        case MPU6050_BAND_44_HZ:
          Serial.println("44 Hz");
          break;
        case MPU6050_BAND_21_HZ:
          Serial.println("21 Hz");
          break;
        case MPU6050_BAND_10_HZ:
          Serial.println("10 Hz");
          break;
        case MPU6050_BAND_5_HZ:
          Serial.println("5 Hz");
          break;
        }    
    Serial.println();
}

void loop() {
    // Read from the sensor
    pox.update();

    // Grab the updated heart rate and SpO2 levels
    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();
        delay(500);
    }
        
    sensors_event_t a, g, temp;
    mpu.getEvent(&a, &g, &temp);

    Serial.print("Accelerometer ");
    Serial.print("X: ");
    Serial.print(a.acceleration.x, 1);
    Serial.print(" m/s^2, ");
    Serial.print("Y: ");
    Serial.print(a.acceleration.y, 1);
    Serial.print(" m/s^2, ");
    Serial.print("Z: ");
    Serial.print(a.acceleration.z, 1);
    Serial.println(" m/s^2");
 
    Serial.print("Gyroscope ");
    Serial.print("X: ");
    Serial.print(g.gyro.x, 1);
    Serial.print(" rps, ");
    Serial.print("Y: ");
    Serial.print(g.gyro.y, 1);
    Serial.print(" rps, ");
    Serial.print("Z: ");
    Serial.print(g.gyro.z, 1);
    Serial.println(" rps");
    delay(500);
    
    Serial.print("Ambient temperature = "); 
    Serial.print(mlx.readAmbientTempC());
    Serial.print("°C");      
    Serial.print("   ");
    Serial.print("Object temperature = "); 
    Serial.print(mlx.readObjectTempC()); 
    Serial.println("°C");
    
    Serial.print("Ambient temperature = ");
    Serial.print(mlx.readAmbientTempF());
    Serial.print("°F");      
    Serial.print("   ");
    Serial.print("Object temperature = "); 
    Serial.print(mlx.readObjectTempF()); 
    Serial.println("°F");
    delay(500);
      
    Serial.println("-----------------------------------------------------------------");

    delay(1000);
}

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Need Help !! having trouble with this code and cant figure out why.

Post by adafruit_support_carter »

Please post some actual Serial Monitor output that shows the issue.

User avatar
LLAMAFTW01
 
Posts: 10
Joined: Wed Nov 30, 2022 8:05 am

Re: Need Help !! having trouble with this code and cant figure out why.

Post by LLAMAFTW01 »

hi sorry but here is the serial monitor output
image_2022-12-01_233844558.png
image_2022-12-01_233844558.png (8.07 KiB) Viewed 338 times

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Need Help !! having trouble with this code and cant figure out why.

Post by adafruit_support_carter »

with all three of the sensors MAX30100, MPU6050 and MLX90614 is only shows data for MPU6050 sensor but not the other two sensors.
It looks like the only issue is with the MLX90614. But you mention two sensors not working?

Does the MLX90614 work stand alone? That is - connected by itself and running the library example.
https://learn.adafruit.com/using-melexi ... g-and-test

User avatar
LLAMAFTW01
 
Posts: 10
Joined: Wed Nov 30, 2022 8:05 am

Re: Need Help !! having trouble with this code and cant figure out why.

Post by LLAMAFTW01 »

Hi thanks for the reply but the sensors MLX90614 works well when it is plugged into the esp32 alone but when I used the max30100 sensor it doesn't seem to work even doing research and using different code it doesn't seem to be functioning and when I started using the sensor standalone I was also having a hard time making the sensor work and idk how to use the tester for the MAX30100 because it uses Arduino but I'm using esp32 is there a place where I can learn more about changing Arduino code to esp32 code ?

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Need Help !! having trouble with this code and cant figure out why.

Post by adafruit_support_carter »

Ideally Arduino code is portable between different platforms.

It sounds like it's the MAX30100 sensor that is the outlier here. Which specific MAX30100 sensor are you using and where did the Arduino library for the MAX30100 come from?

User avatar
LLAMAFTW01
 
Posts: 10
Joined: Wed Nov 30, 2022 8:05 am

Re: Need Help !! having trouble with this code and cant figure out why.

Post by LLAMAFTW01 »

hi the sensor I'm using is this GY-MAX30100 and the library I'm using is this MAX30100lib
image_2022-12-02_230446699.png
image_2022-12-02_230446699.png (201.56 KiB) Viewed 319 times
image_2022-12-02_230603560.png
image_2022-12-02_230603560.png (8.77 KiB) Viewed 319 times

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Need Help !! having trouble with this code and cant figure out why.

Post by adafruit_support_carter »

It looks like the issue here is with non-Adafruit hardware.

That library has a lot of open issues:
https://github.com/oxullo/Arduino-MAX30100/issues
and doesn't look like it's been updated in over 5 years.

User avatar
LLAMAFTW01
 
Posts: 10
Joined: Wed Nov 30, 2022 8:05 am

Re: Need Help !! having trouble with this code and cant figure out why.

Post by LLAMAFTW01 »

ahhh so is there a library for this sensor ? or like can I have a link to where to install the library ?

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: Need Help !! having trouble with this code and cant figure out why.

Post by adafruit_support_carter »

You'll need to contact to the sensor maker to see what Arduino library they recommend.

User avatar
LLAMAFTW01
 
Posts: 10
Joined: Wed Nov 30, 2022 8:05 am

Re: Need Help !! having trouble with this code and cant figure out why.

Post by LLAMAFTW01 »

ahh okay thank you

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”