<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Heart rate and NCIR competition core2]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">I am working on a core 2 v1 module with a NCIR and a heart rate module connected by a grove hub and they both work perfectly fine individually (when only one is plugged in and when they are both plugged in) : whatever the first one I select, it works perfectly but when I want to switch from getting data from the heart rate module to the NCIR module, (or NCIR to heart rate), everything freezes.</p>
<p dir="auto">Here is my code if it helps:</p>
<p dir="auto">rom m5stack import *<br />
from m5stack_ui import *<br />
from m5ui import *<br />
from uiflow import *<br />
import time<br />
import wifiCfg<br />
import urequests<br />
import unit</p>
<h1>INITIATE</h1>
<p dir="auto">screen = M5Screen()<br />
screen.clean_screen()<br />
screen.set_screen_bg_color(0xFFFFFF)<br />
ncir2  = unit.get(unit.NCIR, unit.PORTA)<br />
heart = unit.get(unit.HEART, unit.PORTA)</p>
<p dir="auto">heart.setLedCurrent(0x04, 0x01)<br />
heart.setMode(0x03) # HR &amp; SpO2</p>
<p dir="auto">set_record = 0<br />
wifiCfg.autoConnect(lcdShow=False)</p>
<h1>LABELS</h1>
<p dir="auto">instructions1     = M5Label('Posez votre index gauche sur le capteur', x=15, y=10, color=0xbc0c21, font=FONT_MONT_14, parent=None) # y+15 between lines</p>
<p dir="auto">HeartRate         = M5Label('Heart', x=15, y=114, color=0x509ed3, font=FONT_MONT_30, parent=None)<br />
sp                = M5Label('SpO2', x=129, y=114, color=0x509ed3, font=FONT_MONT_30, parent=None)<br />
temperature_label = M5Label('Temp', x=229, y=114, color=0x509ed3, font=FONT_MONT_30, parent=None)</p>
<h1>IMAGES</h1>
<p dir="auto">image_oxy    = M5Img("res/oximeter.png", x=133, y=46, parent=None)<br />
image_pulse  = M5Img("res/pulse.png", x=20, y=46, parent=None)<br />
image_thermo = M5Img("res/thermometer.png", x=238, y=46, parent=None)</p>
<p dir="auto">radius = 20</p>
<h1>green 0x33b151</h1>
<h1>red 0xb10707</h1>
<p dir="auto">button_cardiac  = M5Btn(text='O', x=120, y=200, w=radius, h=radius, bg_c=0xb10707, text_c=0xFFFFFF, font=FONT_MONT_14, parent=None)<br />
button_temp     = M5Btn(text='O', x=170, y=200, w=radius, h=radius, bg_c=0xb10707, text_c=0xFFFFFF, font=FONT_MONT_14, parent=None)</p>
<p dir="auto">def button_cardiac_pressed():<br />
global set_record<br />
button_cardiac  = M5Btn(text='I', x=120, y=200, w=radius, h=radius, bg_c=0x33b151, text_c=0xFFFFFF, font=FONT_MONT_14, parent=None)<br />
button_temp     = M5Btn(text='O', x=170, y=200, w=radius, h=radius, bg_c=0xb10707, text_c=0xFFFFFF, font=FONT_MONT_14, parent=None)<br />
set_record = 1<br />
pass</p>
<p dir="auto">button_cardiac.pressed(button_cardiac_pressed)</p>
<p dir="auto">def button_temp_pressed():<br />
global set_record<br />
button_cardiac  = M5Btn(text='O', x=120, y=200, w=radius, h=radius, bg_c=0xb10707, text_c=0xFFFFFF, font=FONT_MONT_14, parent=None)<br />
button_temp     = M5Btn(text='I', x=170, y=200, w=radius, h=radius, bg_c=0x33b151, text_c=0xFFFFFF, font=FONT_MONT_14, parent=None)<br />
set_record = 2<br />
pass</p>
<p dir="auto">button_temp.pressed(button_temp_pressed)</p>
<p dir="auto">while True:</p>
<pre><code>button_temp.pressed(button_temp_pressed)
button_cardiac.pressed(button_cardiac_pressed)

if set_record == 1:
    # HR
    hr = int(heart.getHeartRate()/3)
    HeartRate.set_text(str(hr))
    label_heart_value = M5Label('bpm', x=70,  y=125, color=0x509ed3, font=FONT_MONT_14, parent=None)

    # O2 SAT
    delta = 5
    spo2 = heart.getSpO2()+delta
    if spo2 &gt; 100:
        spo2 = 100
    elif spo2 == delta:
        spo2 = 0
    
    sp.set_text(str(spo2))
    label_spo2_value  = M5Label('%', x=180, y=120, color=0x509ed3, font=FONT_MONT_14, parent=None)
    wait(1)
    pass
 
elif set_record == 2:
    temperature = ncir2.temperature
    wait(0.2)
    temperature_label.set_text(str(temperature))
    label_temp_value  = M5Label('°C',  x=300, y=125, color=0x509ed3, font=FONT_MONT_14, parent=None)
    wait(1)
    pass
</code></pre>
<p dir="auto">Thank you so much for your help!</p>
]]></description><link>https://community.m5stack.com/topic/7308/heart-rate-and-ncir-competition-core2</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Mar 2026 02:46:55 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/7308.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Feb 2025 10:10:07 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Heart rate and NCIR competition core2 on Fri, 21 Feb 2025 11:59:30 GMT]]></title><description><![CDATA[<p dir="auto">Hi all,</p>
<p dir="auto">I have been looking for the answer to my problem and my best guest might be the fact that they both are using PortA, thus the competition.</p>
<p dir="auto">Is there a way to switch from one sensor to another to get a reading from both?</p>
<p dir="auto">Thank you in advance :)</p>
]]></description><link>https://community.m5stack.com/post/28295</link><guid isPermaLink="true">https://community.m5stack.com/post/28295</guid><dc:creator><![CDATA[mromandmonnier]]></dc:creator><pubDate>Fri, 21 Feb 2025 11:59:30 GMT</pubDate></item></channel></rss>