<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Getting &amp;quot;inactive sensor channel&amp;quot; when using more than one channel on heart rate sensor MAX30101 sample code</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/74660/getting-inactive-sensor-channel-when-using-more-than-one-channel-on-heart-rate-sensor-max30101-sample-code</link><description>Hello, I am using: 
 NCS v1.5.1 and the sample code from ~/ncs/v1.5.1/zephyr/drivers/sensor/max30101/ (max30101.c, max30101.h) nRF5340dk MAX30101 from Sparkfun www.sparkfun.com/.../16474 
 Sorry for the newbie question but I am a newer programmer and</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 13 Jun 2021 10:00:48 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/74660/getting-inactive-sensor-channel-when-using-more-than-one-channel-on-heart-rate-sensor-max30101-sample-code" /><item><title>RE: Getting "inactive sensor channel" when using more than one channel on heart rate sensor MAX30101 sample code</title><link>https://devzone.nordicsemi.com/thread/315015?ContentTypeID=1</link><pubDate>Sun, 13 Jun 2021 10:00:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:69439e34-a0ed-4416-9671-97dfb2181797</guid><dc:creator>BennyC</dc:creator><description>&lt;p&gt;Sounds good.&amp;nbsp; I will go through those and open up a new case for any further questions.&lt;/p&gt;
