||







| Arduino 开发环境 Arduino的开发环境是Arduino IDE,在网络上就可以下载到。 陆 Arduino 官方网站软件下载 https://www.arduino.cc/en/Main/Software?setlang=cn 安装完Arduino IDE以后,打开软件将会是以下界面: ![]() Arduino IDE默认为我们创建了两个函数:setup函数和loop函数。 关于Arduino的介绍网络上也有很多,大家如果有不明白的可以直接到网络上去查找。 Arduino LCD显示项目实施过程 硬件连接 要确保后面编写代码的工作能顺利进行,我们必须要先确定硬件连接的可靠性。 本项目中只用到了四个硬件: 1、 Arduino Mini pro开发板 2、 STONE STVI070WT-01 TFT-LCD显示屏 3、 MAX30100心率和血氧传感器 4、 MAX3232(RS232-->TTL) Arduino Mini Pro开发板和STVI070WT-01 TFT-LCD显示屏通过UART连接,这中间需要通过MAX3232进行电平转换,然后Arduino Mini pro开发板与MAX30100模块通过IIC接口连接。 思路理清以后,可以绘制出下面的接线图片: ![]() ![]() 确定硬件连接没有错误,然后进入下一步的工作。 LCD-TFT显示屏用户界面设计 首先我们需要设计一张UI显示图片,可以使用PhotoShop软件设计,也可以使用其他图片设计工具设计,设计UI显示图片片以后,把图片保存未JPG格式。 打开STONE TOOL2019软件,新建一个项目: ![]() ![]() 删除掉新建项目默认加载的图片,然后添加我们设计好的UI图片。 添加文本显示组件,设计显示的位数和小数点,获取文本显示组件在显示屏中的存储位置。 效果如下: ![]() 文本显示组件的地址: l Connection sta : 0x0008 l Heart rate : 0x0001 l Blood oxygen : 0x0005 UI界面主要内容如下: l 心率显示 l 血氧显示 l 心脏跳动效果 生成配置文件 上面的UI界面设计完成以后,就可以生成配置文件,然后把配置文件下载到STVI070WT显示屏中,这一部分的操作在STONE的开发资料中有介绍。 ![]() 先执行步骤1,然后再电脑中插入U盘,此时会显示盘符,然后点击“Download to u-disk”把配置文件下载到U盘中,再把U盘插入STVI070WT-01,就可以完成升级。 MAX30100 MAX30100的通信方式是通过IIC进行通信。其工作原理是通过红外led灯照射,能够得到心率的ADC值。 MAX30100的寄存器可以分为五类,状态寄存器、FIFO、控制寄存器、温度寄存器、ID寄存器。温度寄存器是读取芯片的温度值,以矫正因为温度而产生的偏差。ID寄存器可以读取芯片的ID号。 ![]() MAX30100通过IIC通讯接口和Arduino Mini Pro开发板连接,由于Arduino IDE里面有现成的MAX30100库文件,所以我们可以不用研究MAX30100的寄存器,只需要调用Arduino里面的接口就可以实现心率和血氧数据读取。 有兴趣研究MAX30100的寄存器的朋友可以查看MAX30100的Datasheet。 修改MAX30100 IIC上拉电阻 需要注意的是,MAX30100模块的IIC引脚的4.7K上拉电阻是接到1.8V的,这个理论上是没什么问题的,但是Arduino的IIC引脚通讯逻辑电平是5V的,所以在不改动MAX30100模块硬件的情况下,它是无法跟Arduino通讯的。如果MCU使用的是STM32或者其他3.3V逻辑电平的MCU,就可以直接通讯。 所以,需要做以下改动: ![]() 把图片中标出来的三个4.7K的电阻用电烙铁取下来。然后在SDA、SCL引脚处再焊接两个4.7K的电阻接到VIN引脚,这样就可以和Arduino通讯了。 如果项目中需要用到INT引脚,那么还需要把INT引脚也焊接一个4.7K的电阻连接到VIN引脚。 INT引脚是中断功能, 当检测到心跳时,这个引脚会中断一次,可以用来做心跳检测。 Arduino 打开Arduino IDE,找到以下按钮: ![]() 搜索“MAX30100”,找到两个MAX30100的库文件,然后点击下载安装。 ![]() 安装完成以后就可以在Arduino的LIB库文件夹里面找到MAX30100的Demo: ![]() 鼠标双击这个文件就可以打开了。 ![]() 这个Demo就可以直接测试了,在确保硬件连接没问题的情况下,把这个代码编译下载到Arduibo开发板中,就可以在串口调试工具中看到MAX30100的数据了。 完整的代码如下: /* Arduino-MAX30100 oximetry / heart rate integrated sensor library Copyright (C) 2016 OXullo Intersecans <x@brainrapers.org> 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 along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <Wire.h> #include "MAX30100_PulseOximeter.h" #define REPORTING_PERIOD_MS 1000 // 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"); for(;;); } else { 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("%"); tsLastReport = millis(); } } 这套代码非常简单,相信大家一看就能明白,不得不说Arduino的模块化编程是非常方便的,我甚至都不用去了解Uart和IIC的驱动代码是如何实现的。 当然了,上面的代码是官方的Demo,要把数据显示到STONE显示屏,我还需要做一些修改。 通过Arduino把数据显示到STONE显示屏 首先我们需要获取到STONE显示屏中显示心率和血氧数据的组件地址: 在我的项目中,地址如下: 心率显示组件地址:0x0001 血氧显示组件地址:0x0005 传感器连接状态地址:0x0008 如果需要改变对应的空间的显示内容,只需要通过Arduino的串口向显示屏相应的地址发送数据就可以改变显示的内容了。 修改以后的代码如下: /* Arduino-MAX30100 oximetry / heart rate integrated sensor library Copyright (C) 2016 OXullo Intersecans <x@brainrapers.org> 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 along with this program. If not, see <http://www.gnu.org/licenses/>. */ #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的采集器上,就可以实时看到自己的心率和血氧数据了。 运行效果可以参考下面的图片: ![]() ![]() |
手机版|
GMT+8, 2025-11-10 22:15 , Processed in 0.053853 second(s), 6 queries , Gzip On, Redis On. Powered by Discuz! X3.5
YiBoard一板网 © 2015-2022 地址:河北省石家庄市长安区高营大街 ( 冀ICP备18020117号 )