MAX30101 Module¶
This module contains the driver for MAXIM MAX30101 pulse oximetry and heart-rate monitor module. The MAX30101 is capable of direct I2C communication and can be set on 3 different operating mode (datasheet).
MAX30101 Class¶
class MAX30101¶
class MAX30101(i2cdrv,addr=0x57,clk=400000)
Creates an intance of the MAX30101 class.
Arguments:
- i2cdrv – I2C Bus used ‘( I2C0, … )’
- addr – Slave address, default 0x75
- clk – Clock speed, default 400kHz.
Example:
from maxim.max30101 import max30101
...
m301 = max30101.MAX30101(I2C0)
m301.start()
m301.init()
data = m301.read_raw_samples(6)
MAX30101.init¶
init(mode = 'spo2',adc_range = 3,sample_rate = 50,pulse_width = 411,led_current = [255,255,0,0],proximity_thrs = 0,slot_multi = [0,0,0,0])
Initialize the MAX30101. Default paramter values enable "spo2"
- without proximity - mode with: maximum ADC range, sampling rate of 50 Hz, LED pulse width of 411us and maximum pulse amplitude for both red and IR LEDs.
Arguments:
- mode – set the operating state of the MAX30101, default mode is
spo2
. - adc_range – sets the SpO2 sensor ADC’s full-scale range, maximum range by default.
- sample_rate – sets the sampling rate, default is 50 Hz.
- pulse_width – LEDs pulse width in microsecond, default value is 411.
- led_current – sets red, IR, green and IR for proximity mode LEDs pulse amplitude, by default only red and IR red are set to maximum value.
- proximity_thrs – sets the threshold for the proximity mode.
- slot_multi – configuration parameter for
"multi"
operating mode.
Note
For details on available values for all the parameters see set_mode()
.
FIFO configuration¶
The MAX30101 stores the digital output data in a 32-deep circular FIFO within the IC. The sample size depends on the number of LED configured as active. As each led signal is stored as a 3-byte data, the FIFO width can be 3, 6, 9 or 12 bytes in size.
MAX30101.set_sample_averaging¶
set_sample_averaging(n)
To reduce the amount of data throughput, n
adjacent samples (in each individual channel) can be averaged and decimated on the chip by using this method. Accepted values for n
are: 1,2,4,8,16 and 32.
MAX30101.set_fifo_rollover¶
set_fifo_rollover(ro = True)
This method controls the behavior of the FIFO when the FIFO becomes completely filled with data. If ro
is True
, the FIFO Address rolls over to zero and the FIFO continues to fill with new data. If ro
is False
, then the FIFO is not updated until FIFO is read or the FIFO WRITE/READ pointer positions are changed.
MAX30101.set_fifo_afv¶
set_fifo_afv(n)
This method sets the trigger for the "full"
interrupt. The interrupt triggers when there are n
empty spaces left in FIFO.
MAX30101.read_raw_samples¶
read_raw_samples(nbyte)
Return a nbyte-long bytearray containing raw data read from the FIFO.
MAX30101.clear_fifo¶
clear_fifo()
This method set to zero the FIFO read and write pointers and the overflow counter.
Interrupt configuration¶
MAX30101.enable_interrupt¶
enable_interrupt(source)
Set bit on enable interrupt registers corresponding to the selected source. ‘sources’ must be a list including one or more available sources. Available values for ‘sources’ are:
-
"full"
: inspo2
orhr
mode, this interrupt triggers when FIFO has a certain number of free spaces remaining. -
"data"
: inspo2
orhr
mode, this interrupt triggers when there is a new sample in the data FIFO. -
"alc"
: this interrupt triggers when the ambient light cancellation function of the SpO2/HR photodiode has reached its maximum limit, and therefore, ambient light is affecting the output of the ADC. -
"prox"
: the proximity interrupt is triggered when the proximity threshold is reached, and SpO2/HR mode has begun. -
"temp"
: when an internal die temperature conversion is finished, this interrupt is triggered so the processor can read the temperature data registers.
MAX30101.read_triggered_interrupt¶
read_triggered_interrupt()
This method needs to read which interrupt is triggered when more then one is enabled and returns a list containing triggered interrupts.
Note
interrupt defines are shown in method above; this function can return “pwr” interrupt (triggered on every power-up) that is enabled by default and cannot be disabled.
MAX30101.disable_interrupts¶
disable_interrupts()
Disable all interrupts.
Mode configuration¶
MAX30101.shutdown¶
shutdown()
Put the part into a power-save mode. While in power-save mode, all registers retain their values, and write/read operations function as normal. All interrupts are cleared to zero in this mode.
MAX30101.wake_up¶
wake_up()
Wake up the MAX30101 component.
MAX30101.reset¶
reset()
All configuration, threshold, and data registers are reset to their power-on-state through a power-on reset.
MAX30101.set_mode¶
set_mode(mode,adc_range,sample_rate,pulse_width,led_current,proximity_thrs,slot_multi)
Set the operating mode of the MAX30101. Default paramter values are the same of init()
.
Parameters:
-
mode : set the operating state of the MAX30101. Available values are:
"hr"
: Heart Rate mode - only red LED is used for conversion."spo2"
: SpO2 mode - red and IR LEDs are used for conversion."multi"
: Multi-LED mode - green, red and/or IR LEDs can be used for conversion.- adc_range : sets the SpO2 sensor ADC’s full-scale range as shown in the table below.
adc_range | LSB size (pA) | Full Scale (nA) |
---|---|---|
0 | 7.81 | 2048 |
1 | 15.63 | 4096 |
2 | 31.25 | 8192 |
3 | 62.5 | 16384 |
-
sample_rate : sets the SpO2 effective sample rate. One sample consists of one IR pulse/conversion and one RED pulse/conversion. The sample rate and pulse width are related in that the sample rate sets an upper bound on the pulse width time. If the user selects a sample rate that is too high for the selected pulse_width setting, the highest possible sample rate is programmed instead. Available sampling rate values are: 50, 100, 200, 400, 800, 1000, 1600, 3200.
-
pulse_width : set the LED pulse width and indirectly sets the ADC resolution. All LEDs (IR, red and green) have the same pulse width.
pulse_width | Pulse width (us) | ADC Resolution (bits) |
---|---|---|
69 | 68.95 | 15 |
118 | 117.78 | 16 |
215 | 215.44 | 17 |
411 | 410.75 | 18 |
- led_current : sets the pulse amplitude for the LEDs. led_current = [red, ir, green, pilot]. The purpose of pilot is to set the LED power during the proximity mode, as well as in
"multi"
mode.
red, ir, green or pilot | Led Current (mA) |
---|---|
0 | 0.0 |
1 | 0.2 |
2 | 0.4 |
... | ... |
15 | 3.1 |
... | ... |
31 | 6.4 |
... | ... |
63 | 12.5 |
... | ... |
127 | 25.4 |
... | ... |
255 | 50.0 |
-
proximity_thrs: sets the IR ADC count that will trigger the beginning of
"hr"
or"spo2"
mode and, if enabled, the prox interrupt. The threshold is defined as the 8 MSBs of the ADC count. For example, if proximity_thrs = 1, then an ADC value of 1023 (decimal) or higher triggers the prox interrupt. If proximity_thrs = 255, then only a saturated ADC triggers the interrupt. -
slot_multi: In
"multi"
mode, each sample is split into up to four time slots, slot1 through slot4. slot_multi = [slot1, slot2, slot3, slot4]. These method control which LED is active with which amplitude in each time slot, making for a very flexible configuration. The slots should be enabled in order (i.e., slot1 should not be disabled if slot2 or slot3 are enabled).
slotX | Active Led | Led Pulse Amplitude (led_current value) |
---|---|---|
0 | None | Off |
1 | RED | red |
2 | IR | ir |
3 | GREEN | green |
4 | None | Off |
5 | RED | pilot |
6 | IR | pilot |
7 | GREEN | pilot |
Temperature Data¶
MAX30101.enable_temperature¶
enable_temperature()
Initiates a single temperature reading from the temperature sensor.
MAX30101.get_temperature¶
get_temperature()
Returns a float representing the last temperature reading in Celsius.
Part ID¶
MAX30101.get_part_id¶
get_part_id()
Returns the Part ID of the component.
MAX30101.get_revision_id¶
get_revision_id()
Returns the Revision ID of the component.