&lt;p&gt;Thanks again for your help!&lt;/p&gt;
&lt;p&gt;Benny&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting "inactive sensor channel" when using more than one channel on heart rate sensor MAX30101 sample code</title><link>https://devzone.nordicsemi.com/thread/314650?ContentTypeID=1</link><pubDate>Thu, 10 Jun 2021 09:59:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:308dc5cd-77c2-435c-bb6d-ba0641c55ac1</guid><dc:creator>Simon</dc:creator><description>[quote user="BennyC"]Could I suggest a similar sample as a starting point for C++? Even a sample working program (with ADC, I2C) if not a full tutorial.[/quote]
&lt;p&gt;Maybe the sample&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/e4f87fba1b8785dcdcd1a3872e592bd7f7b53039/samples/subsys/cpp/cpp_synchronization/src/main.cpp"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/e4f87fba1b8785dcdcd1a3872e592bd7f7b53039/samples/subsys/cpp/cpp_synchronization/src/main.cpp&lt;/a&gt;&amp;nbsp;would be a good option.&lt;/p&gt;
[quote user="BennyC"]I went through the Edge Impulse and Pelion examples, it looks like both of of those use C++ programs running on the embedded platform that can be called by C programs also running on the embedded platform. Basically I would need to write my own C++ wrapper to the biometrics C++ libraries and run it as a thread that can be called by my C programs, is that correct?[/quote]
&lt;p&gt;I don&amp;#39;t know enough about this to give you a qualified answer at the moment.&amp;nbsp;However, check out the application above, that uses a cpp main file.&lt;/p&gt;
&lt;p&gt;This may be worth taking a look at as well&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.5.1/zephyr/reference/kernel/other/cxx_support.html"&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.5.1/zephyr/reference/kernel/other/cxx_support.html&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you open a new DevZone case about this. Since it&amp;#39;s not related to the initial question. You could also try to ask the Zephyr community on slack, or any of these places:&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/2.3.0/guides/getting-help.html#asking-for-help"&gt;https://docs.zephyrproject.org/2.3.0/guides/getting-help.html#asking-for-help&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting "inactive sensor channel" when using more than one channel on heart rate sensor MAX30101 sample code</title><link>https://devzone.nordicsemi.com/thread/314305?ContentTypeID=1</link><pubDate>Wed, 09 Jun 2021 00:30:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00da6d25-62ec-451c-a10a-4c96dc223535</guid><dc:creator>BennyC</dc:creator><description>&lt;p&gt;Thank-you Simon, you answered the original question, so we can mark this thread as answered. Regarding the bigger question of C++ support for sensor algorithms, I will follow up separately, but just wanted a bit of clarification on what you had mentioned here.&lt;/p&gt;
&lt;p&gt;I went through the Edge Impulse and Pelion examples, it looks like both of of those use C++ programs running on the embedded platform that can be called by C programs also running on the embedded platform. Basically I would need to write my own C++ wrapper to the biometrics C++ libraries and run it as a thread that can be called by my C programs, is that correct?&lt;/p&gt;
&lt;p&gt;The option of manually porting the C++ biometrics libraries to C might not be sustainable for me given the large amount, and continually growing and updating revised C++ biometrics libraries in this (health sensors) field.&lt;/p&gt;
&lt;p&gt;The other option of using the command line, west, VS Code, Ozone looks promising and possibly the most sustainable. I looked into this and am comfortable with those tools, but the biggest hurdle appears to be having the base C++ code to get started with the board (nRF5340dk in this case). Is there a sample like a Blinky in C++ for a board like the nRF5340dk? I am aware you wrote a tutorial for Blinky in C. Could I suggest a similar sample as a starting point for C++? Even a sample working program (with ADC, I2C) if not a full tutorial.&lt;/p&gt;
&lt;p&gt;Thanks-very much&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting "inactive sensor channel" when using more than one channel on heart rate sensor MAX30101 sample code</title><link>https://devzone.nordicsemi.com/thread/309291?ContentTypeID=1</link><pubDate>Tue, 11 May 2021 14:37:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8bc0bd9c-17c0-4df0-a71a-1ef44f230c57</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;It seems like the support for C++ in NCS is better now. I talked to a developer internally. He said the the edge_impulse sample works fine. He also mentioned the &lt;a href="https://github.com/nrfconnect/sdk-nrf/tree/675fc5faad5dc83ad28e447042e8a05a1a4f8b88/applications/pelion_client"&gt;pelion_client application&lt;/a&gt;, which also uses C++ (see &lt;a href="https://github.com/nrfconnect/sdk-nrf/tree/675fc5faad5dc83ad28e447042e8a05a1a4f8b88/applications/pelion_client/src/modules"&gt;pelion_client/src/modules&lt;/a&gt;). However, &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/releases/release-notes-1.3.0.html#id3"&gt;it seems like there are some issues with SES&lt;/a&gt;:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;em&gt;&amp;quot;It is not possible to build Thread samples using SEGGER Embedded Studio (SES). SES does not support .cpp files in nRF Connect SDK projects. (NCSDK-5014)&amp;quot;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If you want to use SES, it seems like you need to convert the library to C-code. If not you can build using command line and west+VS code and debug using &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.5.1/zephyr/guides/tools/nordic_segger.html#segger-ozone"&gt;Ozone&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting "inactive sensor channel" when using more than one channel on heart rate sensor MAX30101 sample code</title><link>https://devzone.nordicsemi.com/thread/309275?ContentTypeID=1</link><pubDate>Tue, 11 May 2021 13:42:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:310e263f-8e13-4cf6-b08e-176850b0d0fa</guid><dc:creator>Simon</dc:creator><description>[quote user="BennyC"]&lt;p&gt;I have to ask, when I build and debug now it always stops at this line 12 of my main.c&lt;/p&gt;
&lt;p&gt;const struct device *dev = device_get_binding(DT_LABEL(DT_INST(0, max_max30101)));&lt;/p&gt;[/quote]
&lt;p&gt;It seems like this is something that SEGGER does automatically at start up, it will find main and stop there. Similar to what Ozone does, as discussed &lt;a href="https://forum.segger.com/index.php/Thread/7326-SOLVED-Ozone-v3-20b-not-stopping-at-main/"&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The reason it stops at device_get_binding() instead of the start of main(), is because the code is optimized by default. I&amp;nbsp;confirmed this by turning of optimizations (set&amp;nbsp;&lt;span&gt;&lt;code&gt;CONFIG_DEBUG_OPTIMIZATIONS=y&lt;/code&gt; in &lt;em&gt;prj.conf&lt;/em&gt;&lt;/span&gt;) and saw that it stopped at main().&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;/div&gt;
[quote user="BennyC"]&lt;p&gt;Now that I can get sensor readings I know I need to perform algorithms to get the biometrics (Heart Rate, Blood Oxygen Saturation).&amp;nbsp; &amp;nbsp;In all of my searching, those algorithms only exist for the Arduino.&lt;/p&gt;
&lt;p&gt;ie:&amp;nbsp;&amp;nbsp;&lt;a href="https://github.com/sparkfun/SparkFun_MAX3010x_Sensor_Library"&gt;https://github.com/sparkfun/SparkFun_MAX3010x_Sensor_Library&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If I am trying to get those readings for the nRF5340, what are the best options?&lt;/p&gt;
&lt;p&gt;Manually port the Arduino C++ code to Zephyr C code for the nRF5340 myself?&amp;nbsp;&lt;/p&gt;[/quote]
&lt;p&gt;This DevZone ticket may be helpful regarding this question:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/57362/how-to-add-c-file-to-nrf9160-project-in-ses"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/57362/how-to-add-c-file-to-nrf9160-project-in-ses&lt;/a&gt;. It seems like C++ is not fully supported in SES.&amp;nbsp;We do have more samples using C++ now, like the &lt;a href="https://github.com/nrfconnect/sdk-nrf/tree/707cb281e7e11e0e893945adeeaec0f0fac6a6fa/samples/edge_impulse"&gt;edge_impulse sample&lt;/a&gt;, which uses&amp;nbsp;the library&amp;nbsp;&amp;nbsp;&lt;a title="https://github.com/nrfconnect/sdk-nrf/blob/707cb281e7e11e0e893945adeeaec0f0fac6a6fa/lib/edge_impulse/ei_wrapper.cpp" href="https://github.com/nrfconnect/sdk-nrf/blob/707cb281e7e11e0e893945adeeaec0f0fac6a6fa/lib/edge_impulse/ei_wrapper.cpp" rel="noopener noreferrer" target="_blank"&gt;ei_wrapper.cpp&lt;/a&gt;&amp;nbsp;and in addition we support thread in NCS, which uses C++, so it seems like the situation has changed. I will ask internally to get more information about this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting "inactive sensor channel" when using more than one channel on heart rate sensor MAX30101 sample code</title><link>https://devzone.nordicsemi.com/thread/308879?ContentTypeID=1</link><pubDate>Mon, 10 May 2021 07:59:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7f430122-7bc5-4aea-81df-5441b2291302</guid><dc:creator>BennyC</dc:creator><description>&lt;p&gt;Thanks very much Simon. I made the changes, got past the &amp;quot;Inactive Sensor Channel&amp;quot; errors and am now getting sensor readings! I always appreciate seeing your posts here.&lt;/p&gt;
&lt;p&gt;I have to ask, when I build and debug now it always stops at this line 12 of my main.c&lt;/p&gt;
&lt;p&gt;const struct device *dev = device_get_binding(DT_LABEL(DT_INST(0, max_max30101)));&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;sys/printk.h&amp;gt;
#include &amp;lt;drivers/sensor.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;

