Skip to content

Commit 93aedf8

Browse files
authored
Merge pull request #24 from sparkfun/v1.0.6
v1.0.6 : allow pins to be defined at begin instead of at class instantiation
2 parents b6bcd7a + d4e797b commit 93aedf8

File tree

6 files changed

+150
-13
lines changed

6 files changed

+150
-13
lines changed

examples/Example1_config_BPM_Mode1/Example1_config_BPM_Mode1.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void setup(){
5858
if (result == 0) // Zero errors!
5959
Serial.println("Sensor started!");
6060
else
61-
Serial.println("Could not communicate with the sensor!!!");
61+
Serial.println("Could not communicate with the sensor!");
6262

6363
Serial.println("Configuring Sensor....");
6464
int error = bioHub.configBpm(MODE_ONE); // Configuring just the BPM settings.

examples/Example2_config_BPM_Mode2/Example2_config_BPM_Mode2.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void setup(){
6262
if (result == 0) //Zero errors!
6363
Serial.println("Sensor started!");
6464
else
65-
Serial.println("Could not communicate with the sensor!!!");
65+
Serial.println("Could not communicate with the sensor!");
6666

6767
Serial.println("Configuring Sensor....");
6868
int error = bioHub.configBpm(MODE_TWO); // Configuring just the BPM settings.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
5+
Here the reset and mfio pins are defined at begin, instead of when the
6+
SparkFun_Bio_Sensor_Hub is instantiated. This makes it much easier to
7+
instantiate the class using a factory method.
8+
9+
This board requires I-squared-C connections but also connections to the reset
10+
and mfio pins. When using the device keep LIGHT and CONSISTENT pressure on the
11+
sensor. Otherwise you may crush the capillaries in your finger which results
12+
in bad or no results. A summary of the hardware connections are as follows:
13+
SDA -> SDA
14+
SCL -> SCL
15+
RESET -> PIN 4
16+
MFIO -> PIN 5
17+
18+
Author: Elias Santistevan
19+
Date: 8/2019
20+
SparkFun Electronics
21+
22+
If you run into an error code check the following table to help diagnose your
23+
problem:
24+
1 = Unavailable Command
25+
2 = Unavailable Function
26+
3 = Data Format Error
27+
4 = Input Value Error
28+
5 = Try Again
29+
255 = Error Unknown
30+
*/
31+
32+
#include <SparkFun_Bio_Sensor_Hub_Library.h>
33+
#include <Wire.h>
34+
35+
// Reset pin, MFIO pin
36+
int resPin = 4;
37+
int mfioPin = 5;
38+
39+
// The reset pin and MFIO pin will be defined at begin in this example.
40+
SparkFun_Bio_Sensor_Hub bioHub;
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+
56+
57+
void setup(){
58+
59+
Serial.begin(115200);
60+
61+
Wire.begin();
62+
int result = bioHub.begin(Wire, resPin, mfioPin); // Define the pins here
63+
if (result == 0) // Zero errors!
64+
Serial.println("Sensor started!");
65+
else
66+
Serial.println("Could not communicate with the sensor!");
67+
68+
Serial.println("Configuring Sensor....");
69+
int error = bioHub.configBpm(MODE_ONE); // Configuring just the BPM settings.
70+
if(error == 0){ // Zero errors!
71+
Serial.println("Sensor configured.");
72+
}
73+
else {
74+
Serial.println("Error configuring sensor.");
75+
Serial.print("Error: ");
76+
Serial.println(error);
77+
}
78+
79+
// Data lags a bit behind the sensor, if you're finger is on the sensor when
80+
// it's being configured this delay will give some time for the data to catch
81+
// up.
82+
Serial.println("Loading up the buffer with data....");
83+
delay(4000);
84+
85+
}
86+
87+
void loop(){
88+
89+
// Information from the readBpm function will be saved to our "body"
90+
// variable.
91+
body = bioHub.readBpm();
92+
Serial.print("Heartrate: ");
93+
Serial.println(body.heartRate);
94+
Serial.print("Confidence: ");
95+
Serial.println(body.confidence);
96+
Serial.print("Oxygen: ");
97+
Serial.println(body.oxygen);
98+
Serial.print("Status: ");
99+
Serial.println(body.status);
100+
// Slow it down or your heart rate will go up trying to keep up
101+
// with the flow of numbers
102+
delay(250);
103+
}

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun Bio Sensor Hub Library
2-
version=1.0.5
2+
version=1.0.6
33
author=Elias Santistevan <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the MAX32664 Bio Metric Hub IC

src/SparkFun_Bio_Sensor_Hub_Library.cpp

+39-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ kk
2020

2121
#include "SparkFun_Bio_Sensor_Hub_Library.h"
2222

23-
SparkFun_Bio_Sensor_Hub::SparkFun_Bio_Sensor_Hub(uint16_t resetPin, uint16_t mfioPin, uint8_t address) {
23+
SparkFun_Bio_Sensor_Hub::SparkFun_Bio_Sensor_Hub(int resetPin, int mfioPin, uint8_t address) {
2424

2525
_resetPin = resetPin;
26+
if (resetPin >= 0)
27+
pinMode(_resetPin, OUTPUT); // Set the pin as output
28+
2629
_mfioPin = mfioPin;
30+
if (mfioPin >= 0)
31+
pinMode(_mfioPin, OUTPUT); // Set the pin as output
32+
2733
_address = address;
28-
pinMode(_mfioPin, OUTPUT);
29-
pinMode(_resetPin, OUTPUT); // Set these pins as output
3034

3135
}
3236

@@ -37,12 +41,27 @@ SparkFun_Bio_Sensor_Hub::SparkFun_Bio_Sensor_Hub(uint16_t resetPin, uint16_t mfi
3741
// in application mode and will return two bytes, the first 0x00 is a
3842
// successful communcation byte, followed by 0x00 which is the byte indicating
3943
// which mode the IC is in.
40-
uint8_t SparkFun_Bio_Sensor_Hub::begin( TwoWire &wirePort ) {
44+
uint8_t SparkFun_Bio_Sensor_Hub::begin( TwoWire &wirePort, int resetPin, int mfioPin ) {
4145

4246
_i2cPort = &wirePort;
4347
// _i2cPort->begin(); A call to Wire.begin should occur in sketch
4448
// to avoid multiple begins with other sketches.
4549

50+
if (resetPin >= 0)
51+
{
52+
_resetPin = resetPin;
53+
pinMode(_resetPin, OUTPUT); // Set the pin as output
54+
}
55+
56+
if (mfioPin >= 0)
57+
{
58+
_mfioPin = mfioPin;
59+
pinMode(_mfioPin, OUTPUT); // Set the pin as output
60+
}
61+
62+
if ((_resetPin < 0) || (_mfioPin < 0)) // Bail if the pins have still not been defined
63+
return 0xFF; // Return ERR_UNKNOWN
64+
4665
digitalWrite(_mfioPin, HIGH);
4766
digitalWrite(_resetPin, LOW);
4867
delay(10);
@@ -61,12 +80,27 @@ uint8_t SparkFun_Bio_Sensor_Hub::begin( TwoWire &wirePort ) {
6180
// in bootloader mode and will return two bytes, the first 0x00 is a
6281
// successful communcation byte, followed by 0x08 which is the byte indicating
6382
// that the board is in bootloader mode.
64-
uint8_t SparkFun_Bio_Sensor_Hub::beginBootloader( TwoWire &wirePort ) {
83+
uint8_t SparkFun_Bio_Sensor_Hub::beginBootloader( TwoWire &wirePort, int resetPin, int mfioPin ) {
6584

6685
_i2cPort = &wirePort;
6786
// _i2cPort->begin(); A call to Wire.begin should occur in sketch
6887
// to avoid multiple begins with other sketches.
6988

89+
if (resetPin >= 0)
90+
{
91+
_resetPin = resetPin;
92+
pinMode(_resetPin, OUTPUT); // Set the pin as output
93+
}
94+
95+
if (mfioPin >= 0)
96+
{
97+
_mfioPin = mfioPin;
98+
pinMode(_mfioPin, OUTPUT); // Set the pin as output
99+
}
100+
101+
if ((_resetPin < 0) || (_mfioPin < 0)) // Bail if the pins have still not been defined
102+
return 0xFF; // Return ERR_UNKNOWN
103+
70104
digitalWrite(_mfioPin, LOW);
71105
digitalWrite(_resetPin, LOW);
72106
delay(10);

src/SparkFun_Bio_Sensor_Hub_Library.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ class SparkFun_Bio_Sensor_Hub
314314
uint8_t bpmSenArrTwo[MAXFAST_ARRAY_SIZE + MAXFAST_EXTENDED_DATA + MAX30101_LED_ARRAY] {};
315315

316316
// Constructor ----------
317-
SparkFun_Bio_Sensor_Hub(uint16_t, uint16_t, uint8_t address = 0x55);
317+
SparkFun_Bio_Sensor_Hub(int resetPin = -1, int mfioPin = -1, uint8_t address = 0x55);
318318

319319
// Functions ------------
320320

@@ -325,7 +325,7 @@ class SparkFun_Bio_Sensor_Hub
325325
// in application mode and will return two bytes, the first 0x00 is a
326326
// successful communcation byte, followed by 0x00 which is the byte indicating
327327
// which mode the IC is in.
328-
uint8_t begin( TwoWire &wirePort = Wire);
328+
uint8_t begin( TwoWire &wirePort = Wire, int resetPin = -1, int mfioPin = -1 );
329329

330330
// Family Byte: READ_DEVICE_MODE (0x02) Index Byte: 0x00, Write Byte: 0x00
331331
// The following function puts the MAX32664 into bootloader mode. To place the MAX32664 into
@@ -334,7 +334,7 @@ class SparkFun_Bio_Sensor_Hub
334334
// in bootloader mode and will return two bytes, the first 0x00 is a
335335
// successful communcation byte, followed by 0x08 which is the byte indicating
336336
// that the board is in bootloader mode.
337-
uint8_t beginBootloader( TwoWire &wirePort = Wire);
337+
uint8_t beginBootloader( TwoWire &wirePort = Wire, int resetPin = -1, int mfioPin = -1 );
338338

339339
// Family Byte: HUB_STATUS (0x00), Index Byte: 0x00, No Write Byte.
340340
// The following function checks the status of the FIFO.
@@ -674,8 +674,8 @@ class SparkFun_Bio_Sensor_Hub
674674
private:
675675

676676
// Variables -----------
677-
uint8_t _resetPin;
678-
uint8_t _mfioPin;
677+
int _resetPin;
678+
int _mfioPin;
679679
uint8_t _address;
680680
uint32_t _writeCoefArr[3] {};
681681
uint8_t _userSelectedMode;

0 commit comments

Comments
 (0)