🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Heart rate and NCIR competition core2

    Core 2
    1
    2
    271
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      mromandmonnier
      last edited by

      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 unit

      INITIATE

      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 & SpO2

      set_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
      pass

      button_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
      pass

      button_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)
          pass
      

      Thank you so much for your help!

      M 1 Reply Last reply Reply Quote 0
      • M
        mromandmonnier @mromandmonnier
        last edited by

        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 :)

        1 Reply Last reply Reply Quote 1
        • First post
          Last post