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.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周围用绝缘黑胶布包裹起来,避免手碰到电阻对结果产生影响

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
-
嵌入式
+关注
关注
5187文章
20170浏览量
329149 -
AI
+关注
关注
90文章
38241浏览量
297147 -
人工智能
+关注
关注
1813文章
49773浏览量
261749
发布评论请先 登录
半年参与3万辆宝马X3生产,人形机器人“进厂打工”真成了
华为路由 X3 Pro火了!业界首发Wi-Fi7+和透明天线,1299元起
安谋发布“周易”X3 NPU,破局AI算力,智绘未来蓝图
奇瑞风云X3系列双车上市
如何在树莓派上安装并运行 Arduino 集成开发环境!
【awinic inside】艾为芯 + 全彩刻蚀光波导!雷鸟AI眼镜 X3 Pro震撼上市
韵乐Vinal X3/X5卡拉OK音频处理器调音软件简介
RDK X3 带飞的智能护理系统:让机器人秒变贴心小棉袄
HMC-XTB110 无源x3倍频器,24-30GHz输入技术手册
九号公司Segway Navimow X3割草机器人获TÜV莱茵"高效割草"Quality-mark认证

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