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