Hi Everyone!
I'm making a health monitoring band in which it will detect temperature, heartbeat, and oxygen level
and I'm using max30100, Bmp280 and mlx90614 code is not working.. so can any one suggest me a proper code for this which will display reading on Oled screen. Also i have attached the circuit diagram which we already made but we need code according to the design.
Please Help Me CODERSS...
Here is the code! which i have, if someone can write down the new code for these sensor or modify this code that will be appreciated
#include <Wire.h>
#include "SparkFunBME280.h"
BME280 mySensor;
#include <Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
#include <Arduino.h>
#include <math.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_Address 0x3C
Adafruit_SSD1306 oled(1);
#include "MAX30100.h"
MAX30100* pulseOxymeter;
#include <SoftwareSerial.h>
SoftwareSerial BLE(2, 3); // RX, TX
const int btn_select = 10;
int btn_count = 1;
int time_hour = 22;
int time_mins = 49;
int counterDeciSec = 0;
int secInDeci = 60*10;
int minsInDeci = (1*10)10;//3000 deciseconds. // ((minssecs)*deciseconds) 1 min = 60 secs & 1 sec = 10 deciseconds.
int bpm=0.00, spo=0.00;
int pressure=0, alt_meter=0, bme_temp_c=0;
int mlx_object_f = 0;
boolean btn_pressed = false;
void setup() {
oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
// oled.setRotation(3);
oled.clearDisplay();
BLE.begin(9600);
Wire.begin();
if (mySensor.beginI2C() == false) //Begin communication over I2C
{
Serial.println("The sensor did not respond. Please check wiring.");
//while(1); //Freeze
}
Serial.begin(115200);
Serial.println("Pulse oxymeter test!");
pulseOxymeter = new MAX30100();
pinMode(4, OUTPUT);
//pulseOxymeter->printRegisters();
Serial.println("Adafruit MLX90614 test");
mlx.begin();
pinMode(btn_select, INPUT);
}
void loop() {
pulseoxymeter_t result = pulseOxymeter->update();
btn_select_read();
static unsigned long timer = millis();
static long int deciSeconds = 0;
if (millis() - timer >= 100) {
timer += 100;
deciSeconds++;
counterDeciSec++;
if(counterDeciSec == secInDeci){
counterDeciSec = 0;
time_mins++;
}
if(time_mins == 60){
time_mins = 0;
time_hour++;
}
if(time_hour == 24){
time_hour = 0;
}
if (deciSeconds == minsInDeci) {
deciSeconds = 0;
String value = ("" + String(bpm) +" " +String(spo) +" "+ String(pressure) +" "+ String(alt_meter) +" "+ String(bme_temp_c) +" "+ String(mlx_object_f) );
Serial.print(value);
BLE.print( value );
//BLE.print( spo );
//BLE.print( pressure );
//BLE.print( alt_meter );
//BLE.print( bme_temp_c );
//BLE.print( mlx_object_f );
}
}
if (btn_count == 1) {
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setTextSize(1);
oled.setRotation(0);
// oled.drawBitmap(-65, 0, imgClock, 128, 64, WHITE);
oled.setRotation(3);
oled.setCursor(5,66);
oled.println("--");
oled.setTextSize(2);
oled.setCursor(5,82);
oled.println(time_hour);
oled.setTextSize(1.5);
oled.setCursor(9,96);
oled.println("..");
oled.setTextSize(2);
oled.setCursor(5,108);
oled.println(time_mins);
oled.display();
oled.display();
}
else if (btn_count == 2) {
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setTextSize(1);
oled.setRotation(0);
// oled.drawBitmap(-65, 0, heartbeat, 128, 64, WHITE);
oled.setRotation(3);
oled.setCursor(5,66);
oled.println("--");
oled.setCursor(5,82);
oled.println(bpm);
oled.setTextSize(1.5);
oled.setCursor(8,108);
oled.println("BPM");
oled.display();
}
else if (btn_count == 3) {
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setTextSize(1);
oled.setRotation(0);
// oled.drawBitmap(-65, 0, oxygen, 128, 64, WHITE);
oled.setRotation(3);
oled.setCursor(5,66);
oled.println("--");
oled.setCursor(5,82);
oled.println(spo);
oled.setTextSize(1.5);
oled.setCursor(10,108);
oled.println("%");
oled.display();
}
else if (btn_count == 4) {
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setTextSize(1);
oled.setRotation(0);
// oled.drawBitmap(-65, 0, tempe, 128, 64, WHITE);
oled.setRotation(3);
oled.setCursor(5,66);
oled.println("--");
oled.setCursor(5,82);
oled.println(mlx_object_f);
oled.setTextSize(1.5);
oled.setCursor(10, 108);
oled.println("C");
oled.display();
}
else if (btn_count == 5) {
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setTextSize(1);
oled.setRotation(0);
// oled.drawBitmap(-65, 0, atmtemp, 128, 64, WHITE);
oled.setRotation(3);
oled.setCursor(5,66);
oled.println("--");
oled.setTextSize(1.5);
oled.setCursor(5,82);
oled.println(pressure);
oled.setTextSize(1.5);
oled.setCursor(9, 108);
oled.println("hPa");
oled.display();
}
else if (btn_count == 6) {
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setTextSize(1);
oled.setRotation(0);
// oled.drawBitmap(-65, 0, altitude, 128, 64, WHITE);
oled.setRotation(3);
oled.setCursor(5,66);
oled.println("--*");
oled.setCursor(5,82);
oled.println(alt_meter);
oled.setCursor(2, 108);
oled.println("meter");
oled.display();
}
else if (btn_count == 7) {
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setTextSize(1);
oled.setRotation(0);
// oled.drawBitmap(-65, 0, roomtemp, 128, 64, WHITE);
oled.setRotation(3);
oled.setCursor(5,66);
oled.println("--");
oled.setCursor(5,82);
oled.println(bme_temp_c);
oled.setTextSize(1.5);
oled.setCursor(9, 108);
oled.println("*C");
oled.display();
} else {}
//if( result.pulseDetected == true )
//{
bpm = result.heartBPM;
spo = result.SaO2;
Serial.print( "BPM: " );
Serial.print( bpm );
Serial.print( " | " );
Serial.print( "SaO2: " );
Serial.print( spo );
Serial.println( "%" );
//}
delay(10);
digitalWrite( 4, !digitalRead(2) );
pressure = ((mySensor.readFloatPressure())/100);
alt_meter = mySensor.readFloatAltitudeMeters();
bme_temp_c = mySensor.readTempC();
Serial.print(" Pressure: ");
Serial.println(pressure);
Serial.print(" Alt: ");
Serial.print(alt_meter);
Serial.print(" Temp: ");
Serial.println(bme_temp_c);
Serial.println();
mlx_object_f = mlx.readObjectTempC();
Serial.print("*Object = "); Serial.print(mlx_object_f); Serial.println("*C");
if(BLE.available() > 0)
{
String Incoming_value = ""; //Variable for storing Incoming_value
//while(BLE.available()){
Incoming_value = BLE.readString();
Serial.print(Incoming_value);
Serial.print("\n");
//}
String hr,mins;
hr = getStringPartByNr(Incoming_value, ':', 0);
mins = getStringPartByNr(Incoming_value, ':', 1);
time_hour = hr.toInt();
time_mins = mins.toInt();
Serial.println(getStringPartByNr(Incoming_value, ':', 2));
}
}
void btn_select_read(){
if (digitalRead(btn_select) == HIGH) {
if(btn_pressed == false){
btn_pressed = true;
btn_count++;
if (btn_count > 7) {
btn_count = 1;
}
}
}
else{
btn_pressed = false;
}
}
String getStringPartByNr(String data, char separator, int index)
{
int stringData = 0;
String dataPart = "";
for(int i = 0; i<data.length()-1; i++) {
if(data*==separator) {*
-
stringData++;*
-
}else if(stringData==index) {*
_ dataPart.concat(data*);*_
* }else if(stringData>index) {*
* return dataPart;*
* break;*
* }*
* }*
* return dataPart;*
}