Skip to content

Commit

Permalink
Adding example to demo 3200Hz reading for issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
nseidle committed Apr 9, 2018
1 parent ffa4215 commit 077399a
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 10 deletions.
6 changes: 3 additions & 3 deletions examples/Example1_Basic_Readings/Example1_Basic_Readings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ MAX30105 particleSensor;

void setup()
{
debug.begin(115200);
debug.println("Initializing...");
debug.begin(9600);
debug.println("MAX30105 Basic Readings Example");

// Initialize sensor
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
if (particleSensor.begin() == false)
{
debug.println("MAX30105 was not found. Please check wiring/power. ");
while (1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ long startTime; //Used to calculate measurement rate

void setup()
{
Serial.begin(115200);
Serial.println("Initializing...");
Serial.begin(9600);
Serial.println("MAX30105 Presence Sensing Example");

// Initialize sensor
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
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);
Expand All @@ -44,7 +44,7 @@ void setup()
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
byte sampleRate = 400; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
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

Expand Down
13 changes: 11 additions & 2 deletions examples/Example6_FIFO_Readings/Example6_FIFO_Readings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,22 @@ void setup()
Serial.println("Initializing...");

// Initialize sensor
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
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);
}

particleSensor.setup(); //Configure sensor. Use 6.4mA for LED drive
//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();
}
Expand Down
92 changes: 92 additions & 0 deletions examples/Example9_RateTesting/Example9_RateTesting.ino
Original file line number Diff line number Diff line change
@@ -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();
}
2 changes: 1 addition & 1 deletion src/MAX30105.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ boolean MAX30105::begin(TwoWire &wirePort, uint32_t i2cSpeed, uint8_t i2caddr) {

_i2caddr = i2caddr;

// Step 1: Initial Communciation and Verification
// Step 1: Initial Communication and Verification
// Check that a MAX30105 is connected
if (!readPartID() == MAX_30105_EXPECTEDPARTID) {
// Error -- Part ID read from MAX30105 does not match expected part ID.
Expand Down

0 comments on commit 077399a

Please sign in to comment.