void main(void)
{
	struct sensor_value green;
	struct sensor_value ir;
	struct sensor_value red;

	const struct device *dev = device_get_binding(DT_LABEL(DT_INST(0, max_max30101)));

	if (dev == NULL) {
		printf(&amp;quot;Could not get max30101 device\n&amp;quot;);
		return;
	}

	while (1) {
		sensor_sample_fetch(dev);
		printf(&amp;quot;\n==============================================================================\n&amp;quot;);
		
		sensor_channel_get(dev, SENSOR_CHAN_GREEN, &amp;amp;green);
		printf(&amp;quot;GREEN=%d\n&amp;quot;, green.val1);

		sensor_channel_get(dev, SENSOR_CHAN_IR, &amp;amp;ir);
		printf(&amp;quot;IR=%d\n&amp;quot;, ir.val1);
		
		sensor_channel_get(dev, SENSOR_CHAN_RED, &amp;amp;red);
		printf(&amp;quot;RED=%d\n&amp;quot;, red.val1);

		printf(&amp;quot;\n&amp;quot;);
		k_sleep(K_MSEC(5000));
	}
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I can click on the &amp;quot;Continue Execution&amp;quot; green play button and it continues and the rest works as expected, but just wondering if there is a fix for it always stopping there.&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/1040x176/__key/communityserver-discussions-components-files/4/pastedimage1620632938859v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now that I can get sensor readings I know I need to perform algorithms to get the biometrics (Heart Rate, Blood Oxygen Saturation).&amp;nbsp; &amp;nbsp;In all of my searching, those algorithms only exist for the Arduino.&lt;/p&gt;
&lt;p&gt;ie:&amp;nbsp;&amp;nbsp;&lt;a href="https://github.com/sparkfun/SparkFun_MAX3010x_Sensor_Library"&gt;https://github.com/sparkfun/SparkFun_MAX3010x_Sensor_Library&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If I am trying to get those readings for the nRF5340, what are the best options?&lt;/p&gt;
&lt;p&gt;Manually port the Arduino C++ code to Zephyr C code for the nRF5340 myself?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Do you know of&amp;nbsp;any initiatives that would be working on this kind of porting already?&amp;nbsp; (I think it would be a fairly high demand common algorithm to work with wearables.)&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting "inactive sensor channel" when using more than one channel on heart rate sensor MAX30101 sample code</title><link>https://devzone.nordicsemi.com/thread/308321?ContentTypeID=1</link><pubDate>Wed, 05 May 2021 10:18:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:94bf53d1-2854-43a5-8b7b-dfd9eb7752e5</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I took a look at the max30101 code and I think I know how to go about this.&lt;/p&gt;
&lt;p&gt;If you take a look at this code snippet:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.4.99-ncs2/drivers/sensor/max30101/max30101.c#L232-L237:"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v2.4.99-ncs2/drivers/sensor/max30101/max30101.c#L232-L237&lt;/a&gt;, you will see how the fifo channels are associated with the led channels.&lt;/p&gt;
&lt;p&gt;I think you can think of it like this, if I have understood it correctly:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;.mode = MAX30101_MODE_MULTI_LED,
.slot[&amp;lt;fifo_chan&amp;gt;] = &amp;lt;led_chan&amp;gt;+1,
.slot[&amp;lt;fifo_chan&amp;gt;] = &amp;lt;led_chan&amp;gt;+1,
.slot[&amp;lt;fifo_chan&amp;gt;] = &amp;lt;led_chan&amp;gt;+1,
.slot[&amp;lt;fifo_chan&amp;gt;] = &amp;lt;led_chan&amp;gt;+1,&lt;/pre&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;Most of the&amp;nbsp;configs CONFIG_MAX30101_SLOTx will default to 0, which means they are disabled, and that&amp;#39;s the reason it fails for you I think.&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;So in your prj.conf, in addition to enabling&amp;nbsp;CONFIG_MAX30101_MULTI_LED_MODE, try assigning a value to the configs&amp;nbsp;CONFIG_MAX30101_SLOTx:&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v2.4.99-ncs2/drivers/sensor/max30101/Kconfig#L141-L199"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v2.4.99-ncs2/drivers/sensor/max30101/Kconfig#L141-L199&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t have a max30101 sensor at hand, and haven&amp;#39;t tested this, so I may have overlooked something.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting "inactive sensor channel" when using more than one channel on heart rate sensor MAX30101 sample code</title><link>https://devzone.nordicsemi.com/thread/307816?ContentTypeID=1</link><pubDate>Mon, 03 May 2021 00:33:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8edf01a7-e90c-48bd-a2a6-e08275d1939e</guid><dc:creator>BennyC</dc:creator><description>&lt;p&gt;Thank-you very much for the reply, Wasan.&lt;/p&gt;
&lt;p&gt;I edited my prj.conf according to your suggestions, re-opened the project, re-built, and re-run, but I am getting the same output as before where RED is always 0 and IR is always 29473.&lt;/p&gt;
&lt;p&gt;Here is my prj.conf:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_SERIAL=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_LOG=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_SENSOR_LOG_LEVEL_DBG=y
CONFIG_MAX30101=y
CONFIG_MAX30101_MULTI_LED_MODE=y
CONFIG_MAX30101_LED2_PA=0x0f&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;In max30101.c the part that confuses me is line 78 to 87 since fifo_chan always gets set to 3 when led_chan is 1 or 0, which is what throws the &amp;quot;Inactive sensor channel&amp;quot; error.&amp;nbsp; What is the right way to activate those 2 channels correctly in code and as a result set fifo_chan to a correct value and avoid the error?&lt;/p&gt;
&lt;p&gt;Lines 195 to 211 Initialize the channel map and active channel count, but should I change the code there (and to what?) or is that only for initialization as the comments state?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/*
 * Copyright (c) 2017, NXP
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#define DT_DRV_COMPAT max_max30101

#include &amp;lt;logging/log.h&amp;gt;

#include &amp;quot;max30101.h&amp;quot;

LOG_MODULE_REGISTER(MAX30101, CONFIG_SENSOR_LOG_LEVEL);

static int max30101_sample_fetch(const struct device *dev,
				 enum sensor_channel chan)
{
	struct max30101_data *data = dev-&amp;gt;data;
	const struct max30101_config *config = dev-&amp;gt;config;
	uint8_t buffer[MAX30101_MAX_BYTES_PER_SAMPLE];
	uint32_t fifo_data;
	int fifo_chan;
	int num_bytes;
	int i;

	/* Read all the active channels for one sample */
	num_bytes = data-&amp;gt;num_channels * MAX30101_BYTES_PER_CHANNEL;
	if (i2c_burst_read(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			   MAX30101_REG_FIFO_DATA, buffer, num_bytes)) {
		LOG_ERR(&amp;quot;Could not fetch sample&amp;quot;);
		return -EIO;
	}

	fifo_chan = 0;
	for (i = 0; i &amp;lt; num_bytes; i += 3) {
		/* Each channel is 18-bits */
		fifo_data = (buffer[i] &amp;lt;&amp;lt; 16) | (buffer[i + 1] &amp;lt;&amp;lt; 8) |
			    (buffer[i + 2]);
		fifo_data &amp;amp;= MAX30101_FIFO_DATA_MASK;

		/* Save the raw data */
		data-&amp;gt;raw[fifo_chan++] = fifo_data;
	}

	return 0;
}

