Hey! First time ever writing in a forum, i am really in a pickle...
It's my first project with an Arduino UNO and im trying to build a heart rate reader that would then display messages depending on the heart rate values, but first im just trying to program it so it gives the normal heart rate, i have tested both devices on separate examples from libraries and they work , the OLED Display 7 pin SPI , and the MAX30100 Pulse Oximeter I2C , my problem is in the code, i have gotten to this point were i got this code to work whenever i take out line 67 : Pox.update(). Leaving me with a screen stuck on "Initializing..." . But whenever i run the full code which i would expect wo work i get the message "SSD1306 Allocation Failed"
Any clue why this happens ? im very lost.
#include <SPI.h>
#include <Wire.h> // For I2C communication
#include <Adafruit_GFX.h> // Graphics library
#include <Adafruit_SSD1306.h> // OLED display library
#include <CircularBuffer.h>
#include <MAX30100.h>
#include <MAX30100_BeatDetector.h>
#include <MAX30100_Filters.h>
#include <MAX30100_PulseOximeter.h>
#include <MAX30100_Registers.h>
#include <MAX30100_SpO2Calculator.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_MOSI SDA
#define OLED_CLK SCL
#define OLED_DC 9
#define OLED_CS 10
#define OLED_RESET 8
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI,
OLED_DC, OLED_RESET, OLED_CS);
PulseOximeter pox;
uint32_t tsLastReport = 0;
#define REPORTING_PERIOD_MS 1000
void onBeatDetected() {
Serial.println("Beat!!!");
}
void setup() {
Serial.begin(115200);
// Initialize the OLED display
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3d)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println("Initializing...");
display.display();
if (!pox.begin()) {
Serial.println("FAILED");
for (;;);
} else {
Serial.println("SUCCESS");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop() {
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
display.clearDisplay();
display.setCursor(0, 0);
display.print("BPM : ");
display.print(pox.getHeartRate());
display.setCursor(0, 10);
display.print("SpO2: ");
display.print(pox.getSpO2());
display.print("%");
display.display();
tsLastReport = millis();
}
}