0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

#旭日X3派首百尝鲜# 【AI健身实体机】Arduino使用MAX30102人体心率血氧检测模块在X3派上位机上的显示

地平线机器人 2022-07-27 16:19 次阅读

一、Arduino与旭日X3派通信

1.查看X3派上python是否安装serial包

pYYBAGLg8eGAJp9PAAAxOqHTrJk179.png

2.X3派与Arduino之间通过USB进行通信

poYBAGLg8eyAGBaAAA1XJhJatUE823.png

3.在终端上输入 ls /dev/tty* 出现ACM0说明两者可以正常通信

poYBAGLg8eGAAAdUAAB5lrRFEok395.png

4.在Arduino上烧录代码

void setup() { Serial.begin(9600);}void loop(){ if ( Serial.available()) { if('s' == Serial.read()) Serial.println("HelloWorld!"); }}

5.在X3派上测试是否能够收到信息

在终端下通过python3进行测试

最后print可以出现HelloWorld!

import serialser=serial.Serial('/dev/ttyACM0',9600,timeout=1)while 1: ser.write('s'.encode()) msg=ser.readall() print(msg)

ser.write('s')会报编码的错误,使用方法encode()解决。

pYYBAGLg8eGAMs-pAADA09EvquE363.png

6.权限不够,退出后终端输入sudo su进入管理员模式可以解决

poYBAGLg8eGAMyBbAAC-dRWfW2k146.png

二、MAX30102人体心率血氧检测模块在上位机旭日X3派上的数据显示

1.MAX30102

MAX30102是一种用于可穿戴健康设备的高灵敏度脉搏血氧仪和心率传感器

MAX30102内部集成了一整套完整信号采集电路,包括光信号发射及接收、AD转换、环境光干扰消除及数字滤波部分,只将数字接口留给用户。

pYYBAGLg8eKAFDWUAAF-HCn-ohY762.png

2.Arduino代码

#include #include "MAX30105.h"#include "spo2_algorithm.h"MAX30105 particleSensor;#define MAX_BRIGHTNESS 255#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)//Arduino Uno doesn't have enough SRAM to store 100 samples of IR led data and red led data in 32-bit format//To solve this problem, 16-bit MSB of the sampled data will be truncated. Samples become 16-bit data.uint16_t irBuffer[100]; //infrared LED sensor datauint16_t redBuffer[100]; //red LED sensor data#elseuint32_t irBuffer[100]; //infrared LED sensor datauint32_t redBuffer[100]; //red LED sensor data#endifint32_t bufferLength; //data lengthint32_t spo2; //SPO2 valueint8_t validSPO2; //indicator to show if the SPO2 calculation is validint32_t heartRate; //heart rate valueint8_t validHeartRate; //indicator to show if the heart rate calculation is validbyte pulseLED = 11; //Must be on PWM pinbyte readLED = 13; //Blinks with each data readvoid setup(){ Serial.begin(115200); // initialize serial communication at 115200 bits per second: pinMode(pulseLED, OUTPUT); pinMode(readLED, OUTPUT); // Initialize sensor if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed { Serial.println(F("MAX30105 was not found. Please check wiring/power.")); while (1); } //Serial.println(F("Attach sensor to finger with rubber band. Press any key to start conversion")); //while (Serial.available() == 0) ; //wait until user presses a key //Serial.read(); byte ledBrightness = 60; //Options: 0=Off to 255=50mA byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32 byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green byte sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200 int pulseWidth = 411; //Options: 69, 118, 215, 411 int adcRange = 4096; //Options: 2048, 4096, 8192, 16384 particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings}void loop(){ bufferLength = 100; //buffer length of 100 stores 4 seconds of samples running at 25sps //read the first 100 samples, and determine the signal range for (byte i = 0 ; i < bufferLength ; i++) { while (particleSensor.available() == false) //do we have new data? particleSensor.check(); //Check the sensor for new data redBuffer[i] = particleSensor.getRed(); irBuffer[i] = particleSensor.getIR(); particleSensor.nextSample(); //We're finished with this sample so move to next sample Serial.print(F("red=")); Serial.print(redBuffer[i], DEC); Serial.print(F(", ir=")); Serial.println(irBuffer[i], DEC); } //calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples) maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate); //Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second while (1) { //dumping the first 25 sets of samples in the memory and shift the last 75 sets of samples to the top for (byte i = 25; i < 100; i++) { redBuffer[i - 25] = redBuffer[i]; irBuffer[i - 25] = irBuffer[i]; } //take 25 sets of samples before calculating the heart rate. for (byte i = 75; i < 100; i++) { while (particleSensor.available() == false) //do we have new data? particleSensor.check(); //Check the sensor for new data digitalWrite(readLED, !digitalRead(readLED)); //Blink onboard LED with every data read redBuffer[i] = particleSensor.getRed(); irBuffer[i] = particleSensor.getIR(); particleSensor.nextSample(); //We're finished with this sample so move to next sample //send samples and calculation result to terminal program through UART //Serial.print(F("red=")); //Serial.print(redBuffer[i], DEC); //Serial.print(F(", ir=")); //Serial.print(irBuffer[i], DEC); Serial.print(F(", HR=")); Serial.print(heartRate, DEC); //Serial.print(F(", HRvalid=")); //Serial.print(validHeartRate, DEC); Serial.print(F(", SPO2=")); Serial.println(spo2, DEC); //Serial.print(F(", SPO2Valid=")); //Serial.println(validSPO2, DEC); } //After gathering 25 new samples recalculate HR and SP02 maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate); }}