static int max30101_channel_get(const struct device *dev,
				enum sensor_channel chan,
				struct sensor_value *val)
{
	struct max30101_data *data = dev-&amp;gt;data;
	enum max30101_led_channel led_chan;
	int fifo_chan;

	switch (chan) {
	case SENSOR_CHAN_RED:
		led_chan = MAX30101_LED_CHANNEL_RED;
		break;

	case SENSOR_CHAN_IR:
		led_chan = MAX30101_LED_CHANNEL_IR;
		break;

	case SENSOR_CHAN_GREEN:
		led_chan = MAX30101_LED_CHANNEL_GREEN;
		break;

	default:
		LOG_ERR(&amp;quot;Unsupported sensor channel&amp;quot;);
		return -ENOTSUP;
	}

	/* Check if the led channel is active by looking up the associated fifo
	 * channel. If the fifo channel isn&amp;#39;t valid, then the led channel
	 * isn&amp;#39;t active.
	 */
	fifo_chan = data-&amp;gt;map[led_chan];

// begin what I added
	LOG_ERR(&amp;quot;led_chan: %d. fifo_chan: %d. MAX30101_MAX_NUM_CHANNELS: %d  &amp;quot;, led_chan, fifo_chan, MAX30101_MAX_NUM_CHANNELS);
// end what I added

