Skip to content

Commit 89484e3

Browse files
author
Elias Santistevan
committed
Renames the example code, adds the second mode for the maximFast algorithm in second example code
1 parent 319fdab commit 89484e3

File tree

6 files changed

+128
-22
lines changed

6 files changed

+128
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
This example sketch gives you exactly what the SparkFun Pulse Oximiter and
3+
Heart Rate Monitor is designed to do: read heart rate and blood oxygen levels.
4+
This board requires I-squared-C connections but also connections to the reset
5+
and mfio pins. When using the device keep LIGHT and CONSISTENT pressure on the
6+
sensor. Otherwise you may crush the capillaries in your finger which results
7+
in bad or no results. This differs from example one by giving an additional
8+
two data points: an extended finger status and the r value of the blood oxygen
9+
level. A summary of the hardware connections are as follows:
10+
SDA -> SDA
11+
SCL -> SCL
12+
RESET -> PIN 4
13+
MFIO -> PIN 5
14+
15+
Author: Elias Santistevan
16+
Date: 8/2019
17+
SparkFun Electronics
18+
19+
If you run into an error code check the following table to help diagnose your
20+
problem:
21+
1 = Unavailable Command
22+
2 = Unavailable Function
23+
3 = Data Format Error
24+
4 = Input Value Error
25+
5 = Try Again
26+
255 = Error Unknown
27+
*/
28+
29+
#include <SparkFun_Bio_Sensor_Hub_Library.h>
30+
#include <Wire.h>
31+
32+
// No other Address options.
33+
#define DEF_ADDR 0x55
34+
35+
// Reset pin, MFIO pin
36+
const int resPin = 4;
37+
const int mfioPin = 5;
38+
39+
// Takes address, reset pin, and MFIO pin.
40+
SparkFun_Bio_Sensor_Hub bioHub(DEF_ADDR, resPin, mfioPin);
41+
42+
bioData body;
43+
// ^^^^^^^^^
44+
// What's this!? This is a type (like int, byte, long) unique to the SparkFun
45+
// Pulse Oximeter and Heart Rate Monitor. Unlike those other types it holds
46+
// specific information on your heartrate and blood oxygen levels. BioData is
47+
// actually a specific kind of type, known as a "struct".
48+
// You can choose another variable name other than "body", like "blood", or
49+
// "readings", but I chose "body". Using this "body" varible in the
50+
// following way gives us access to the following data:
51+
// body.heartrate - Heartrate
52+
// body.confidence - Confidence in the heartrate value
53+
// body.oxygen - Blood oxygen level
54+
// body.status - Has a finger been sensed?
55+
// body.extStatus - What else is the finger up to?
56+
// body.rValue - Blood oxygen correlation coefficient.
57+
58+
59+
void setup(){
60+
61+
Serial.begin(115200);
62+
63+
Wire.begin();
64+
int result = bioHub.begin();
65+
if (!result)
66+
Serial.println("Sensor started!");
67+
else
68+
Serial.println("Could not communicate with the sensor!!!");
69+
70+
Serial.println("Configuring Sensor....");
71+
int error = bioHub.configBpm(MODE_TWO); // Configuring just the BPM settings.
72+
if(!error){
73+
Serial.println("Sensor configured.");
74+
}
75+
else {
76+
Serial.println("Error configuring sensor.");
77+
Serial.print("Error: ");
78+
Serial.println(error);
79+
}
80+
81+
// Data lags a bit behind the sensor, if you're finger is on the sensor when
82+
// it's being configured this delay will give some time for the data to catch
83+
// up.
84+
delay(4000);
85+
86+
}
87+
88+
void loop(){
89+
90+
// Information from the readBpm function will be saved to our "body"
91+
// variable.
92+
body = bioHub.readBpm();
93+
Serial.print("Heartrate: ");
94+
Serial.println(body.heartRate);
95+
Serial.print("Confidence: ");
96+
Serial.println(body.confidence);
97+
Serial.print("Oxygen: ");
98+
Serial.println(body.oxygen);
99+
Serial.print("Status: ");
100+
Serial.println(body.status);
101+
Serial.print("Extended Status: ");
102+
Serial.println(body.extStatus);
103+
Serial.print("Blood Oxygen R value: ");
104+
Serial.println(body.rValue);
105+
delay(250); // Slowing it down, we don't need to break our necks here.
106+
}

