Hi everyone. I got a problem with my coding during setup oled display. The main sensor for max30100 cant detect my finger after i put a coding for my oled. Can someone tell me what is the problem with my coding
This want is original main coding for main sensor
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 5000
// PulseOximeter is the higher level interface to the sensor
// it offers:
// * beat detection reporting
// * heart rate calculation
// * SpO2 (oxidation level) calculation
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;
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup()
{
Serial.begin(115200);
Serial.print("Initializing pulse oximeter..");
pinMode(Buzz, OUTPUT);
digitalWrite (Buzz, HIGH); //(No sound at starting)
// 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);
}
void loop()
{
temp = analogRead(temppin);
temp = temp * 0.48828125;
// 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("TEMPRATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
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();
}
}
This is the coding after i put the oled display and the main sensor cannot detect my finger
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(4);
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 5000
// PulseOximeter is the higher level interface to the sensor
// it offers:
// * beat detection reporting
// * heart rate calculation
// * SpO2 (oxidation level) calculation
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;
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
Serial.println("Beat!");
}
void setup()
{
Serial.begin(115200);
Serial.print("Initializing pulse oximeter..");
pinMode(Buzz, OUTPUT);
digitalWrite (Buzz, HIGH); //(No sound at starting)
// 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);
}
void loop()
{
temp = analogRead(temppin);
temp = temp * 0.48828125;
// 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("TEMPRATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.print("Heart rate:");
display.setTextColor(WHITE);
display.setCursor(87, 0);
display.print(pox.getHeartRate());
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("TEMPRATURE:");
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 > 40 || ((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();
}
}