	if (fifo_chan &amp;gt;= MAX30101_MAX_NUM_CHANNELS) {
		LOG_ERR(&amp;quot;Inactive sensor channel\n&amp;quot;);
		return -ENOTSUP;
	}


	/* TODO: Scale the raw data to standard units */
	val-&amp;gt;val1 = data-&amp;gt;raw[fifo_chan];
	val-&amp;gt;val2 = 0;

	return 0;
}

static const struct sensor_driver_api max30101_driver_api = {
	.sample_fetch = max30101_sample_fetch,
	.channel_get = max30101_channel_get,
};

static int max30101_init(const struct device *dev)
{
	const struct max30101_config *config = dev-&amp;gt;config;
	struct max30101_data *data = dev-&amp;gt;data;
	uint8_t part_id;
	uint8_t mode_cfg;
	uint32_t led_chan;
	int fifo_chan;

	/* Get the I2C device */
	data-&amp;gt;i2c = device_get_binding(config-&amp;gt;i2c_label);
	if (!data-&amp;gt;i2c) {
		LOG_ERR(&amp;quot;Could not find I2C device&amp;quot;);
		return -EINVAL;
	}

	/* Check the part id to make sure this is MAX30101 */
	if (i2c_reg_read_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			      MAX30101_REG_PART_ID, &amp;amp;part_id)) {
		LOG_ERR(&amp;quot;Could not get Part ID&amp;quot;);
		return -EIO;
	}
	if (part_id != MAX30101_PART_ID) {
		LOG_ERR(&amp;quot;Got Part ID 0x%02x, expected 0x%02x&amp;quot;,
			    part_id, MAX30101_PART_ID);
		return -EIO;
	}

	/* Reset the sensor */
	if (i2c_reg_write_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			       MAX30101_REG_MODE_CFG,
			       MAX30101_MODE_CFG_RESET_MASK)) {
		return -EIO;
	}

	/* Wait for reset to be cleared */
	do {
		if (i2c_reg_read_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
				      MAX30101_REG_MODE_CFG, &amp;amp;mode_cfg)) {
			LOG_ERR(&amp;quot;Could read mode cfg after reset&amp;quot;);
			return -EIO;
		}
	} while (mode_cfg &amp;amp; MAX30101_MODE_CFG_RESET_MASK);

	/* Write the FIFO configuration register */
	if (i2c_reg_write_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			       MAX30101_REG_FIFO_CFG, config-&amp;gt;fifo)) {
		return -EIO;
	}

	/* Write the mode configuration register */
	if (i2c_reg_write_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			       MAX30101_REG_MODE_CFG, config-&amp;gt;mode)) {
		return -EIO;
	}

	/* Write the SpO2 configuration register */
	if (i2c_reg_write_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			       MAX30101_REG_SPO2_CFG, config-&amp;gt;spo2)) {
		return -EIO;
	}

	/* Write the LED pulse amplitude registers */
	if (i2c_reg_write_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			       MAX30101_REG_LED1_PA, config-&amp;gt;led_pa[0])) {
		return -EIO;
	}
	if (i2c_reg_write_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			       MAX30101_REG_LED2_PA, config-&amp;gt;led_pa[1])) {
		return -EIO;
	}
	if (i2c_reg_write_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			       MAX30101_REG_LED3_PA, config-&amp;gt;led_pa[2])) {
		return -EIO;
	}

