SparkFun MAX3010x Sensor Library

repository·master·Indexed 42 days ago

https://github.com/sparkfun/sparkfun_max3010x_sensor_library

A C++ library for Arduino to interface with Maxim MAX3010x series sensors, including the MAX30105, MAX30102, MAX30101, and MAX30100. It supports particle sensing and pulse oximetry, providing functionality for FIFO buffer management, LED amplitude control, die temperature reading, and interrupt configuration.

Tokens
1.4K
Snippets
5
Records
11
Agent score
5%

What's inside SparkFun MAX3010x

  1. Overview of the SparkFun MAX301x Particle Sensor Library

    master

    The SparkFun MAX301x Particle Sensor Library provides an interface for interacting with Maxim MAX3010x series sensors. It is designed to work with the MAX30105 (reflectance, particle, and pulse ox sensor), as well as the MAX30102, MAX30101, and MAX30100 sensors.

    Key features include support for particle sensing and pulse oximetry (pulse ox) applications.

  2. Manage sensor interrupts

    master

    The sensor supports several interrupt types to notify the host of events. You can enable or disable them individually.

    Interrupt Types:

    • enableAFULL() / disableAFULL(): Data in FIFO is almost full.
    • enableDATARDY() / disableDATARDY(): Data is ready.
    • enableALCOVF() / disableALCOVF(): Almost overflow.
    • enablePROXINT() / disablePROXINT(): Proximity interrupt.
    • enableDIETEMPRDY() / disableDIETEMPRDY(): Die temperature ready.

    Reading Interrupt Status:

    • getINT1(): Returns the main interrupt group status.
    • getINT2(): Returns the temperature ready interrupt status.
  3. Configure LED amplitudes and modes

    master

    You can manually control the intensity of the LEDs and the sensor's operational mode.

    LED Amplitude:

    • setPulseAmplitudeRed(uint8_t value)
    • setPulseAmplitudeIR(uint8_t value)
    • setPulseAmplitudeGreen(uint8_t value)
    • setPulseAmplitudeProximity(uint8_t value)

    Modes and Sampling:

    • setLEDMode(uint8_t mode): Sets the operational LED mode.
    • setSampleRate(uint8_t sampleRate): Sets the sampling frequency.
    • setPulseWidth(uint8_t pulseWidth): Sets the pulse width.
    • setADCRange(uint8_t adcRange): Sets the ADC range.
  4. Configure sensor settings with setup()

    master

    The setup() method provides a high-level way to configure the sensor's power, sampling, and LED modes in a single call.

    Parameters:

    • powerLevel: Power level (default 0x1F).
    • sampleAverage: Number of samples to average (default 4).
    • ledMode: LED mode (default 3).
    • sampleRate: Sample rate in Hz (default 400).
    • pulseWidth: Pulse width in microseconds (default 411).
    • adcRange: ADC range (default 4096).
    sensor.setup(0x1F, 4, 3, 400, 411, 4096);
  5. Read data from the FIFO buffer

    master

    The MAX30105 contains a FIFO (First-In, First-Out) buffer to store multiple samples. To read data from the buffer, follow this pattern:

    1. Use check() to fill the internal buffer with new data.
    2. Use available() to determine how many new samples are ready to be read.
    3. Iterate through the samples using nextSample() to advance the pointer.
    4. Use getFIFORed(), getFIFOIR(), or getFIFOGreen() to retrieve the data at the current pointer.

    Pointer Management:

    • getWritePointer(): Returns the current write pointer position.
    • getReadPointer(): Returns the current read pointer position.
    • clearFIFO(): Resets both read and write pointers to zero.
    if (sensor.check()) {
      uint8_t numSamples = sensor.available();
      for (uint8_t i = 0; i < numSamples; i++) {
        uint32_t r = sensor.getFIFORed();
        uint32_t ir = sensor.getFIFOIR();
        uint32_t g = sensor.getFIFOGreen();
        // Process data...
        sensor.nextSample();
      }
    }
  6. Initialize the MAX30105 sensor

    master

    To use the sensor, first instantiate the MAX30105 class and then call the begin() method. The begin() method configures the I2C interface.

    Parameters:

    • wirePort: A reference to the TwoWire instance (defaults to Wire).
    • i2cSpeed: The I2C clock speed. Use I2C_SPEED_STANDARD (100,000) or I2C_SPEED_FAST (400,000).
    • i2caddr: The 7-bit I2C address (defaults to MAX30105_ADDRESS which is 0x57). Note that the MAX30102 uses the same address.

    Returns true if initialization was successful.

    MAX30105 sensor;
    if (!sensor.begin(Wire, I2C_SPEED_FAST)) {
      // Handle error
    }