初始化提交
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
MAX30105 Breakout: Output all the raw Red/IR/Green readings
|
||||
By: Nathan Seidle @ SparkFun Electronics
|
||||
Date: October 2nd, 2016
|
||||
https://github.com/sparkfun/MAX30105_Breakout
|
||||
|
||||
Outputs all Red/IR/Green values.
|
||||
|
||||
Hardware Connections (Breakoutboard to Arduino):
|
||||
-5V = 5V (3.3V is allowed)
|
||||
-GND = GND
|
||||
-SDA = A4 (or SDA)
|
||||
-SCL = A5 (or SCL)
|
||||
-INT = Not connected
|
||||
|
||||
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
|
||||
but it will also run at 3.3V.
|
||||
|
||||
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "MAX30105.h"
|
||||
|
||||
MAX30105 particleSensor;
|
||||
|
||||
#define debug Serial //Uncomment this line if you're using an Uno or ESP
|
||||
//#define debug SerialUSB //Uncomment this line if you're using a SAMD21
|
||||
|
||||
void setup()
|
||||
{
|
||||
debug.begin(9600);
|
||||
debug.println("MAX30105 Basic Readings Example");
|
||||
|
||||
// Initialize sensor
|
||||
if (particleSensor.begin() == false)
|
||||
{
|
||||
debug.println("MAX30105 was not found. Please check wiring/power. ");
|
||||
while (1);
|
||||
}
|
||||
|
||||
particleSensor.setup(); //Configure sensor. Use 6.4mA for LED drive
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
debug.print(" R[");
|
||||
debug.print(particleSensor.getRed());
|
||||
debug.print("] IR[");
|
||||
debug.print(particleSensor.getIR());
|
||||
debug.print("] G[");
|
||||
debug.print(particleSensor.getGreen());
|
||||
debug.print("]");
|
||||
|
||||
debug.println();
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
MAX30105 Breakout: Take IR reading to sense presence
|
||||
By: Nathan Seidle @ SparkFun Electronics
|
||||
Date: October 2nd, 2016
|
||||
https://github.com/sparkfun/MAX30105_Breakout
|
||||
|
||||
This takes an average reading at power up and if the reading changes more than 100
|
||||
then print 'Something is there!'.
|
||||
|
||||
Hardware Connections (Breakoutboard to Arduino):
|
||||
-5V = 5V (3.3V is allowed)
|
||||
-GND = GND
|
||||
-SDA = A4 (or SDA)
|
||||
-SCL = A5 (or SCL)
|
||||
-INT = Not connected
|
||||
|
||||
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
|
||||
but it will also run at 3.3V.
|
||||
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "MAX30105.h"
|
||||
|
||||
MAX30105 particleSensor;
|
||||
|
||||
long samplesTaken = 0; //Counter for calculating the Hz or read rate
|
||||
long unblockedValue; //Average IR at power up
|
||||
long startTime; //Used to calculate measurement rate
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("MAX30105 Presence Sensing Example");
|
||||
|
||||
// Initialize sensor
|
||||
if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false) //Use default I2C port, 400kHz speed
|
||||
{
|
||||
Serial.println("MAX30105 was not found. Please check wiring/power. ");
|
||||
while (1);
|
||||
}
|
||||
|
||||
//Setup to sense up to 18 inches, max LED brightness
|
||||
byte ledBrightness = 0xFF; //Options: 0=Off to 255=50mA
|
||||
byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
|
||||
byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
|
||||
int sampleRate = 400; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
|
||||
int pulseWidth = 411; //Options: 69, 118, 215, 411
|
||||
int adcRange = 2048; //Options: 2048, 4096, 8192, 16384
|
||||
|
||||
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
|
||||
|
||||
particleSensor.setPulseAmplitudeRed(0); //Turn off Red LED
|
||||
particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED
|
||||
|
||||
//Take an average of IR readings at power up
|
||||
unblockedValue = 0;
|
||||
for (byte x = 0 ; x < 32 ; x++)
|
||||
{
|
||||
unblockedValue += particleSensor.getIR(); //Read the IR value
|
||||
}
|
||||
unblockedValue /= 32;
|
||||
|
||||
startTime = millis();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
samplesTaken++;
|
||||
|
||||
Serial.print("IR[");
|
||||
Serial.print(particleSensor.getIR());
|
||||
Serial.print("] Hz[");
|
||||
Serial.print((float)samplesTaken / ((millis() - startTime) / 1000.0), 2);
|
||||
Serial.print("]");
|
||||
|
||||
long currentDelta = particleSensor.getIR() - unblockedValue;
|
||||
|
||||
Serial.print(" delta[");
|
||||
Serial.print(currentDelta);
|
||||
Serial.print("]");
|
||||
|
||||
if (currentDelta > (long)100)
|
||||
{
|
||||
Serial.print(" Something is there!");
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
MAX3010 Breakout: Read the onboard temperature sensor
|
||||
By: Nathan Seidle @ SparkFun Electronics
|
||||
Date: October 20th, 2016
|
||||
https://github.com/sparkfun/MAX30105_Breakout
|
||||
|
||||
This demo outputs the onboard temperature sensor. The temp sensor is accurate to +/-1 C but
|
||||
has an astonishing precision of 0.0625 C.
|
||||
|
||||
Hardware Connections (Breakoutboard to Arduino):
|
||||
-5V = 5V (3.3V is allowed)
|
||||
-GND = GND
|
||||
-SDA = A4 (or SDA)
|
||||
-SCL = A5 (or SCL)
|
||||
-INT = Not connected
|
||||
|
||||
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
|
||||
but it will also run at 3.3V.
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#include "MAX30105.h" //Get it here: http://librarymanager/All#SparkFun_MAX30105
|
||||
MAX30105 particleSensor;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Initializing...");
|
||||
|
||||
// Initialize sensor
|
||||
if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false) //Use default I2C port, 400kHz speed
|
||||
{
|
||||
Serial.println("MAX30105 was not found. Please check wiring/power. ");
|
||||
while (1);
|
||||
}
|
||||
|
||||
//The LEDs are very low power and won't affect the temp reading much but
|
||||
//you may want to turn off the LEDs to avoid any local heating
|
||||
particleSensor.setup(0); //Configure sensor. Turn off LEDs
|
||||
//particleSensor.setup(); //Configure sensor. Use 25mA for LED drive
|
||||
|
||||
particleSensor.enableDIETEMPRDY(); //Enable the temp ready interrupt. This is required.
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
float temperature = particleSensor.readTemperature();
|
||||
|
||||
Serial.print("temperatureC=");
|
||||
Serial.print(temperature, 4);
|
||||
|
||||
float temperatureF = particleSensor.readTemperatureF(); //Because I am a bad global citizen
|
||||
|
||||
Serial.print(" temperatureF=");
|
||||
Serial.print(temperatureF, 4);
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
Heart beat plotting!
|
||||
By: Nathan Seidle @ SparkFun Electronics
|
||||
Date: October 20th, 2016
|
||||
https://github.com/sparkfun/MAX30105_Breakout
|
||||
|
||||
Shows the user's heart beat on Arduino's serial plotter
|
||||
|
||||
Instructions:
|
||||
1) Load code onto Redboard
|
||||
2) Attach sensor to your finger with a rubber band (see below)
|
||||
3) Open Tools->'Serial Plotter'
|
||||
4) Make sure the drop down is set to 115200 baud
|
||||
5) Checkout the blips!
|
||||
6) Feel the pulse on your neck and watch it mimic the blips
|
||||
|
||||
It is best to attach the sensor to your finger using a rubber band or other tightening
|
||||
device. Humans are generally bad at applying constant pressure to a thing. When you
|
||||
press your finger against the sensor it varies enough to cause the blood in your
|
||||
finger to flow differently which causes the sensor readings to go wonky.
|
||||
|
||||
Hardware Connections (Breakoutboard to Arduino):
|
||||
-5V = 5V (3.3V is allowed)
|
||||
-GND = GND
|
||||
-SDA = A4 (or SDA)
|
||||
-SCL = A5 (or SCL)
|
||||
-INT = Not connected
|
||||
|
||||
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
|
||||
but it will also run at 3.3V.
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "MAX30105.h"
|
||||
|
||||
MAX30105 particleSensor;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("Initializing...");
|
||||
|
||||
// Initialize sensor
|
||||
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
|
||||
{
|
||||
Serial.println("MAX30105 was not found. Please check wiring/power. ");
|
||||
while (1);
|
||||
}
|
||||
|
||||
//Setup to sense a nice looking saw tooth on the plotter
|
||||
byte ledBrightness = 0x1F; //Options: 0=Off to 255=50mA
|
||||
byte sampleAverage = 8; //Options: 1, 2, 4, 8, 16, 32
|
||||
byte ledMode = 3; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
|
||||
int sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
|
||||
int pulseWidth = 411; //Options: 69, 118, 215, 411
|
||||
int adcRange = 4096; //Options: 2048, 4096, 8192, 16384
|
||||
|
||||
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
|
||||
|
||||
//Arduino plotter auto-scales annoyingly. To get around this, pre-populate
|
||||
//the plotter with 500 of an average reading from the sensor
|
||||
|
||||
//Take an average of IR readings at power up
|
||||
const byte avgAmount = 64;
|
||||
long baseValue = 0;
|
||||
for (byte x = 0 ; x < avgAmount ; x++)
|
||||
{
|
||||
baseValue += particleSensor.getIR(); //Read the IR value
|
||||
}
|
||||
baseValue /= avgAmount;
|
||||
|
||||
//Pre-populate the plotter so that the Y scale is close to IR values
|
||||
for (int x = 0 ; x < 500 ; x++)
|
||||
Serial.println(baseValue);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println(particleSensor.getIR()); //Send raw data to plotter
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
Optical Heart Rate Detection (PBA Algorithm) using the MAX30105 Breakout
|
||||
By: Nathan Seidle @ SparkFun Electronics
|
||||
Date: October 2nd, 2016
|
||||
https://github.com/sparkfun/MAX30105_Breakout
|
||||
|
||||
This is a demo to show the reading of heart rate or beats per minute (BPM) using
|
||||
a Penpheral Beat Amplitude (PBA) algorithm.
|
||||
|
||||
It is best to attach the sensor to your finger using a rubber band or other tightening
|
||||
device. Humans are generally bad at applying constant pressure to a thing. When you
|
||||
press your finger against the sensor it varies enough to cause the blood in your
|
||||
finger to flow differently which causes the sensor readings to go wonky.
|
||||
|
||||
Hardware Connections (Breakoutboard to Arduino):
|
||||
-5V = 5V (3.3V is allowed)
|
||||
-GND = GND
|
||||
-SDA = A4 (or SDA)
|
||||
-SCL = A5 (or SCL)
|
||||
-INT = Not connected
|
||||
|
||||
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
|
||||
but it will also run at 3.3V.
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "MAX30105.h"
|
||||
|
||||
#include "heartRate.h"
|
||||
|
||||
MAX30105 particleSensor;
|
||||
|
||||
const byte RATE_SIZE = 4; //Increase this for more averaging. 4 is good.
|
||||
byte rates[RATE_SIZE]; //Array of heart rates
|
||||
byte rateSpot = 0;
|
||||
long lastBeat = 0; //Time at which the last beat occurred
|
||||
|
||||
float beatsPerMinute;
|
||||
int beatAvg;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("Initializing...");
|
||||
|
||||
// Initialize sensor
|
||||
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
|
||||
{
|
||||
Serial.println("MAX30105 was not found. Please check wiring/power. ");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("Place your index finger on the sensor with steady pressure.");
|
||||
|
||||
particleSensor.setup(); //Configure sensor with default settings
|
||||
particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is running
|
||||
particleSensor.setPulseAmplitudeGreen(0); //Turn off Green LED
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
long irValue = particleSensor.getIR();
|
||||
|
||||
if (checkForBeat(irValue) == true)
|
||||
{
|
||||
//We sensed a beat!
|
||||
long delta = millis() - lastBeat;
|
||||
lastBeat = millis();
|
||||
|
||||
beatsPerMinute = 60 / (delta / 1000.0);
|
||||
|
||||
if (beatsPerMinute < 255 && beatsPerMinute > 20)
|
||||
{
|
||||
rates[rateSpot++] = (byte)beatsPerMinute; //Store this reading in the array
|
||||
rateSpot %= RATE_SIZE; //Wrap variable
|
||||
|
||||
//Take average of readings
|
||||
beatAvg = 0;
|
||||
for (byte x = 0 ; x < RATE_SIZE ; x++)
|
||||
beatAvg += rates[x];
|
||||
beatAvg /= RATE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
Serial.print("IR=");
|
||||
Serial.print(irValue);
|
||||
Serial.print(", BPM=");
|
||||
Serial.print(beatsPerMinute);
|
||||
Serial.print(", Avg BPM=");
|
||||
Serial.print(beatAvg);
|
||||
|
||||
if (irValue < 50000)
|
||||
Serial.print(" No finger?");
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
|
||||
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Maxim Integrated
|
||||
* Products, Inc. shall not be used except as stated in the Maxim Integrated
|
||||
* Products, Inc. Branding Policy.
|
||||
*
|
||||
* The mere transfer of this software does not imply any licenses
|
||||
* of trade secrets, proprietary technology, copyrights, patents,
|
||||
* trademarks, maskwork rights, or any other form of intellectual
|
||||
* property whatsoever. Maxim Integrated Products, Inc. retains all
|
||||
* ownership rights.
|
||||
*
|
||||
*/
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
MAX30105 Breakout: Take readings from the FIFO
|
||||
By: Nathan Seidle @ SparkFun Electronics
|
||||
Date: October 2nd, 2016
|
||||
https://github.com/sparkfun/MAX30105_Breakout
|
||||
|
||||
Outputs all Red/IR/Green values at 25Hz by polling the FIFO
|
||||
|
||||
Hardware Connections (Breakoutboard to Arduino):
|
||||
-5V = 5V (3.3V is allowed)
|
||||
-GND = GND
|
||||
-SDA = A4 (or SDA)
|
||||
-SCL = A5 (or SCL)
|
||||
-INT = Not connected
|
||||
|
||||
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
|
||||
but it will also run at 3.3V.
|
||||
|
||||
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "MAX30105.h"
|
||||
|
||||
MAX30105 particleSensor;
|
||||
|
||||
long startTime;
|
||||
long samplesTaken = 0; //Counter for calculating the Hz or read rate
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("Initializing...");
|
||||
|
||||
// Initialize sensor
|
||||
if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false) //Use default I2C port, 400kHz speed
|
||||
{
|
||||
Serial.println("MAX30105 was not found. Please check wiring/power. ");
|
||||
while (1);
|
||||
}
|
||||
|
||||
//Setup to sense up to 18 inches, max LED brightness
|
||||
byte ledBrightness = 0xFF; //Options: 0=Off to 255=50mA
|
||||
byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
|
||||
byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
|
||||
int sampleRate = 400; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
|
||||
int pulseWidth = 411; //Options: 69, 118, 215, 411
|
||||
int adcRange = 2048; //Options: 2048, 4096, 8192, 16384
|
||||
|
||||
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
|
||||
// particleSensor.setup(); //Configure sensor. Use 6.4mA for LED drive
|
||||
|
||||
startTime = millis();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
particleSensor.check(); //Check the sensor, read up to 3 samples
|
||||
|
||||
while (particleSensor.available()) //do we have new data?
|
||||
{
|
||||
samplesTaken++;
|
||||
|
||||
Serial.print(" R[");
|
||||
Serial.print(particleSensor.getFIFORed());
|
||||
Serial.print("] IR[");
|
||||
Serial.print(particleSensor.getFIFOIR());
|
||||
Serial.print("] G[");
|
||||
Serial.print(particleSensor.getFIFOGreen());
|
||||
Serial.print("] Hz[");
|
||||
Serial.print((float)samplesTaken / ((millis() - startTime) / 1000.0), 2);
|
||||
Serial.print("]");
|
||||
|
||||
Serial.println();
|
||||
|
||||
particleSensor.nextSample(); //We're finished with this sample so move to next sample
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
MAX30105 Breakout: Output all the raw Red/IR/Green readings, check INT pin and interrupt register
|
||||
By: Nathan Seidle @ SparkFun Electronics
|
||||
Date: October 2nd, 2016
|
||||
https://github.com/sparkfun/MAX30105_Breakout
|
||||
|
||||
Outputs all Red/IR/Green values as fast as possible
|
||||
Checks the interrupt pin to see if an interrupt occurred
|
||||
Checks the interrupt register to see if a bit was set
|
||||
|
||||
Hardware Connections (Breakoutboard to Arduino):
|
||||
-5V = 5V (3.3V is allowed)
|
||||
-GND = GND
|
||||
-SDA = A4 (or SDA)
|
||||
-SCL = A5 (or SCL)
|
||||
-INT = Not connected
|
||||
|
||||
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
|
||||
but it will also run at 3.3V.
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "MAX30105.h"
|
||||
|
||||
MAX30105 particleSensor;
|
||||
|
||||
long startTime;
|
||||
long samplesTaken = 0; //Counter for calculating the Hz or read rate
|
||||
|
||||
byte interruptPin = 3; //Connect INT pin on breakout board to pin 3
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(interruptPin, INPUT);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("Initializing...");
|
||||
|
||||
// Initialize sensor
|
||||
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
|
||||
{
|
||||
Serial.println("MAX30105 was not found. Please check wiring/power. ");
|
||||
while (1);
|
||||
}
|
||||
|
||||
//Let's configure the sensor to run fast so we can over-run the buffer and cause an interrupt
|
||||
byte ledBrightness = 0x7F; //Options: 0=Off to 255=50mA
|
||||
byte sampleAverage = 1; //Options: 1, 2, 4, 8, 16, 32
|
||||
byte ledMode = 3; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
|
||||
byte sampleRate = 400; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
|
||||
int pulseWidth = 69; //Options: 69, 118, 215, 411
|
||||
int adcRange = 4096; //Options: 2048, 4096, 8192, 16384
|
||||
|
||||
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
|
||||
|
||||
particleSensor.enableAFULL(); //Enable the almost full interrupt (default is 32 samples)
|
||||
|
||||
particleSensor.setFIFOAlmostFull(3); //Set almost full int to fire at 29 samples
|
||||
|
||||
startTime = millis();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
particleSensor.check(); //Check the sensor, read up to 3 samples
|
||||
|
||||
while (particleSensor.available()) //do we have new data?
|
||||
{
|
||||
samplesTaken++;
|
||||
|
||||
Serial.print(" R[");
|
||||
Serial.print(particleSensor.getRed());
|
||||
Serial.print("] IR[");
|
||||
Serial.print(particleSensor.getIR());
|
||||
Serial.print("] G[");
|
||||
Serial.print(particleSensor.getGreen());
|
||||
Serial.print("] Hz[");
|
||||
Serial.print((float)samplesTaken / ((millis() - startTime) / 1000.0), 2);
|
||||
Serial.print("]");
|
||||
|
||||
if (digitalRead(interruptPin) == LOW) //Hardware way of reading interrupts
|
||||
{
|
||||
Serial.print(" INT!");
|
||||
}
|
||||
|
||||
byte flags = particleSensor.getINT1(); //Software way of reading interrupts
|
||||
if (flags)
|
||||
{
|
||||
Serial.print(" I[");
|
||||
Serial.print(flags, BIN);
|
||||
Serial.print("]");
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
|
||||
particleSensor.nextSample(); //We're finished with this sample so move to next sample
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
Optical SP02 Detection (SPK Algorithm) using the MAX30105 Breakout
|
||||
By: Nathan Seidle @ SparkFun Electronics
|
||||
Date: October 19th, 2016
|
||||
https://github.com/sparkfun/MAX30105_Breakout
|
||||
|
||||
This demo shows heart rate and SPO2 levels.
|
||||
|
||||
It is best to attach the sensor to your finger using a rubber band or other tightening
|
||||
device. Humans are generally bad at applying constant pressure to a thing. When you
|
||||
press your finger against the sensor it varies enough to cause the blood in your
|
||||
finger to flow differently which causes the sensor readings to go wonky.
|
||||
|
||||
This example is based on MAXREFDES117 and RD117_LILYPAD.ino from Maxim. Their example
|
||||
was modified to work with the SparkFun MAX30105 library and to compile under Arduino 1.6.11
|
||||
Please see license file for more info.
|
||||
|
||||
Hardware Connections (Breakoutboard to Arduino):
|
||||
-5V = 5V (3.3V is allowed)
|
||||
-GND = GND
|
||||
-SDA = A4 (or SDA)
|
||||
-SCL = A5 (or SCL)
|
||||
-INT = Not connected
|
||||
|
||||
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
|
||||
but it will also run at 3.3V.
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "MAX30105.h"
|
||||
#include "spo2_algorithm.h"
|
||||
|
||||
MAX30105 particleSensor;
|
||||
|
||||
#define MAX_BRIGHTNESS 255
|
||||
|
||||
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
|
||||
//Arduino Uno doesn't have enough SRAM to store 100 samples of IR led data and red led data in 32-bit format
|
||||
//To solve this problem, 16-bit MSB of the sampled data will be truncated. Samples become 16-bit data.
|
||||
uint16_t irBuffer[100]; //infrared LED sensor data
|
||||
uint16_t redBuffer[100]; //red LED sensor data
|
||||
#else
|
||||
uint32_t irBuffer[100]; //infrared LED sensor data
|
||||
uint32_t redBuffer[100]; //red LED sensor data
|
||||
#endif
|
||||
|
||||
int32_t bufferLength; //data length
|
||||
int32_t spo2; //SPO2 value
|
||||
int8_t validSPO2; //indicator to show if the SPO2 calculation is valid
|
||||
int32_t heartRate; //heart rate value
|
||||
int8_t validHeartRate; //indicator to show if the heart rate calculation is valid
|
||||
|
||||
byte pulseLED = 11; //Must be on PWM pin
|
||||
byte readLED = 13; //Blinks with each data read
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200); // initialize serial communication at 115200 bits per second:
|
||||
|
||||
pinMode(pulseLED, OUTPUT);
|
||||
pinMode(readLED, OUTPUT);
|
||||
|
||||
// Initialize sensor
|
||||
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
|
||||
{
|
||||
Serial.println(F("MAX30105 was not found. Please check wiring/power."));
|
||||
while (1);
|
||||
}
|
||||
|
||||
Serial.println(F("Attach sensor to finger with rubber band. Press any key to start conversion"));
|
||||
while (Serial.available() == 0) ; //wait until user presses a key
|
||||
Serial.read();
|
||||
|
||||
byte ledBrightness = 60; //Options: 0=Off to 255=50mA
|
||||
byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
|
||||
byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
|
||||
byte sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
|
||||
int pulseWidth = 411; //Options: 69, 118, 215, 411
|
||||
int adcRange = 4096; //Options: 2048, 4096, 8192, 16384
|
||||
|
||||
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
bufferLength = 100; //buffer length of 100 stores 4 seconds of samples running at 25sps
|
||||
|
||||
//read the first 100 samples, and determine the signal range
|
||||
for (byte i = 0 ; i < bufferLength ; i++)
|
||||
{
|
||||
while (particleSensor.available() == false) //do we have new data?
|
||||
particleSensor.check(); //Check the sensor for new data
|
||||
|
||||
redBuffer[i] = particleSensor.getRed();
|
||||
irBuffer[i] = particleSensor.getIR();
|
||||
particleSensor.nextSample(); //We're finished with this sample so move to next sample
|
||||
|
||||
Serial.print(F("red="));
|
||||
Serial.print(redBuffer[i], DEC);
|
||||
Serial.print(F(", ir="));
|
||||
Serial.println(irBuffer[i], DEC);
|
||||
}
|
||||
|
||||
//calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples)
|
||||
maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
|
||||
|
||||
//Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second
|
||||
while (1)
|
||||
{
|
||||
//dumping the first 25 sets of samples in the memory and shift the last 75 sets of samples to the top
|
||||
for (byte i = 25; i < 100; i++)
|
||||
{
|
||||
redBuffer[i - 25] = redBuffer[i];
|
||||
irBuffer[i - 25] = irBuffer[i];
|
||||
}
|
||||
|
||||
//take 25 sets of samples before calculating the heart rate.
|
||||
for (byte i = 75; i < 100; i++)
|
||||
{
|
||||
while (particleSensor.available() == false) //do we have new data?
|
||||
particleSensor.check(); //Check the sensor for new data
|
||||
|
||||
digitalWrite(readLED, !digitalRead(readLED)); //Blink onboard LED with every data read
|
||||
|
||||
redBuffer[i] = particleSensor.getRed();
|
||||
irBuffer[i] = particleSensor.getIR();
|
||||
particleSensor.nextSample(); //We're finished with this sample so move to next sample
|
||||
|
||||
//send samples and calculation result to terminal program through UART
|
||||
Serial.print(F("red="));
|
||||
Serial.print(redBuffer[i], DEC);
|
||||
Serial.print(F(", ir="));
|
||||
Serial.print(irBuffer[i], DEC);
|
||||
|
||||
Serial.print(F(", HR="));
|
||||
Serial.print(heartRate, DEC);
|
||||
|
||||
Serial.print(F(", HRvalid="));
|
||||
Serial.print(validHeartRate, DEC);
|
||||
|
||||
Serial.print(F(", SPO2="));
|
||||
Serial.print(spo2, DEC);
|
||||
|
||||
Serial.print(F(", SPO2Valid="));
|
||||
Serial.println(validSPO2, DEC);
|
||||
}
|
||||
|
||||
//After gathering 25 new samples recalculate HR and SP02
|
||||
maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
|
||||
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Maxim Integrated
|
||||
* Products, Inc. shall not be used except as stated in the Maxim Integrated
|
||||
* Products, Inc. Branding Policy.
|
||||
*
|
||||
* The mere transfer of this software does not imply any licenses
|
||||
* of trade secrets, proprietary technology, copyrights, patents,
|
||||
* trademarks, maskwork rights, or any other form of intellectual
|
||||
* property whatsoever. Maxim Integrated Products, Inc. retains all
|
||||
* ownership rights.
|
||||
*
|
||||
*/
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
MAX30105 Breakout: Take readings from the FIFO
|
||||
By: Nathan Seidle @ SparkFun Electronics
|
||||
Date: April 8th, 2018
|
||||
https://github.com/sparkfun/MAX30105_Breakout
|
||||
|
||||
Push the MAX30105 as fast as it will go!
|
||||
|
||||
We used a Teensy 3.2 for testing. This will configure the MAX3010x and
|
||||
output at approximately 3200Hz.
|
||||
|
||||
On an Uno the fastest we can read is 2700Hz.
|
||||
|
||||
Setting required:
|
||||
Sample average has a direct impact on max read amount. Set to 1 for max speed.
|
||||
The pulsewidth must be as short as possible. Set to 69.
|
||||
ledMode must be 1 for 3200Hz. If ledMode is set to 2 max is 1600Hz.
|
||||
Run at 400kHz I2C communication speed.
|
||||
Print serial at 115200.
|
||||
|
||||
Any serial printing will slow the reading of data and may cause the FIFO to overflow.
|
||||
Keep your prints small.
|
||||
|
||||
Hardware Connections (Breakoutboard to Arduino):
|
||||
-5V = 5V (3.3V is allowed)
|
||||
-GND = GND
|
||||
-SDA = A4 (or SDA) - Pin 18 on Teensy
|
||||
-SCL = A5 (or SCL) - Pin 19 on Teensy
|
||||
-INT = Not connected
|
||||
|
||||
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
|
||||
but it will also run at 3.3V.
|
||||
|
||||
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
|
||||
*/
|
||||
|
||||
#include <Wire.h>
|
||||
#include "MAX30105.h"
|
||||
|
||||
MAX30105 particleSensor;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(!Serial); //We must wait for Teensy to come online
|
||||
Serial.println("Max sample rate example");
|
||||
|
||||
// Initialize sensor
|
||||
if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false) //Use default I2C port, 400kHz speed
|
||||
{
|
||||
Serial.println("MAX30105 was not found. Please check wiring/power. ");
|
||||
while (1);
|
||||
}
|
||||
|
||||
//Setup to sense up to 18 inches, max LED brightness
|
||||
byte ledBrightness = 0xFF; //Options: 0=Off to 255=50mA
|
||||
byte sampleAverage = 1; //Options: 1, 2, 4, 8, 16, 32
|
||||
byte ledMode = 1; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
|
||||
int sampleRate = 3200; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
|
||||
int pulseWidth = 69; //Options: 69, 118, 215, 411
|
||||
int adcRange = 16384; //Options: 2048, 4096, 8192, 16384
|
||||
|
||||
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
byte samplesTaken = 0;
|
||||
long startTime = micros();
|
||||
|
||||
while(samplesTaken < 10)
|
||||
{
|
||||
particleSensor.check(); //Check the sensor, read up to 3 samples
|
||||
while (particleSensor.available()) //do we have new data?
|
||||
{
|
||||
samplesTaken++;
|
||||
particleSensor.getFIFOIR();
|
||||
particleSensor.nextSample(); //We're finished with this sample so move to next sample
|
||||
}
|
||||
}
|
||||
|
||||
long endTime = micros();
|
||||
|
||||
Serial.print("samples[");
|
||||
Serial.print(samplesTaken);
|
||||
|
||||
Serial.print("] Hz[");
|
||||
Serial.print((float)samplesTaken / ((endTime - startTime) / 1000000.0), 2);
|
||||
Serial.print("]");
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
Reference in New Issue
Block a user