#ifdef CONFIG_MAX30101_MULTI_LED_MODE
	uint8_t multi_led[2];

	/* Write the multi-LED mode control registers */
	multi_led[0] = (config-&amp;gt;slot[1] &amp;lt;&amp;lt; 4) | (config-&amp;gt;slot[0]);
	multi_led[1] = (config-&amp;gt;slot[3] &amp;lt;&amp;lt; 4) | (config-&amp;gt;slot[2]);

	if (i2c_reg_write_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			       MAX30101_REG_MULTI_LED, multi_led[0])) {
		return -EIO;
	}
	if (i2c_reg_write_byte(data-&amp;gt;i2c, config-&amp;gt;i2c_addr,
			       MAX30101_REG_MULTI_LED + 1, multi_led[1])) {
		return -EIO;
	}
#endif

	/* Initialize the channel map and active channel count */
	data-&amp;gt;num_channels = 0U;
	for (led_chan = 0U; led_chan &amp;lt; MAX30101_MAX_NUM_CHANNELS; led_chan++) {
		data-&amp;gt;map[led_chan] = MAX30101_MAX_NUM_CHANNELS;
	}

	/* Count the number of active channels and build a map that translates
	 * the LED channel number (red/ir/green) to the fifo channel number.
	 */
	for (fifo_chan = 0; fifo_chan &amp;lt; MAX30101_MAX_NUM_CHANNELS;
	     fifo_chan++) {
		led_chan = (config-&amp;gt;slot[fifo_chan] &amp;amp; MAX30101_SLOT_LED_MASK)-1;
		if (led_chan &amp;lt; MAX30101_MAX_NUM_CHANNELS) {
			data-&amp;gt;map[led_chan] = fifo_chan;
			data-&amp;gt;num_channels++;
		}
	}

	return 0;
}

