Skip to content

Commit 077399a

Browse files
committed
Adding example to demo 3200Hz reading for issue #2
1 parent ffa4215 commit 077399a

File tree

5 files changed

+111
-10
lines changed

5 files changed

+111
-10
lines changed

examples/Example1_Basic_Readings/Example1_Basic_Readings.ino

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ MAX30105 particleSensor;
2929

3030
void setup()
3131
{
32-
debug.begin(115200);
33-
debug.println("Initializing...");
32+
debug.begin(9600);
33+
debug.println("MAX30105 Basic Readings Example");
3434

3535
// Initialize sensor
36-
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
36+
if (particleSensor.begin() == false)
3737
{
3838
debug.println("MAX30105 was not found. Please check wiring/power. ");
3939
while (1);

examples/Example2_Presence_Sensing/Example2_Presence_Sensing.ino

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ long startTime; //Used to calculate measurement rate
3030

3131
void setup()
3232
{
33-
Serial.begin(115200);
34-
Serial.println("Initializing...");
33+
Serial.begin(9600);
34+
Serial.println("MAX30105 Presence Sensing Example");
3535

3636
// Initialize sensor
37-
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
37+
if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false) //Use default I2C port, 400kHz speed
3838
{
3939
Serial.println("MAX30105 was not found. Please check wiring/power. ");
4040
while (1);
@@ -44,7 +44,7 @@ void setup()
4444
byte ledBrightness = 0xFF; //Options: 0=Off to 255=50mA
4545
byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
4646
byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
47-
byte sampleRate = 400; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
47+
int sampleRate = 400; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
4848
int pulseWidth = 411; //Options: 69, 118, 215, 411
4949
int adcRange = 2048; //Options: 2048, 4096, 8192, 16384
5050

examples/Example6_FIFO_Readings/Example6_FIFO_Readings.ino

+11-2
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,22 @@ void setup()
3333
Serial.println("Initializing...");
3434

3535
// Initialize sensor
36-
if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
36+
if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false) //Use default I2C port, 400kHz speed
3737
{
3838
Serial.println("MAX30105 was not found. Please check wiring/power. ");
3939
while (1);
4040
}
4141

42-
particleSensor.setup(); //Configure sensor. Use 6.4mA for LED drive
42+
//Setup to sense up to 18 inches, max LED brightness
43+
byte ledBrightness = 0xFF; //Options: 0=Off to 255=50mA
44+
byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
45+
byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
46+
int sampleRate = 400; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
47+
int pulseWidth = 411; //Options: 69, 118, 215, 411
48+
int adcRange = 2048; //Options: 2048, 4096, 8192, 16384
49+
50+
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
51+
// particleSensor.setup(); //Configure sensor. Use 6.4mA for LED drive
4352

4453
startTime = millis();
4554
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
MAX30105 Breakout: Take readings from the FIFO
3+
By: Nathan Seidle @ SparkFun Electronics
4+
Date: April 8th, 2018
5+
https://github.com/sparkfun/MAX30105_Breakout
6+
7+
Push the MAX30105 as fast as it will go!
8+
9+
We used a Teensy 3.2 for testing. This will configure the MAX3010x and
10+
output at approximately 3200Hz.
11+
12+
On an Uno the fastest we can read is 2700Hz.
13+
14+
Setting required:
15+
Sample average has a direct impact on max read amount. Set to 1 for max speed.
16+
The pulsewidth must be as short as possible. Set to 69.
17+
ledMode must be 1 for 3200Hz. If ledMode is set to 2 max is 1600Hz.
18+
Run at 400kHz I2C communication speed.
19+
Print serial at 115200.
20+
21+
Any serial printing will slow the reading of data and may cause the FIFO to overflow.
22+
Keep your prints small.
23+
24+
Hardware Connections (Breakoutboard to Arduino):
25+
-5V = 5V (3.3V is allowed)
26+
-GND = GND
27+
-SDA = A4 (or SDA) - Pin 18 on Teensy
28+
-SCL = A5 (or SCL) - Pin 19 on Teensy
29+
-INT = Not connected
30+
31+
The MAX30105 Breakout can handle 5V or 3.3V I2C logic. We recommend powering the board with 5V
32+
but it will also run at 3.3V.
33+
34+
This code is released under the [MIT License](http://opensource.org/licenses/MIT).
35+
*/
36+
37+
#include <Wire.h>
38+
#include "MAX30105.h"
39+
40+
MAX30105 particleSensor;
41+
42+
void setup()
43+
{
44+
Serial.begin(115200);
45+
while(!Serial); //We must wait for Teensy to come online
46+
Serial.println("Max sample rate example");
47+
48+
// Initialize sensor
49+
if (particleSensor.begin(Wire, I2C_SPEED_FAST) == false) //Use default I2C port, 400kHz speed
50+
{
51+
Serial.println("MAX30105 was not found. Please check wiring/power. ");
52+
while (1);
53+
}
54+
55+
//Setup to sense up to 18 inches, max LED brightness
56+
byte ledBrightness = 0xFF; //Options: 0=Off to 255=50mA
57+
byte sampleAverage = 1; //Options: 1, 2, 4, 8, 16, 32
58+
byte ledMode = 1; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
59+
int sampleRate = 3200; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
60+
int pulseWidth = 69; //Options: 69, 118, 215, 411
61+
int adcRange = 16384; //Options: 2048, 4096, 8192, 16384
62+
63+
particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
64+
}
65+
66+
void loop()
67+
{
68+
byte samplesTaken = 0;
69+
long startTime = micros();
70+
71+
while(samplesTaken < 10)
72+
{
73+
particleSensor.check(); //Check the sensor, read up to 3 samples
74+
while (particleSensor.available()) //do we have new data?
75+
{
76+
samplesTaken++;
77+
particleSensor.getFIFOIR();
78+
particleSensor.nextSample(); //We're finished with this sample so move to next sample
79+
}
80+
}
81+
82+
long endTime = micros();
83+
84+
Serial.print("samples[");
85+
Serial.print(samplesTaken);
86+
87+
Serial.print("] Hz[");
88+
Serial.print((float)samplesTaken / ((endTime - startTime) / 1000000.0), 2);
89+
Serial.print("]");
90+
91+
Serial.println();
92+
}

src/MAX30105.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ boolean MAX30105::begin(TwoWire &wirePort, uint32_t i2cSpeed, uint8_t i2caddr) {
160160

161161
_i2caddr = i2caddr;
162162

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

0 commit comments

Comments
 (0)