Heart rate and NCIR competition core2
-
Hi all,
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.
Here is my code if it helps:
rom m5stack import *
from m5stack_ui import *
from m5ui import *
from uiflow import *
import time
import wifiCfg
import urequests
import unitINITIATE
screen = M5Screen()
screen.clean_screen()
screen.set_screen_bg_color(0xFFFFFF)
ncir2 = unit.get(unit.NCIR, unit.PORTA)
heart = unit.get(unit.HEART, unit.PORTA)heart.setLedCurrent(0x04, 0x01)
heart.setMode(0x03) # HR & SpO2set_record = 0
wifiCfg.autoConnect(lcdShow=False)LABELS
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
HeartRate = M5Label('Heart', x=15, y=114, color=0x509ed3, font=FONT_MONT_30, parent=None)
sp = M5Label('SpO2', x=129, y=114, color=0x509ed3, font=FONT_MONT_30, parent=None)
temperature_label = M5Label('Temp', x=229, y=114, color=0x509ed3, font=FONT_MONT_30, parent=None)IMAGES
image_oxy = M5Img("res/oximeter.png", x=133, y=46, parent=None)
image_pulse = M5Img("res/pulse.png", x=20, y=46, parent=None)
image_thermo = M5Img("res/thermometer.png", x=238, y=46, parent=None)radius = 20
green 0x33b151
red 0xb10707
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)
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)def button_cardiac_pressed():
global set_record
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)
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)
set_record = 1
passbutton_cardiac.pressed(button_cardiac_pressed)
def button_temp_pressed():
global set_record
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)
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)
set_record = 2
passbutton_temp.pressed(button_temp_pressed)
while True:
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 > 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) passThank you so much for your help!
-
Hi all,
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.
Is there a way to switch from one sensor to another to get a reading from both?
Thank you in advance :)
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login