Problem to combine OLED DISPLAY 128X64 with main sensor(MAX30100+LM35+BUZZER)

Today at 09:29 am Last Edit: Today at 09:35 am by usherul
Hi All,

Let me explain first what is the problem with my coding. Actually, i try to make a project to detect heart rate,spo2 and temperature using the arduino nano. The sensor i use for heart rate and spo2 is MAX30100 and for the temperature sensor i use LM35. I done compare all this coding and is work properly. The problem is when i try to combine the oled sendor with all the main sensor(Max30100 and LM35) the data for heart rate and spo2 cant detect and only show the 0 value on the oled screen. There is no error for my coding but when i put the coding for display.display(); the max sensor cant detect.

Below is the coding:

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <Adafruit_SSD1306.h>
  Adafruit_SSD1306 display(4);
#define REPORTING_PERIOD_MS   5000


PulseOximeter pox;

int temppin = A1;   //<---------This is the PIN the LM53 (Temperature Sensor)
float temp = 0;
int Buzz = A2;       //<---------This is the PIN for (HYDZ BUZZER)
uint32_t tsLastReport = 0;


void onBeatDetected()
{
  Serial.println("Beat!");
}

void setup()
{
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  
  Serial.begin(115200);

  Serial.print("Initializing pulse oximeter..");
  pinMode(Buzz, OUTPUT);
  digitalWrite (Buzz, HIGH);   //(No sound at starting)

 
  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);
}

void loop()
{

  temp = analogRead(temppin);
  temp = temp * 0.48828125;
  
    delay(10);
    display.clearDisplay();

  // 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)
  {
    Serial.print("Heart rate:");
    Serial.print(pox.getHeartRate());
    Serial.print("bpm / SpO2:");
    Serial.print(pox.getSpO2());
    Serial.println("%");

    Serial.print("TEMPERATURE = ");
    Serial.print(temp);
    Serial.print("*C");
    Serial.println();

    display.setTextColor(WHITE);
    display.setCursor(0, 0);
    display.print("Heart rate:");
    
    display.setTextColor(WHITE);
    display.setCursor(87, 0);
    display.print(pox.getHeartRate());
    //display.print(millis()/1000);
   
    display.setTextColor(WHITE);
    display.setCursor(0, 12);
    display.print("Bpm / SpO2:");
 
    display.setTextColor(WHITE);
    display.setCursor(87, 12);
    display.print(pox.getSpO2());

  
    display.setTextColor(WHITE);
    display.setCursor(105, 12);
    display.println("%");
 
 
    display.setTextColor(WHITE);
    display.setCursor(0, 24);
    display.print("TEMPERATURE:");

    display.setTextColor(WHITE);
    display.setCursor(87, 24);
    display.print(temp);
   
    display.setTextColor(WHITE);
    display.setCursor(117, 24);
    display.print("C");
    display.println();

    display.display();
   

    tsLastReport = millis();


    if ( temp > 37 || ((pox.getSpO2() < 95) && !((pox.getSpO2() < 25))) || (pox.getHeartRate() > 100) || ((pox.getHeartRate() < 60) && !((pox.getHeartRate() < 39))) )
    { digitalWrite(Buzz, LOW);//bunyi

    }

    else
    { digitalWrite (Buzz, HIGH);//tak bunyi

    }

    tsLastReport = millis();



  }

}

anyone??pls help

My guess is you're running out of memory. The SSD_1306 library is using most of the RAM the Nano has and you're wasting the rest by not using the F() macro for constant strings. So either reduce the memory footprint or change to a board with more RAM (p.e. Mega2560).

Hi sir. Appreciate you are reply. I think is not the issue with my arduino because the data can read for the first time which is after uploading but the data for the next reading cant detected. izit any problem with my oled coding?

#include <Adafruit_SSD1306.h>
  Adafruit_SSD1306 display(4);

The default Adafruit library expects a 128x32 display with this code. And if you changed the library to let it run with your 128x64 display, it uses more than 1916 bytes of RAM after the first few lines of code for the global variables and the display buffer (not counting local variables and return addresses on the stack). Sooner or later the stack will grow into heap and your code goes crazy. But if you think it's not a RAM problem, search for other problems. Good luck!

can u rewrite my coding to make the low of ram use. i cant change the types of arduino and oled display because of the size of the design. Please i really need your help sir

Learn to use the F() macro. This might save a few bytes but in the end you probably have to change to an Arduino with more memory anyway. There are quite small versions of Arduino Mega2560 compatible board available.