Can an Arduino UNO handle two sensors and an oled display at the same time?

Hi all
Im trying to connect two sensors (max30100 and mlx90614) to an arduino and view the output on an oled display.
The sketch:

#include <Wire.h>
#include <MAX30100_PulseOximeter.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


#define REPORTING_PERIOD_MS 1000


uint32_t tsLastReport = 0;

Adafruit_MLX90614 mlx = Adafruit_MLX90614();
PulseOximeter pox;
Adafruit_SSD1306 oled;

void setup() 
{
Serial.begin(9600);
mlx.begin();
pox.begin();
oled.begin();
oled.clearDisplay();
   
}

void loop() 
{
  // oled.clearDisplay();
pox.update();
 if (millis() - tsLastReport > REPORTING_PERIOD_MS) 
 {
    Serial.print("Heart rate = ");Serial.print(pox.getHeartRate());Serial.print(" BPM");
    Serial.print("      SpO2 = ");Serial.print(pox.getSpO2());Serial.println(" %");
    Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());Serial.print("c");
    Serial.print("           Object = "); Serial.print(mlx.readObjectTempC()); Serial.println("c");
    Serial.println();   

    oled.setTextColor(WHITE);             
    oled.setCursor(0,0);   
    oled.print("Object = "); oled.print(mlx.readObjectTempC()); oled.println("c");
    oled.print("SpO2 = ");oled.print(pox.getSpO2());oled.print(" %");   

oled.display();
oled.clearDisplay();
    tsLastReport = millis();          
}
   
}

The problem:
this code will stop the max30100 from working and it won't read anything in the serial monitor:
Heart rate = 0.00 BPM SpO2 = 0 %
Ambient = 29.25c Object = 27.85c
but the mlx90614 works fine

when removing
oled.display();
oled.clearDisplay();
the sketch works fine and the values appear correct in the serial monitor, but of course, nothing displays on the oled

something to do with the oled.begin(); effecting the max30100

or could it be that the Arduino doesn't have enough F memory to handle two sensors and an oled display at the same time?

the sketch is using a bit more than half the memory:
Sketch uses 19660 bytes (60%) of program storage space. Maximum is 32256 bytes.
Global variables use 849 bytes (41%) of dynamic memory, leaving 1199 bytes for local variables. Maximum is 2048 bytes.

NOTE: already changed the max30100 bus speed to 100000UL

1 Like

what Arduino are you using?
upload a schematic showing the wiring

... for the global variables! The display buffer will use half of the available memory on top, so you're running out of memory.

Arduino UNO

I2C scanner

What did the I2C scanner report?

Thanks for posting the code in code tags.

So you think the problem is with the Arduino and not the code?
Will getting an Arduino Mega solve it?

Look at the u8g2 library for the OLED, using a page buffer instead of a full buffer will use considerably less ram.

Scanning...
I2C device found at address 0x3C !
I2C device found at address 0x57 !
I2C device found at address 0x5A !
done

Cool, Now we know the 3 devices are being 'seen'.

Now to play the pull up resistor game. Do you have 2.2K to 4.7K ohm resistors? Put one on the SCL line to Vcc and one on the SDL line to Vcc.

Now to play the pull up resistor game. Do you have 2.2K to 4.7K ohm resistors? Put one on the SCL line to Vcc and one on the SDL line to Vcc.

do you mean short circuit the SCL and SDA lines to the VCC using a resistor?

I do not mean for you to short circuit Vcc to anything.


Pull up resistors.


ok working on it

unfortunately no luck
the same thing

Heart rate = 0.00 BPM SpO2 = 0 %
Ambient = 29.21c Object = 27.81c

1 Like

leave the circuit wired as is but comment out the code for the mlx, does the pox porduce results?

same thing

void setup() 
{
Serial.begin(9600);

if (!mlx.begin()) {
    Serial.println("Error connecting to MLX sensor. Check wiring.");
    while (1);
  };

pox.begin();


oled.begin();
oled.clearDisplay();
   
}

add in tests to see which device is not starting up.

this is code to test the max thingy

code to test the oled

also the max thingy requires more setup parameters then your code shows,

post an image of the project.

If you are using a 9V battery like this.


Don't.



test of the max 30100 :
IR=3 RED=22
IR=0 RED=16
IR=2 RED=17
IR=0 RED=24
IR=0 RED=9
IR=2 RED=15
IR=0 RED=16
IR=0 RED=10
IR=0 RED=22
IR=0 RED=8
IR=5 RED=14
IR=0 RED=18
IR=0 RED=8
IR=0 RED=26
IR=0 RED=8
IR=5 RED=16
IR=0 RED=18
IR=0 RED=11
IR=0 RED=17
IR=0 RED=16
IR=0 RED=12
IR=1 RED=16
IR=0 RED=19
IR=0 RED=18

test of the oled: ok

could you post your most recent code in a post below this one?