本帖最后由 Ableson 于 2020-4-15 17:31 编辑
通过Arduino把数据显示到STONE显示屏
首先我们需要获取到STONE显示屏中显示心率和血氧数据的组件地址: 在我的项目中,地址如下: 心率显示组件地址:0x0001 血氧显示组件地址:0x0005 传感器连接状态地址:0x0008 如果需要改变对应的空间的显示内容,只需要通过Arduino的串口向显示屏相应的地址发送数据就可以改变显示的内容了。 修改以后的代码如下:
/* Arduino-MAX30100 oximetry / heart rate integrated sensor library
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License */
#include <Wire.h> #include "MAX30100_PulseOximeter.h"
#define REPORTING_PERIOD_MS 1000 #define Heart_dis_addr 0x01 #define Sop2_dis_addr 0x05 #define connect_sta_addr 0x08
unsigned char heart_rate_send[8]= {0xA5, 0x5A, 0x05, 0x82,\ 0x00, Heart_dis_addr, 0x00, 0x00}; unsigned char Sop2_send[8]= {0xA5, 0x5A, 0x05, 0x82, 0x00, \ Sop2_dis_addr, 0x00, 0x00}; unsigned char connect_sta_send[8]={0xA5, 0x5A, 0x05, 0x82, 0x00, \ connect_sta_addr,0x00, 0x00};
// PulseOximeter is the higher level interface to the sensor // it offers: // * beat detection reporting // * heart rate calculation // * SpO2 (oxidation level) calculation PulseOximeter pox;
uint32_t tsLastReport = 0;
// Callback (registered below) fired when a pulse is detected void onBeatDetected() { // Serial.println("Beat!"); }
void setup() { Serial.begin(115200);
// Serial.print("Initializing pulse oximeter..");
// Initialize the PulseOximeter instance // Failures are generally due to an improper I2C wiring, missing power supply // or wrong target chip if (!pox.begin()) { // Serial.println("FAILED"); // connect_sta_send[7]=0x00; // Serial.write(connect_sta_send,8); for(;;); } else { connect_sta_send[7]=0x01; Serial.write(connect_sta_send,8); // Serial.println("SUCCESS"); }
// The default current for the IR LED is 50mA and it could be changed // by uncommenting the following line. Check MAX30100_Registers.h for all the // available options. pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// Register a callback for the beat detection pox.setOnBeatDetectedCallback(onBeatDetected); }
void loop() { // Make sure to call update as fast as possible pox.update();
// Asynchronously dump heart rate and oxidation levels to the serial // For both, a value of 0 means "invalid" if (millis() - tsLastReport > REPORTING_PERIOD_MS) { // Serial.print("Heart rate:"); // Serial.print(pox.getHeartRate()); // Serial.print("bpm / SpO2:"); // Serial.print(pox.getSpO2()); // Serial.println("%"); heart_rate_send[7]=(uint32_t)pox.getHeartRate(); Serial.write(heart_rate_send,8); Sop2_send[7]=pox.getSpO2(); Serial.write(Sop2_send,8); tsLastReport = millis(); } }
编译这些代码,然后下载到Arduino开发板中,就可以开始测试了。 我们可以发现,当手指离开MAX30100时,心率和血氧显示的是0。把手指放到MAX30100的采集器上,就可以实时看到自己的心率和血氧数据了。 运行效果可以参考下面的图片:
|