3.接线

VCC----5V

GND---GND

SCL----A5

SDA---A4

将MAX30102周围用绝缘黑胶布包裹起来,避免手碰到电阻对结果产生影响

poYBAGLg8eKAES2KAACDEabj6MI275.png

4.X3派代码

sudo nano max30102_test.py

import serialser=serial.Serial('/dev/ttyACM0',115200,timeout=1)while 1: msg=ser.read(10) print(msg)

5.运行代码

python3 max30102_test.py

将手放上测量心率血氧,心率可以较快得出,血氧需要等待较久。

HR为心率,SPO2为血氧,ir和red为计算的中间值。

pYYBAGLg8eKASIx8AAAOKRPl3Fo874.png


本文转自地平线开发者社区

原作者:jmulin

原链接:https://developer.horizon.ai/forumDetail/98129540173361549

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 嵌入式
    +关注

    关注

    4983

    文章

    18286

    浏览量

    288486
  • AI
    AI
    +关注

    关注

    87

    文章

    26457

    浏览量

    264070
  • 人工智能
    +关注

    关注

    1776

    文章

    43871

    浏览量

    230620
收藏 人收藏

    评论

    相关推荐

    科大讯飞推出AI扫拖机器X3:主打“指哪扫哪”

    机器AI
    北京中科同志科技股份有限公司
    发布于 :2024年02月22日 10:11:12

    max30100和max30102的区别

    30100和MAX30102都是用于非侵入性测量的传感器,可以通过脉搏波检测和光电测量来监测心率和血氧饱和度。它们采用的技术原理是脉搏氧饱和度测量(SpO2)。 MAX30100和
    的头像 发表于 12-28 16:54 2099次阅读

    【开源项目】Emo:基于树莓 4B DIY 能笑会动的桌面机器

    USB 模块的位置上,它可以侦测到机器周围产生的任何振动。 底座部分由以下三根导线组成:VCC、GND 和震动传感器的输出导线。 最后,我们使用 M3 x 10 mm 螺栓将盖子
    发表于 12-26 15:18

    【悟空H3开发板免费体验】基于悟空H3开发板实现:三全向轮小车速度控制、里程反馈

    非常出色。成功安装了ROS操作系统。 ROS的各种库和工具可以完美运行在悟空H3上,为机器应用提供了广泛的功能支持。 3. 控制和键盘操作 我成功地将悟空
    发表于 11-02 01:37

    树莓3树莓4原理图分享

    提供了树莓3、树莓3B、树莓4版本的原理图
    发表于 09-27 07:58

    【悟空H3开发板免费体验】悟空H3开发板

    个Arm Cortex-A53内核。我的测试中,悟空H3开发板能够流畅运行Linux、Android等操作系统。 接口丰富 :悟空H3
    发表于 09-19 10:04

    Arm Cortex‑X3核心加密扩展技术参考手册

    Cortex®-X3内核支持可选的ARMv8.0-A和ARM®v8.2-A加密扩展。 Armv8.0-A加密扩展向Advanced SIMD添加了A64指令,以加速高级加密标准(AES)加密和解
    发表于 08-17 06:25

    ARM Cortex-X3核心技术参考手册

    计算应用。 Cortex®-X3核心Dynamiq™-110群集中实施,并始终连接到Dynamiq™共享单元-110(DSU-110),该共享单元与L3缓存和监听控制完全互连。此配置还可用于具有不同类型内核的系统,其中Cor
    发表于 08-09 07:39

    【CW32饭盒开发板试用体验】+串行通信与MP3播放控制

    CW32饭盒提供了多个串行接口,提供串口可进行数据的交互和串口设备的控制,这里是利用串口来控制MP3播放模块,从而使饭盒能轻松地实现音乐播放功能。 为了控制MP
    发表于 06-19 09:41

    手指测原理是什么?

    仪测的就是这个饱和度。血红蛋白有携带氧气的状态,当然也有空载状态,我们把携带氧气的血红蛋白称为合血红蛋白,空载状态的血红蛋白称为
    发表于 06-16 07:01

    ​使用旭日X3派实现手势检测

    本篇博客通过旭日X3搭载手势识别算法,实现实时检测,同时测试其运行性能。
    的头像 发表于 06-02 17:36 565次阅读
    ​使用<b class='flag-5'>旭日</b><b class='flag-5'>X3</b>派实现手势<b class='flag-5'>检测</b>

    基于STM32物联网开发板(7)--心率血氧采集MAX30102

    MAX30102是一种集成的脉搏血氧计心率监测模块。它包括内部LED,光电探测器、光学元件和低噪声电子器件具有环境光抑制。MAX30102提供简化设计过程的完整系统解决方案用于移动和可
    的头像 发表于 05-24 11:10 6005次阅读
    基于STM32物联网开发板(7)--<b class='flag-5'>心率</b>血氧采集<b class='flag-5'>MAX30102</b>

    【CW32饭盒开发板试用体验】+温度大气压检测

    long up; long x1, x2, b5, b6, x3, b3, p; unsigned long b4, b7; ut = bmp085ReadTemp(); up
    发表于 05-15 11:16