当前位置:   article > 正文

#旭日X3派首百尝鲜# 【AI健身实体机】Arduino使用MAX30102人体心率血氧检测模块在X3派上位机上的显示_max30105 was not found. please check wiring/power.

max30105 was not found. please check wiring/power.

一、Arduino与旭日X3派通信

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

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

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

4.在Arduino上烧录代码

  1. void setup()
  2. {
  3. Serial.begin(9600);
  4. }
  5. void loop()
  6. {
  7. if ( Serial.available())
  8. {
  9. if('s' == Serial.read())
  10. Serial.println("HelloWorld!");
  11. }
  12. }

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

在终端下通过python3进行测试

最后print可以出现HelloWorld!

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

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

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

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

1.MAX30102

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

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

2.Arduino代码

  1. #include <Wire.h>
  2. #include "MAX30105.h"
  3. #include "spo2_algorithm.h"
  4. MAX30105 particleSensor;
  5. #define MAX_BRIGHTNESS 255
  6. #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
  7. //Arduino Uno doesn't have enough SRAM to store 100 samples of IR led data and red led data in 32-bit format
  8. //To solve this problem, 16-bit MSB of the sampled data will be truncated. Samples become 16-bit data.
  9. uint16_t irBuffer[100]; //infrared LED sensor data
  10. uint16_t redBuffer[100]; //red LED sensor data
  11. #else
  12. uint32_t irBuffer[100]; //infrared LED sensor data
  13. uint32_t redBuffer[100]; //red LED sensor data
  14. #endif
  15. int32_t bufferLength; //data length
  16. int32_t spo2; //SPO2 value
  17. int8_t validSPO2; //indicator to show if the SPO2 calculation is valid
  18. int32_t heartRate; //heart rate value
  19. int8_t validHeartRate; //indicator to show if the heart rate calculation is valid
  20. byte pulseLED = 11; //Must be on PWM pin
  21. byte readLED = 13; //Blinks with each data read
  22. void setup()
  23. {
  24. Serial.begin(115200); // initialize serial communication at 115200 bits per second:
  25. pinMode(pulseLED, OUTPUT);
  26. pinMode(readLED, OUTPUT);
  27. // Initialize sensor
  28. if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
  29. {
  30. Serial.println(F("MAX30105 was not found. Please check wiring/power."));
  31. while (1);
  32. }
  33. //Serial.println(F("Attach sensor to finger with rubber band. Press any key to start conversion"));
  34. //while (Serial.available() == 0) ; //wait until user presses a key
  35. //Serial.read();
  36. byte ledBrightness = 60; //Options: 0=Off to 255=50mA
  37. byte sampleAverage = 4; //Options: 1, 2, 4, 8, 16, 32
  38. byte ledMode = 2; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
  39. byte sampleRate = 100; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
  40. int pulseWidth = 411; //Options: 69, 118, 215, 411
  41. int adcRange = 4096; //Options: 2048, 4096, 8192, 16384
  42. particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings
  43. }
  44. void loop()
  45. {
  46. bufferLength = 100; //buffer length of 100 stores 4 seconds of samples running at 25sps
  47. //read the first 100 samples, and determine the signal range
  48. for (byte i = 0 ; i < bufferLength ; i++)
  49. {
  50. while (particleSensor.available() == false) //do we have new data?
  51. particleSensor.check(); //Check the sensor for new data
  52. redBuffer[i] = particleSensor.getRed();
  53. irBuffer[i] = particleSensor.getIR();
  54. particleSensor.nextSample(); //We're finished with this sample so move to next sample
  55. Serial.print(F("red="));
  56. Serial.print(redBuffer[i], DEC);
  57. Serial.print(F(", ir="));
  58. Serial.println(irBuffer[i], DEC);
  59. }
  60. //calculate heart rate and SpO2 after first 100 samples (first 4 seconds of samples)
  61. maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
  62. //Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second
  63. while (1)
  64. {
  65. //dumping the first 25 sets of samples in the memory and shift the last 75 sets of samples to the top
  66. for (byte i = 25; i < 100; i++)
  67. {
  68. redBuffer[i - 25] = redBuffer[i];
  69. irBuffer[i - 25] = irBuffer[i];
  70. }
  71. //take 25 sets of samples before calculating the heart rate.
  72. for (byte i = 75; i < 100; i++)
  73. {
  74. while (particleSensor.available() == false) //do we have new data?
  75. particleSensor.check(); //Check the sensor for new data
  76. digitalWrite(readLED, !digitalRead(readLED)); //Blink onboard LED with every data read
  77. redBuffer[i] = particleSensor.getRed();
  78. irBuffer[i] = particleSensor.getIR();
  79. particleSensor.nextSample(); //We're finished with this sample so move to next sample
  80. //send samples and calculation result to terminal program through UART
  81. //Serial.print(F("red="));
  82. //Serial.print(redBuffer[i], DEC);
  83. //Serial.print(F(", ir="));
  84. //Serial.print(irBuffer[i], DEC);
  85. Serial.print(F(", HR="));
  86. Serial.print(heartRate, DEC);
  87. //Serial.print(F(", HRvalid="));
  88. //Serial.print(validHeartRate, DEC);
  89. Serial.print(F(", SPO2="));
  90. Serial.println(spo2, DEC);
  91. //Serial.print(F(", SPO2Valid="));
  92. //Serial.println(validSPO2, DEC);
  93. }
  94. //After gathering 25 new samples recalculate HR and SP02
  95. maxim_heart_rate_and_oxygen_saturation(irBuffer, bufferLength, redBuffer, &spo2, &validSPO2, &heartRate, &validHeartRate);
  96. }
  97. }

3.接线

VCC----5V

GND---GND

SCL----A5

SDA---A4

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

4.X3派代码

sudo nano max30102_test.py

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

5.运行代码

python3 max30102_test.py

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

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

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

原作者:jmulin

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/401537
推荐阅读
相关标签
  

闽ICP备14008679号