I'm using Arduino NANO, MAX30100(purple), OLED SSD1306 for showing the values, RTC DS3231 and SD Card Module for datalogging the values. Values of the pulseoximeter sensor are high even if there's no finger placed. im thinking its because all three I2C devices(RTC,OLED,PULSE) are connected in A4(SDA), A5(SCL). Some folks said i should use pull up resistors, where would i put the resistors and what size? and would it fix the problem?
#include <Wire.h>
#include <SSD1306AsciiWire.h>
#include <SD.h>
#include <RTClib.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 3000
PulseOximeter pox;
SSD1306AsciiWire display;
TwoWire myWire = TwoWire();
RTC_DS3231 rtc;
File dataFile;
void onBeatDetected() {
Serial.println("Beat!");
float heartRate = pox.getHeartRate();
float spO2 = pox.getSpO2();
Serial.print("BPM: ");
Serial.print(heartRate);
Serial.print(", SpO2: ");
Serial.println(spO2);
}
void setup() {
Serial.begin(115200);
myWire.begin();
display.begin(&Adafruit128x64, 0x3C);
display.setFont(System5x7);
display.set2X();
pinMode(SS, OUTPUT);
if (!SD.begin(10)) {
Serial.println("SD card initialization failed!");
while (1);
}
if (!rtc.begin()) {
Serial.println("RTC initialization failed!");
while (1);
}
{
Serial.print("Initializing pulse oximeter..");
// Initialize sensor
if (!pox.begin()) {
Serial.println("FAILED");
for (;;);
} else {
Serial.println("SUCCESS");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
pox.begin();
pox.setOnBeatDetectedCallback(onBeatDetected);
}
}
void loop() {
static uint32_t tsLastReport = 0;
pox.update();
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
float heartRate = pox.getHeartRate();
float spO2 = pox.getSpO2();
String heartRate_string = String(heartRate, 2);
String spO2_string = String(spO2, 2);
display.clear();
display.setCursor(0, 0);
display.println("BPM: " + heartRate_string);
display.setCursor(0, 2);
display.println("SpO2: " + spO2_string);
display.displayRows();
// Log the data to SD card with current date and time from RTC
DateTime now = rtc.now();
String date_string = String(now.month()) + "/" + String(now.day()) + "/" + String(now.year());
String time_string = String(now.hour()) + ":" + String(now.minute()) + ":" + String(now.second());
String data = date_string + "," + time_string + ",BPM:" + heartRate_string + ",SpO2:" + spO2_string + "\n";
dataFile = SD.open("data.txt", FILE_WRITE);
if (dataFile) {
dataFile.print(data);
dataFile.close();
}
tsLastReport = millis();
}
}
