Sketch for the mlx90614 with oled:
#include <DFRobot_MLX90614.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//sda A4 scl a5
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
DFRobot_MLX90614_I2C sensor; // instantiate an object to drive our sensor
void setup()
{
Serial.begin(115200);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
// initialize the sensor
while( NO_ERR != sensor.begin() ){
Serial.println("Communication with device failed, please check connection");
delay(3000);
}
Serial.println("Begin ok!");
/**
* adjust sensor sleep mode
* mode select to enter or exit sleep mode, it's enter sleep mode by default
* true is to enter sleep mode
* false is to exit sleep mode (automatically exit sleep mode after power down and restart)
*/
sensor.enterSleepMode();
delay(50);
sensor.enterSleepMode(false);
delay(200);
sensor.setEmissivityCorrectionCoefficient(1);
float ambientTemp = sensor.getAmbientTempCelsius();
float objectTemp = sensor.getObjectTempCelsius();
}
void loop()
{
/**
* get ambient temperature, unit is Celsius
* return value range: -40 C ~ 85 C
*/
float ambientTemp = sensor.getAmbientTempCelsius();
/**
* get temperature of object 1, unit is Celsius
* return value range: -40 C ~ 85 C
*/
float objectTemp = sensor.getObjectTempCelsius();
// print measured data in Celsius
Serial.print("Ambient celsius : "); Serial.print(ambientTemp); Serial.println(" C");
Serial.print("Object celsius : "); Serial.print(objectTemp); Serial.println(" C");
display.clearDisplay();
// display R G B Values
display.setTextSize(2);
display.setCursor(0,0);
display.print("Temp:");
display.setTextSize(3);
display.setCursor(0, 28);
display.print(objectTemp);
display.setTextSize(1);
display.setCursor(0, 56);
display.print("electroniclinic.com");
display.display();
// print measured data in Fahrenheit
Serial.print("Ambient fahrenheit : "); Serial.print(ambientTemp*9/5 + 32); Serial.println(" F");
Serial.print("Object fahrenheit : "); Serial.print(objectTemp*9/5 + 32); Serial.println(" F");
delay(1000);
}
Sketch for the max30100 with oled:
#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);
Serial.print("Initializing pulse oximeter..");
oled.begin();
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(1);
oled.setCursor(0, 0);
oled.println("Initializing pulse oximeter..");
oled.display();
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.println("%");
oled.display();
tsLastReport = millis();
}
}
sketch for the tow sensors together with the oled:
#include <Wire.h>
#include <MAX30100_PulseOximeter.h>
#include <DFRobot_MLX90614.h>
#include <OakOLED.h>
// OLED display and pulse oximeter objects
OakOLED oled;
PulseOximeter pox;
DFRobot_MLX90614_I2C mlx;
// Reporting period in milliseconds
#define REPORTING_PERIOD_MS 1000
void setup() {
// Initialize serial communication and OLED display
Serial.begin(9600);
mlx.begin();
oled.begin();
pox.begin();
// // Initialize the pulse oximeter sensor
// Serial.println("Initializing pulse oximeter...");
// if (!pox.begin()) {
// Serial.println("Failed to initialize pulse oximeter!");
// for (;;); // Stop the program if initialization fails
// }
// // // Initialize the MLX90614 temperature sensor
// if (!mlx.begin()) {
// Serial.println("Failed to initialize MLX90614 temperature sensor!");
// for (;;); // Stop the program if initialization fails
// }
}
void loop() {
// Update the pulse oximeter and check if it's time to report SPO2 values
pox.update();
static uint32_t tsLastReport = 0;
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
// Print the SPO2 values to the serial monitor and OLED display
Serial.print("Heart BPM: ");
Serial.print(pox.getHeartRate());
Serial.print(" ----- Oxygen Percent: ");
Serial.println(pox.getSpO2());
oled.clearDisplay();
oled.setCursor(0, 0);
oled.print("BPM: ");
oled.print(pox.getHeartRate());
oled.setCursor(0, 15);
oled.print("SPO2: ");
oled.print(pox.getSpO2());
// Read and print the temperature from the MLX90614 sensor
float temp = mlx.getObjectTempCelsius();
Serial.print(" ----- Temperature: ");
Serial.println(temp);
oled.setCursor(0, 30);
oled.print("TEMP: ");
oled.print((temp));
oled.display();
tsLastReport = millis(); // reset the timer
}
}