Examples/Example3_modifyAGCalgo/Example3_modifyAGCalgo.ino renamed to Examples/Example3_modify_AGC_Algo/Example3_modify_AGC_Algo.ino

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
pulse width and current consumption of the MAX30101's LEDs as it gathers data
66
on light absorption. This particular setting is enabled when calling
77
"configBpm" and so in this example we demonstrate how to modify the algorithm.
8-
98
SDA -> SDA
109
SCL -> SCL
1110
RESET -> PIN 4

Examples/Example2_adjustLEDvalues/Example2_adjustLEDvalues.ino renamed to Examples/Example4_config_LEDs_BPM/Example4_config_LEDs_BPM.ino

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
that can be gathered, so we'll adjust this value as well. In addition we
66
gather additional data from the bioData type: LED samples. This data gives
77
the number of samples gathered by the MAX30101 for both the red and IR LEDs.
8+
As a side note you can also choose MODE_ONE and MODE_TWO for configSensorBpm
9+
as well.
810
A summary of the hardware connections are as follows:
911
SDA -> SDA
1012
SCL -> SCL
@@ -74,7 +76,7 @@ void setup(){
7476
Serial.println("Sensor started!");
7577

7678
Serial.println("Configuring Sensor....");
77-
int error = bioHub.configSensorBpm(); // Configure Sensor and BPM mode
79+
int error = bioHub.configSensorBpm(MODE_ONE); // Configure Sensor and BPM mode , MODE_TWO also available
7880
if(!error){
7981
Serial.println("Sensor configured.");
8082
}

src/SparkFun_Bio_Sensor_Hub_Library.cpp

+17-18
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ bioData SparkFun_Bio_Sensor_Hub::readBpm(){
209209

210210
numSamplesOutFifo();
211211

212-
if (_userSelectedMode = MODE_ONE) {
212+
if (_userSelectedMode == MODE_ONE) {
213213

214214
readFillArray(READ_DATA_OUTPUT, READ_DATA, MAXFAST_ARRAY_SIZE, bpmArr);
215215

@@ -232,8 +232,7 @@ bioData SparkFun_Bio_Sensor_Hub::readBpm(){
232232
return libBpm;
233233
}
234234

235-
else if (_userSelectedMode = MODE_TWO) {
236-
235+
else if (_userSelectedMode == MODE_TWO) {
237236
readFillArray(READ_DATA_OUTPUT, READ_DATA,\
238237
MAXFAST_ARRAY_SIZE + MAXFAST_EXTENDED_DATA, bpmArrTwo);
239238

@@ -248,15 +247,16 @@ bioData SparkFun_Bio_Sensor_Hub::readBpm(){
248247
//Blood oxygen level formatting
249248
libBpm.oxygen = uint16_t(bpmArrTwo[3]) << 8;
250249
libBpm.oxygen |= bpmArrTwo[4];
251-
libBpm.oxygen /= 10;
250+
libBpm.oxygen /= 10.0;
252251

253252
//"Machine State" - has a finger been detected?
254253
libBpm.status = bpmArrTwo[5];
255254

256255
//Sp02 r Value formatting
257-
libBpm.rValue = uint16_t(bpmArrTwo[6]) << 8;
258-
libBpm.rValue |= bpmArrTwo[7];
259-
libBpm.rValue /= 10;
256+
uint16_t tempVal = uint16_t(bpmArrTwo[6]) << 8;
257+
tempVal |= bpmArrTwo[7];
258+
libBpm.rValue = tempVal;
259+
libBpm.rValue /= 10.0;
260260

261261
//Extended Machine State formatting
262262
libBpm.extStatus = bpmArrTwo[8];
@@ -375,8 +375,9 @@ bioData SparkFun_Bio_Sensor_Hub::readSensorBpm(){
375375
libLedBpm.status = bpmSenArr[17];
376376

377377
//Sp02 r Value formatting
378-
libLedBpm.rValue = uint16_t(bpmArrTwo[18]) << 8;
379-
libLedBpm.rValue |= bpmArrTwo[19];
378+
uint16_t tempVal = uint16_t(bpmArrTwo[6]) << 8;
379+
tempVal |= bpmArrTwo[7];
380+
libLedBpm.rValue = tempVal;
380381
libLedBpm.rValue /= 10;
381382

382383
//Extended Machine State formatting
@@ -1031,7 +1032,6 @@ bool SparkFun_Bio_Sensor_Hub::eraseFlash() {
10311032

10321033
}
10331034

1034-
// Family Byte: BOOTLOADER_FLASH (0x80), Index Byte: SEND_PAGE_VALUE (0x04)
10351035
// Family Byte: BOOTLOADER_INFO (0x81), Index Byte: BOOTLOADER_VERS (0x00)
10361036
version SparkFun_Bio_Sensor_Hub::readBootloaderVers(){
10371037

@@ -1044,7 +1044,7 @@ version SparkFun_Bio_Sensor_Hub::readBootloaderVers(){
10441044

10451045
_i2cPort->requestFrom(_address, static_cast<uint8_t>(4));
10461046
uint8_t statusByte = _i2cPort->read();
1047-
if (!statusByte) { // Pass through if SUCCESS (0x00).
1047+
if (statusByte) { // Pass through if SUCCESS (0x00).
10481048
booVers.major = 0;
10491049
booVers.minor = 0;
10501050
booVers.revision = 0;
@@ -1059,20 +1059,19 @@ version SparkFun_Bio_Sensor_Hub::readBootloaderVers(){
10591059

10601060
}
10611061

1062-
// Family Byte: BOOTLOADER_INFO (0x81), Index Byte: PAGE_SIZE (0x01)
10631062
// Family Byte: IDENTITY (0xFF), Index Byte: READ_SENSOR_HUB_VERS (0x03)
10641063
version SparkFun_Bio_Sensor_Hub::readSensorHubVersion(){
10651064

10661065
version bioHubVers;
10671066
_i2cPort->beginTransmission(_address);
1068-
_i2cPort->write(BOOTLOADER_INFO);
1069-
_i2cPort->write(BOOTLOADER_VERS);
1067+
_i2cPort->write(IDENTITY);
1068+
_i2cPort->write(READ_SENSOR_HUB_VERS);
10701069
_i2cPort->endTransmission();
10711070
delay(CMD_DELAY);
10721071

10731072
_i2cPort->requestFrom(_address, static_cast<uint8_t>(4));
10741073
uint8_t statusByte = _i2cPort->read();
1075-
if (!statusByte){ // Pass through if SUCCESS (0x00).
1074+
if (statusByte){ // Pass through if SUCCESS (0x00).
10761075
bioHubVers.major = 0;
10771076
bioHubVers.minor = 0;
10781077
bioHubVers.revision = 0;
@@ -1092,14 +1091,14 @@ version SparkFun_Bio_Sensor_Hub::readAlgorithmVersion(){
10921091

10931092
version libAlgoVers;
10941093
_i2cPort->beginTransmission(_address);
1095-
_i2cPort->write(BOOTLOADER_INFO);
1096-
_i2cPort->write(BOOTLOADER_VERS);
1094+
_i2cPort->write(IDENTITY);
1095+
_i2cPort->write(READ_ALGO_VERS);
10971096
_i2cPort->endTransmission();
10981097
delay(CMD_DELAY);
10991098

11001099
_i2cPort->requestFrom(_address, static_cast<uint8_t>(4));
11011100
uint8_t statusByte = _i2cPort->read();
1102-
if (!statusByte){ // Pass through if SUCCESS (0x00).
1101+
if (statusByte){ // Pass through if SUCCESS (0x00).
11031102
libAlgoVers.major = 0;
11041103
libAlgoVers.minor = 0;
11051104
libAlgoVers.revision = 0;

src/SparkFun_Bio_Sensor_Hub_Library.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ struct bioData {
4343
uint8_t confidence; // 0-100% LSB = 1%
4444
uint16_t oxygen; // 0-100% LSB = 1%
4545
uint8_t status; // 0: Success, 1: Not Ready, 2: Object Detectected, 3: Finger Detected
46-
uint16_t rValue; // -- Algorithm Mode 2 vv
47-
uint8_t extStatus; // --
46+
float rValue; // -- Algorithm Mode 2 vv
47+
int8_t extStatus; // --
4848
uint8_t reserveOne; // --
4949
uint8_t resserveTwo; // -- Algorithm Mode 2 ^^
5050

0 commit comments

Comments
 (0)