|
| 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 | +} |
0 commit comments