Trouble in BME class

I'm making a pulse oximeter for my first project in university. The sensor work fine, the problem is the result do not show on my oled screen. I'm using a sh1106 oled screen. this is my code

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
 
#include "Wire.h"
#include "Adafruit_GFX.h"
#include "OakOLED.h"
#define REPORTING_PERIOD_MS 1000
OakOLED oled;
 
PulseOximeter pox;
 
uint32_t tsLastReport = 0;
 
const unsigned char bitmap [] PROGMEM=
{
0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x18, 0x00, 0x0f, 0xe0, 0x7f, 0x00, 0x3f, 0xf9, 0xff, 0xc0,
0x7f, 0xf9, 0xff, 0xc0, 0x7f, 0xff, 0xff, 0xe0, 0x7f, 0xff, 0xff, 0xe0, 0xff, 0xff, 0xff, 0xf0,
0xff, 0xf7, 0xff, 0xf0, 0xff, 0xe7, 0xff, 0xf0, 0xff, 0xe7, 0xff, 0xf0, 0x7f, 0xdb, 0xff, 0xe0,
0x7f, 0x9b, 0xff, 0xe0, 0x00, 0x3b, 0xc0, 0x00, 0x3f, 0xf9, 0x9f, 0xc0, 0x3f, 0xfd, 0xbf, 0xc0,
0x1f, 0xfd, 0xbf, 0x80, 0x0f, 0xfd, 0x7f, 0x00, 0x07, 0xfe, 0x7e, 0x00, 0x03, 0xfe, 0xfc, 0x00,
0x01, 0xff, 0xf8, 0x00, 0x00, 0xff, 0xf0, 0x00, 0x00, 0x7f, 0xe0, 0x00, 0x00, 0x3f, 0xc0, 0x00,
0x00, 0x0f, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
 
void onBeatDetected()
{
Serial.println("Beat!");
oled.drawBitmap( 60, 20, bitmap, 28, 28, 1);
oled.display();
}
 
void setup()
{
Serial.begin(9600);
 
oled.begin();
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 0);
 
oled.println("Initializing pulse oximeter..");
oled.display();
Serial.print("Initializing pulse oximeter..");
 
if (!pox.begin()) {
Serial.println("FAILED");
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 0);
oled.println("FAILED");
oled.display();
for(;;);
} else {
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 0);
oled.println("SUCCESS");
oled.display();
Serial.println("SUCCESS");
}
pox.setOnBeatDetectedCallback(onBeatDetected);
}
 
void loop()
{
pox.update();
 
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart BPM:");
Serial.print(pox.getHeartRate());
Serial.print("-----");
Serial.print("Oxygen Percent:");
Serial.print(pox.getSpO2());
Serial.println("\n");
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0,16);
oled.println(pox.getHeartRate());
 
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 0);
oled.println("Heart BPM");
 
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 30);
oled.println("Spo2");
 
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0,45);
oled.println(pox.getSpO2());
oled.display();
tsLastReport = millis();
}
}

The two SCL and SDA pin of the oled screen is correctly connected to the 2 pin above the AREF pin. I'm using an Arduino Uno R3

Please post a wiring diagram, as the description does not make sense. Hand drawn is fine, as long as pins, parts and connections are clearly labeled.

Please describe what you expected to happen, and what happened instead.

Reverse the order? Or, use A4 (DATA) and A5 (CLOCK).
20231231_201441

before trying to dive into the code, have you tried any example code for the oled screen to ensure it's working as expected?

i have tested the oled with example code, and it worked

OK so at least you know the wiring is fine.

if you remove the display from this function

void onBeatDetected()
{
Serial.println("Beat!");
oled.drawBitmap( 60, 20, bitmap, 28, 28, 1);
oled.display();
}

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

do you see anything ?

can i hook up the oled and the sensor to those 2 pins simultaneously?

still no display, just a bunch of distorted gibberish

I2C is a bus, so in theory yes. you might need to look at pullup resistors and the exact specs of your sensor. Is it a 5V sensor ?

can you post the exact circuit and power and links to the components

it's a 5v sensor. and i dont know how to draw a schematic, i usually use tinkercad and fritzing to draw my schematic, but i cant find the part im using on them. Here is my sensor: MAX30100 Heart Rate Oxygen Pulse Sensor Pinout, features, datasheet, working, applications (components101.com).
Here is my oled: 1.3 inch OLED Display 128*64 pixels white - I2C - I2C1.3OLEDWHITE (tinytronics.nl)

a pencil, a ruler and a piece of paper :slight_smile:
parts don't need to look good, just use standard representations or just rectangles with the pin names / numbers you use


the link you provided states>

  1. Operating Voltage - 1.8V to 3.3V

they also say

As part of the communication protocol, two pins which are the SCL and SDA are connected to the Arduino’s A5 and A4 pins, respectively. The INT pin on the module is also connected to the microcontroller’s Digital Pin 2 to check if the heartbeat is captured properly

a voltage level shifter for this component might be needed.

omg i realized what may be the problem. My oled i has a sh1106 driver and the oak oled lib is for ssd1306

i have to use apps cause my hands are defected, i cant hold a pen

OK - understood

the listing of the place i bought the oled said that it's a ssd1306 oled

you said

so seems you have the right library

i have 2 libs for oled and i use the adafruit lib for testing. Not sure why i did that.

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