Heart Unit

MAX30100 is a complete pulse oximetry and heart-rate sensor system solution designed for the demanding requirements of wearable devices.

Support the following products:

HeartUnit

Micropython Example:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8from hardware import *
 9from unit import HeartUnit
10
11
12label0 = None
13labelHeart = None
14i2c0 = None
15heart_0 = None
16
17
18def setup():
19    global label0, labelHeart, i2c0, heart_0
20
21    M5.begin()
22    Widgets.fillScreen(0x222222)
23    label0 = Widgets.Label("Heart Rate", 57, 18, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu40)
24    labelHeart = Widgets.Label("label1", 82, 111, 1.0, 0xFFFFFF, 0x222222, Widgets.FONTS.DejaVu56)
25
26    i2c0 = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
27    heart_0 = HeartUnit(i2c0, 0x57)
28    heart_0.start()
29
30
31def loop():
32    global label0, labelHeart, i2c0, heart_0
33    M5.update()
34    labelHeart.setText(str(heart_0.get_heart_rate()))
35
36
37if __name__ == "__main__":
38    try:
39        setup()
40        while True:
41            loop()
42    except (Exception, KeyboardInterrupt) as e:
43        try:
44            heart_0.deinit()
45            from utility import print_error_msg
46
47            print_error_msg(e)
48        except ImportError:
49            print("please update to latest firmware")

UIFLOW2 Example:

example.png

core_heart_unit_example.m5f2

class HeartUnit

Constructors

class HeartUnit(i2c, address)

Initialize the HeartUnit.

  • i2c: I2C port to use.

  • address: I2C address of the HeartUnit.

UIFLOW2:

init.png

Methods

HeartUnit.stop()

Stop the HeartUnit.

UIFLOW2:

stop.png

HeartUnit.start()

Start the HeartUnit.

UIFLOW2:

start.png

HeartUnit.deinit()

Deinitialize the HeartUnit.

UIFLOW2:

deinit.png

HeartUnit.get_heart_rate()

Get the heart rate.

UIFLOW2:

get_heart_rate.png

HeartUnit.get_spo2()

Get the SpO2.

UIFLOW2:

get_spo2.png

HeartUnit.get_ir()

Get the IR value.

UIFLOW2:

get_ir.png

HeartUnit.get_red()

Get the red value.

UIFLOW2:

get_red.png

HeartUnit.set_mode(mode)

Set the mode of the HeartUnit.

参数:

mode (int) – The detect mode of the HeartUnit. Options: - HeartUnit.MODE_HR_ONLY: Only heart rate - HeartUnit.MODE_SPO2_HR: Heart rate and SpO2

UIFLOW2:

set_mode.png

HeartUnit.set_led_current(led_current)

Set the LED current of the HeartUnit.

参数:

led_current (int) – The LED current of the HeartUnit. Options: - HeartUnit.LED_CURRENT_0MA: 0mA - HeartUnit.LED_CURRENT_4_4MA: 4.4mA - HeartUnit.LED_CURRENT_7_6MA: 7.6mA - HeartUnit.LED_CURRENT_11MA: 11mA - HeartUnit.LED_CURRENT_14_2MA: 14.2mA - HeartUnit.LED_CURRENT_17_4MA: 17.4mA - HeartUnit.LED_CURRENT_20_8MA: 20.8mA - HeartUnit.LED_CURRENT_24MA: 24mA - HeartUnit.LED_CURRENT_27_1MA: 27.1mA - HeartUnit.LED_CURRENT_30_6MA: 30.6mA - HeartUnit.LED_CURRENT_33_8MA: 33.8mA - HeartUnit.LED_CURRENT_37MA: 37mA - HeartUnit.LED_CURRENT_40_2MA: 40.2mA - HeartUnit.LED_CURRENT_43_6MA: 43.6mA - HeartUnit.LED_CURRENT_46_8MA: 46.8mA - HeartUnit.LED_CURRENT_50MA: 50mA

UIFLOW2:

set_led_current.png

HeartUnit.set_pulse_width(pulse_width)

Set the pulse width of the HeartUnit.

参数:

pulse_width (int) – The pulse width of the HeartUnit. Options: - HeartUnit.PULSE_WIDTH_200US_ADC_13: 200us - HeartUnit.PULSE_WIDTH_400US_ADC_14: 400us - HeartUnit.PULSE_WIDTH_800US_ADC_15: 800us - HeartUnit.PULSE_WIDTH_1600US_ADC_16: 1600us

UIFLOW2:

set_pulse_width.png

HeartUnit.set_sampling_rate(sampling_rate)

Set the sampling rate of the HeartUnit.

参数:

sampling_rate (int) – The sampling rate of the HeartUnit. Options: - HeartUnit.SAMPLING_RATE_50HZ: 50Hz - HeartUnit.SAMPLING_RATE_100HZ: 100Hz - HeartUnit.SAMPLING_RATE_167HZ: 167Hz - HeartUnit.SAMPLING_RATE_200HZ: 200Hz - HeartUnit.SAMPLING_RATE_400HZ: 400Hz - HeartUnit.SAMPLING_RATE_600HZ: 600Hz - HeartUnit.SAMPLING_RATE_800HZ: 800Hz - HeartUnit.SAMPLING_RATE_1000HZ: 1000Hz

UIFLOW2:

set_sampling_rate.png

Constants

HeartUnit.MODE_HR_ONLY

Detect heart rate only.

HeartUnit.MODE_SPO2_HR

Detect heart rate and SpO2.