Arduino Oled code help needed

Hey,
Somehow i made a MAX30100 and DS18B20 sensor work together but i want to interface the serial monitor on the oled screen, please help

This is my code -

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"

#define REPORTING_PERIOD_MS 1000

PulseOximeter pox;

uint32_t tsLastReport = 0;

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

DeviceAddress tempDeviceAddress;

int resolution = 12;
unsigned long lastTempRequest = 0;
int delayInMillis = 0;
float temperature = 0.0;
int idle = 0;

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

pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

pox.setOnBeatDetectedCallback(onBeatDetected);
}

void setup(void)
{
Serial.begin(9600);
Serial.println("Dallas Temperature Control Library - Async Demo");
Serial.print("Library Version: ");
Serial.println(DALLASTEMPLIBVERSION);
Serial.println("\n");

sensors.begin();
sensors.getAddress(tempDeviceAddress, 0);
sensors.setResolution(tempDeviceAddress, resolution);

sensors.setWaitForConversion(false);
sensors.requestTemperatures();
delayInMillis = 750 / (1 << (12 - resolution));
lastTempRequest = millis();

pinMode(13, OUTPUT);

Serial.print("Initializing pulse oximeter..");
Wire.setClock(400000UL);

if (!pox.begin()) {
Serial.println("FAILED");
for (;;);
} else {
Serial.println("SUCCESS");
}

configureMax30100();
}

void loop(void)
{

if (millis() - lastTempRequest >= 2000)
{

Serial.print(" Temperature: ");
temperature = sensors.getTempCByIndex(0);
Serial.println(temperature, resolution - 8);
Serial.println();

idle = 0;


resolution++;
if (resolution > 12) resolution = 9;

sensors.setResolution(tempDeviceAddress, resolution);
sensors.requestTemperatures();
delayInMillis = 750 / (1 << (12 - resolution));
lastTempRequest = millis();

}

delay(1);
idle++;

pox.update();

if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");

tsLastReport = millis();

}
}

#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <SPI.h>
#include <wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define REPORTING_PERIOD_MS 1000

PulseOximeter pox;

uint32_t tsLastReport = 0;

#define ONE_WIRE_BUS 2
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

DeviceAddress tempDeviceAddress;

int resolution = 12;
unsigned long lastTempRequest = 0;
int delayInMillis = 0;
float temperature = 0.0;
float heartRate = 0.0;
int idle = 0;

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

pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

pox.setOnBeatDetectedCallback(onBeatDetected);
}

void setup(void)
{
Serial.begin(9600);
Serial.println("Dallas Temperature Control Library - Async Demo");
Serial.print("Library Version: ");
Serial.println(DALLASTEMPLIBVERSION);
Serial.println("");
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();

sensors.begin();
sensors.getAddress(tempDeviceAddress, 0);
sensors.setResolution(tempDeviceAddress, resolution);

sensors.setWaitForConversion(false);
sensors.requestTemperatures();
delayInMillis = 750 / (1 << (12 - resolution));
lastTempRequest = millis();

pinMode(13, OUTPUT);

Serial.print("Initializing pulse oximeter..");
Wire.setClock(400000UL);

if (!pox.begin()) {
Serial.println("FAILED");
for (;;);
} else {
Serial.println("SUCCESS");
}

configureMax30100();
}

void loop(void)
{
if (millis() - lastTempRequest >= 2000)
{

Serial.print(" Temperature: ");
temperature = sensors.getTempCByIndex(0);
Serial.println(temperature, resolution - 8);
Serial.println();

idle = 0;


resolution++;
if (resolution > 12) resolution = 9;

sensors.setResolution(tempDeviceAddress, resolution);
sensors.requestTemperatures();
delayInMillis = 750 / (1 << (12 - resolution));
lastTempRequest = millis();

}

delay(1);
idle++;

pox.update();

if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
heartRate = pox.getHeartRate();

Serial.print("Heart rate:");
Serial.print(heartRate);
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");

tsLastReport = millis();

}

display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("Temperature: ");
display.print(temperature, resolution - 8);
display.println(" C");
display.display();
}

I tried this code but the MAX30100 stopped working

I moved your topic to an appropriate forum category @kartik_sakhuja.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.