大数跨境
0
0

Arduino-心率测量

Arduino-心率测量 沛华测控
2021-01-15
2
导读:糟糕!是心动啊~

点击上方蓝字【沛华测控】订阅我们


沛华LabVIEW基础课程|第49讲

LabVIEW+Arduino

MAX30105+OLED


前几天Shania在收拾公室,分类整理模块的时候,突然从一个盒子里发现一块非常mini的屏幕,就是下图这货~



一块0.96英寸大小的OLED,屏幕宽度大概只有我大拇指那么宽吧,这么迷你的屏幕一下子吸引了我的注意


MAX30102-心率脉搏血氧检测传感器


正巧手头上还有一块MAX30102-心率脉搏血氧检测传感器,So,我们今天结合这两个模块来做个简易的心率测试仪玩玩吧~LCD之前也有更新,还没看的小伙伴赶紧点蓝字前去围观👉👉👉LabVIEW+Arduino之LCD显示


请看视频



我们今天用到的MAX30102模块既可以用来测量心率,也可以用来脉搏血氧浓度;采用标准I2C通信接口,可通过软件关断模块,实现超长时间待机。据说三星Galaxy S系列手机就大量应用了此模块


OLED的全称是OrganicLight-Emitting Diode,即有机发光半导体,通过有机分子发光。相较于LCD或LED,OLED优点还挺多的更加纤薄可弯曲,可用于制造曲面屏;高分辨率,无需背光;可视角度广;亮度更大、低功耗;也可应用于新材料,甚至能“印刷”在衣服上……体积可以做得很大,也可以做得很小,还是挺有趣的。


实物接线图

APDS-9960 实物接线图


MAX30102&Arduino接线

VCC→3.3V;

GND→GND;

SDA→A4

SCL→A5


OLED&Arduino接线

VCC→5V;

GND→GND;

SDASDA

SCLSCL


OLEDMAX30102最好不要共用I2C接口。如果你用的Arduino UNO开发板是改进板的话,除了A4、A5,在Digital IO 上方还有另外的I2C接口。



Arduino Code

向上滑动查看Arduino源代码



#include <Wire.h> //Include Wire Library for I2C

#include <Adafruit_GFX.h> //Include Adafruit GFX Library

#include <Adafruit_SSD1306.h> //Include Adafruit OLED Library


#include "MAX30105.h"//Include MAX30105 Library

#include "heartRate.h"//Heart rate calculating algorithm

MAX30105 particleSensor;//Define object MAX30105


#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 64 // OLED display height, in pixels

#define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)


Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);//Declaring the display name (display)


const byte RATE_SIZE = 4; //Increase this for more averaging. 4 is good.

byte rates[RATE_SIZE]; //Array of heart rates

byte rateSpot = 0;

long lastBeat = 0; //Time at which the last beat occurred

float beatsPerMinute;

int beatAvg;



void setup() {

  Wire.begin(); //Start Wire library for I2C

  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize OLED with I2C address 0×3C

  //Serial.begin(115200); //Initialize baud rate


  particleSensor.begin(Wire, I2C_SPEED_FAST); //Use default I2C port, 400kHz speed

  particleSensor.setup(); //Configure sensor with default settings

  particleSensor.setPulseAmplitudeRed(0x0A); //Turn Red LED to low to indicate sensor is running

}


void loop() {

  long irValue = particleSensor.getIR();


  if (checkForBeat(irValue) == true)//If a heart beat is detected

  {

    display.clearDisplay(); //Clear the display

    display.setTextSize(2);

    display.setTextColor(WHITE);

    display.setCursor(0, 0);

    display.print("MaxChina");

    display.setCursor(0, 20);

    display.print("BPM=");

    display.print(beatAvg);

    display.display();

    

    long delta = millis() - lastBeat;

    lastBeat = millis();


    beatsPerMinute = 60 / (delta / 1000.0);


    if (beatsPerMinute < 255 && beatsPerMinute > 20)

    {

      rates[rateSpot++] = (byte)beatsPerMinute; //Store this reading in the array

      rateSpot %= RATE_SIZE; //Wrap variable


      //Take average of readings

      beatAvg = 0;

      for (byte x = 0 ; x < RATE_SIZE ; x++)

        beatAvg += rates[x];

      beatAvg /= RATE_SIZE;

    }

  }


  if (irValue < 50000) {

    beatAvg = 0;

    display.clearDisplay();

    display.setTextSize(2);

    display.setTextColor(WHITE);

    display.setCursor(15, 20);

    display.println("no finger");

    display.display();

  }

}

需要安装的函数库比较多:Adafruit_GFX函数库、Adafruit_SSD1306函数库用于驱动OLED;MAX3010函数库、heartRate函数库用于驱动MAX30102模块;另外还需要用于I2C通信协议的Wire函数库。



以上就是今天的内容~我是Shania~咱们下期再会!



【往期精彩】
LabVIEW+Arduino之电磁炮
声控灯
★温控装置
自动逗猫棒
HMI基础入门教程(3)
LabVIEW+Arduino之RTC
手势识别
语言识别模块
Arduino简易温控装置
★温差发电
LabVIEW+Arduino之简单串口通信
LabVIEW Vision+Arduino之水平+垂直移动跟踪
★LabVIEW Vision 之 OCR
基于LabVIEW+Raspberry Pi 的麦克纳姆轮四驱小车


微信又双叒叕改版
为了不失联&获取最新最好玩的信息
记得星标&置顶我们公众号哟!



置顶方式

1.点击蓝字&扫描二维码进入公众号;
2.按右上方的【●●●】符号;
3.再点击【设为星标】就可以啦!!!



【声明】内容源于网络
0
0
沛华测控
这儿有好玩的LabVIEW基础教程!深圳市沛华测控有限公司/沛华电子科技有限公司是专注于系统设计、研发、软件硬件互相配合并提供整体方案的快速发展的高科技公司,也是NI公司在中国华南地区的合作伙伴。
内容 56
粉丝 0
沛华测控 这儿有好玩的LabVIEW基础教程!深圳市沛华测控有限公司/沛华电子科技有限公司是专注于系统设计、研发、软件硬件互相配合并提供整体方案的快速发展的高科技公司,也是NI公司在中国华南地区的合作伙伴。
总阅读38
粉丝0
内容56