static struct max30101_config max30101_config = {
	.i2c_label = DT_INST_BUS_LABEL(0),
	.i2c_addr = DT_INST_REG_ADDR(0),
	.fifo = (CONFIG_MAX30101_SMP_AVE &amp;lt;&amp;lt; MAX30101_FIFO_CFG_SMP_AVE_SHIFT) |
#ifdef CONFIG_MAX30101_FIFO_ROLLOVER_EN
		MAX30101_FIFO_CFG_ROLLOVER_EN_MASK |
#endif
		(CONFIG_MAX30101_FIFO_A_FULL &amp;lt;&amp;lt;
		 MAX30101_FIFO_CFG_FIFO_FULL_SHIFT),

#if defined(CONFIG_MAX30101_HEART_RATE_MODE)
	.mode = MAX30101_MODE_HEART_RATE,
	.slot[0] = MAX30101_SLOT_RED_LED1_PA,
	.slot[1] = MAX30101_SLOT_DISABLED,
	.slot[2] = MAX30101_SLOT_DISABLED,
	.slot[3] = MAX30101_SLOT_DISABLED,
#elif defined(CONFIG_MAX30101_SPO2_MODE)
	.mode = MAX30101_MODE_SPO2,
	.slot[0] = MAX30101_SLOT_RED_LED1_PA,
	.slot[1] = MAX30101_SLOT_IR_LED2_PA,
	.slot[2] = MAX30101_SLOT_DISABLED,
	.slot[3] = MAX30101_SLOT_DISABLED,
#else
	.mode = MAX30101_MODE_MULTI_LED,
	.slot[0] = CONFIG_MAX30101_SLOT1,
	.slot[1] = CONFIG_MAX30101_SLOT2,
	.slot[2] = CONFIG_MAX30101_SLOT3,
	.slot[3] = CONFIG_MAX30101_SLOT4,
#endif

	.spo2 = (CONFIG_MAX30101_ADC_RGE &amp;lt;&amp;lt; MAX30101_SPO2_ADC_RGE_SHIFT) |
		(CONFIG_MAX30101_SR &amp;lt;&amp;lt; MAX30101_SPO2_SR_SHIFT) |
		(MAX30101_PW_18BITS &amp;lt;&amp;lt; MAX30101_SPO2_PW_SHIFT),

	.led_pa[0] = CONFIG_MAX30101_LED1_PA,
	.led_pa[1] = CONFIG_MAX30101_LED2_PA,
	.led_pa[2] = CONFIG_MAX30101_LED3_PA,
};

static struct max30101_data max30101_data;

DEVICE_DT_INST_DEFINE(0, max30101_init, device_pm_control_nop,
		    &amp;amp;max30101_data, &amp;amp;max30101_config,
		    POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
		    &amp;amp;max30101_driver_api);
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Getting "inactive sensor channel" when using more than one channel on heart rate sensor MAX30101 sample code</title><link>https://devzone.nordicsemi.com/thread/307775?ContentTypeID=1</link><pubDate>Sun, 02 May 2021 03:17:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a21925f-7eeb-46ad-b906-9b60c4c70ad0</guid><dc:creator>wasan</dc:creator><description>&lt;p&gt;For fix RED LED is 0. I think you can try add config as below to prj.conf&lt;/p&gt;
&lt;p&gt;CONFIG_MAX30101_MULTI_LED_MODE=y&lt;/p&gt;
&lt;p&gt;About IR LED&amp;nbsp;&lt;span&gt;is always at the maximum value. I think you can try setup led power to&amp;nbsp;reduce the brightness.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;CONFIG_MAX30101_LED2_PA=0x0f&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;You can see all max30101 configulation&amp;nbsp; at &amp;quot;$YOUR_SDK_DIR\ncs\v1.5.0\zephyr\drivers\sensor\max30101\Kconfig&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This is a example for config IR LED power from Kconfig file.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;config MAX30101_LED2_PA&lt;br /&gt;&amp;nbsp; &amp;nbsp;hex &amp;quot;LED2 (IR) pulse amplitude&amp;quot;&lt;br /&gt;&amp;nbsp; &amp;nbsp;range 0 0xff&lt;br /&gt;&amp;nbsp; &amp;nbsp;default 0x33&amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;help&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Set the pulse amplitude to control the LED2 (IR) current. The actual&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; measured LED current for each part can vary significantly due to the&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; trimming methodology.&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0x00 = 0.0 mA&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0x01 = 0.2 mA&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0x02 = 0.4 mA&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0x0f = 3.1 mA&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0xff = 50.0 mA&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Wasan&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>