一、arduino与旭日x3派通信
1.查看x3派上python是否安装serial包
2.x3派与arduino之间通过usb进行通信
3.在终端上输入 ls /dev/tty* 出现acm0说明两者可以正常通信
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()解决。
6.权限不够,退出后终端输入sudo su进入管理员模式可以解决
二、max30102人体心率血氧检测模块在上位机旭日x3派上的数据显示
1.max30102
max30102是一种用于可穿戴健康设备的高灵敏度脉搏血氧仪和心率传感器。
max30102内部集成了一整套完整信号采集电路,包括光信号发射及接收、ad转换、环境光干扰消除及数字滤波部分,只将数字接口留给用户。
2.arduino代码
#include #include max30105.h#include spo2_algorithm.hmax30105 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周围用绝缘黑胶布包裹起来,避免手碰到电阻对结果产生影响
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为计算的中间值。
本文转自地平线开发者社区
原作者:jmulin
原链接:https://developer.horizon.ai/forumdetail/98129540173361549
预测到2025年,5G市场规模将达到449亿美元
符合EMI/EMC标准的SerDes——基本测试策略和指南
人工智能如何助力生物技术公司成功研制疫苗
日本丰田带来了 i-TRIL 概念车
机加工自动化生产线怎么维护保养?
#旭日X3派首百尝鲜# 【AI健身实体机】Arduino使用MAX30102人体心率血氧检测模块在X3派上位机上的显示
菲数科技以“FPGA+云”助力高性能计算
防爆气象站技术参数常用哪些?
诺基亚6除外还有诺基亚8 诺基亚8除外还有诺基亚N!
最新MSP430 MCU Value Line Launch
5G手机出货量阶梯式上升,产业链业绩有望大增
全省首个!国显科技倾情助力“城市智慧大脑指控中心”
瑞幸咖啡将无人配送的工具由无人驾驶车辆升级为无人机
VPS和VPN这两个到底有什么区别
电位器的种类、作用及其引脚的接法
谷歌BERT模型的主体结构和创新点介绍 双向语言模型的引入
关于声学特性指标的说明
200V单芯片驱动器LME49810的技术特点及适用范围
多氟多: 积极发展新材料,有序发展锂电池,稳健发展新能源汽车
续航613KM、百公里加速2.7秒 特斯拉正式发布Model S P100D