Skip to content

Instantly share code, notes, and snippets.

@weldtype
Created May 19, 2017 17:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save weldtype/2238cd134b9a2d1239c8859447551679 to your computer and use it in GitHub Desktop.
Save weldtype/2238cd134b9a2d1239c8859447551679 to your computer and use it in GitHub Desktop.
// MAX30100 test
// 2017/05/16 edy
// 2017/05/17
// LED current 4.4mAに変更
// onBeatDetected() 変更
// 脈拍値 整数型に変更
// REPORTING_PERIOD_MS 2000に変更
/*
Arduino-MAX30100 oximetry / heart rate integrated sensor library
Copyright (C) 2016 OXullo Intersecans <x@brainrapers.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 2000
// PulseOximeter is the higher level interface to the sensor
// it offers:
// * beat detection reporting
// * heart rate calculation
// * SpO2 (oxidation level) calculation
PulseOximeter pox;
uint32_t tsLastReport = 0;
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
//Serial.println("Beat!");
digitalWrite(13, HIGH);
delay(10);
digitalWrite(13, LOW);
}
void setup()
{
pinMode(13,OUTPUT);
Serial.begin(115200);
Serial.print("Initializing pulse oximeter..");
// Initialize the PulseOximeter instance
// Failures are generally due to an improper I2C wiring, missing power supply
// or wrong target chip
if (!pox.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
// The default current for the IR LED is 50mA and it could be changed
// by uncommenting the following line. Check MAX30100_Registers.h for all the
// available options.
/*
MAX30100_LED_CURR_0MA = 0x00,
MAX30100_LED_CURR_4_4MA = 0x01,
MAX30100_LED_CURR_7_6MA = 0x02,
MAX30100_LED_CURR_11MA = 0x03,
MAX30100_LED_CURR_14_2MA = 0x04,
MAX30100_LED_CURR_17_4MA = 0x05,
MAX30100_LED_CURR_20_8MA = 0x06,
MAX30100_LED_CURR_24MA = 0x07,
MAX30100_LED_CURR_27_1MA = 0x08,
MAX30100_LED_CURR_30_6MA = 0x09,
MAX30100_LED_CURR_33_8MA = 0x0a,
MAX30100_LED_CURR_37MA = 0x0b,
MAX30100_LED_CURR_40_2MA = 0x0c,
MAX30100_LED_CURR_43_6MA = 0x0d,
MAX30100_LED_CURR_46_8MA = 0x0e,
MAX30100_LED_CURR_50MA = 0x0f
*/
pox.setIRLedCurrent(MAX30100_LED_CURR_4_4MA);
// Register a callback for the beat detection
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop()
{
// Make sure to call update as fast as possible
pox.update();
// Asynchronously dump heart rate and oxidation levels to the serial
// For both, a value of 0 means "invalid"
if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
Serial.print("Heart rate:");
Serial.print((int)pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.print("% / temp:");
Serial.print(pox.getTemperature());
Serial.println("C");
tsLastReport = millis();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment