Skip to content

Commit bf664b8

Browse files
MagpieEmbeddedkartben
authored andcommitted
samples: sensor: Modify MAX30101 sample to generic heart rate sensor sample
This commit modifies the MAX30101 sample to produce a generic heart rate sensor sample. Support for the BH1790 sensor is added. Signed-off-by: Magpie Embedded <[email protected]>
1 parent 74ef345 commit bf664b8

File tree

8 files changed

+82
-48
lines changed

8 files changed

+82
-48
lines changed

samples/sensor/heart_rate/README.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.. zephyr:code-sample:: heart_rate
2+
:name: Heart Rate Sensor
3+
:relevant-api: sensor_interface
4+
5+
Get heart rate data from a sensor (polling mode).
6+
7+
Overview
8+
********
9+
10+
A sensor application that demonstrates how to poll data from a heart rate
11+
sensor.
12+
13+
Requirements
14+
************
15+
16+
* A supported heart rate sensor (e.g., MAX30101 or BH1790), available as ``heart-rate-sensor`` Devicetree alias.
17+
18+
Building and Running
19+
********************
20+
21+
This project configures a sensor on the board to enable the green LED and
22+
measure the reflected light with a photodiode. The raw data prints to the
23+
console. Further processing (not included in this sample) is required to
24+
extract a heart rate signal from the light measurement.
25+
26+
.. zephyr-app-commands::
27+
:zephyr-app: samples/sensor/heart_rate
28+
:board: hexiwear/mk64f12
29+
:goals: build
30+
:compact:
31+
32+
Sample Output
33+
=============
34+
35+
.. code-block:: console
36+
37+
GREEN=5731
38+
GREEN=5750
39+
GREEN=5748
40+
GREEN=5741
41+
GREEN=5735
42+
GREEN=5737
43+
GREEN=5736
44+
GREEN=5748
45+
46+
<repeats endlessly>

samples/sensor/max30101/boards/hexiwear_mk64f12.overlay renamed to samples/sensor/heart_rate/boards/hexiwear_mk64f12.overlay

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
/ {
8+
aliases {
9+
heart-rate-sensor = &max30101;
10+
};
11+
};
12+
713
&i2c0 {
8-
max30101@57 {
14+
max30101: max30101@57 {
915
status = "okay";
1016
};
1117
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2025, Magpie Embedded
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
heart-rate-sensor = &bh1790;
10+
};
11+
};
12+
13+
&i2c1 {
14+
compatible = "nordic,nrf-twi";
15+
status = "okay";
16+
pinctrl-0 = <&i2c0_default>;
17+
pinctrl-1 = <&i2c0_sleep>;
18+
pinctrl-names = "default", "sleep";
19+
20+
bh1790: bh1790@5b {
21+
compatible = "rohm,bh1790";
22+
reg=<0x5b>;
23+
};
24+
};
File renamed without changes.

samples/sensor/max30101/sample.yaml renamed to samples/sensor/heart_rate/sample.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
sample:
2-
description: TBD
3-
name: TBD
2+
name: Heart Rate Sensor Sample
43
tests:
5-
sample.sensor.max30101:
4+
sample.sensor.heart_rate:
65
harness: sensor
76
tags: sensors
87
platform_allow: hexiwear/mk64f12

samples/sensor/max30101/src/main.c renamed to samples/sensor/heart_rate/src/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
int main(void)
1212
{
1313
struct sensor_value green;
14-
const struct device *const dev = DEVICE_DT_GET_ANY(maxim_max30101);
14+
const struct device *const dev = DEVICE_DT_GET(DT_ALIAS(heart_rate_sensor));
1515

1616
if (dev == NULL) {
17-
printf("Could not get max30101 device\n");
17+
printf("Could not get heart_rate_sensor\n");
1818
return 0;
1919
}
2020
if (!device_is_ready(dev)) {
21-
printf("max30101 device %s is not ready\n", dev->name);
21+
printf("Device %s is not ready\n", dev->name);
2222
return 0;
2323
}
2424

samples/sensor/max30101/README.rst

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)