差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 | ||
pulse_oximeter_sensor [2023/07/27 10:53] wangzihao [5. 参考案例] |
pulse_oximeter_sensor [2023/08/08 16:06] (当前版本) zili [5. 参考案例] |
||
---|---|---|---|
行 68: | 行 68: | ||
### 5. 参考案例 | ### 5. 参考案例 | ||
- | 在Thonny使用Mircopython编写程序控制RP2040控制Max30102读取心率数据 | + | **在Thonny使用Mircopython编写程序控制RP2040控制Max30102读取心率数据** |
####Max30102芯片介绍 | ####Max30102芯片介绍 | ||
行 94: | 行 94: | ||
- HR_SpO2.py | - HR_SpO2.py | ||
- | 前面两个文件可在github上面下载 | + | 前面两个文件可在github上面下载https://github.com/n-elia/MAX30102-MicroPython-driver/tree/main/max30102 |
spo2cal.py程序如下 | spo2cal.py程序如下 | ||
+ | |||
+ | <code verilog> | ||
# -*-coding:utf-8 | # -*-coding:utf-8 | ||
行 306: | 行 308: | ||
print("SPO2 : ", sp2) | print("SPO2 : ", sp2) | ||
+ | </code> | ||
+ | | ||
HR_SpO2.py程序如下: | HR_SpO2.py程序如下: | ||
- | from machine import SoftI2C, Pin, Timer | + | <code verilog> |
+ | |||
+ | from machine import SoftI2C, Pin, Timer | ||
from utime import ticks_diff, ticks_us | from utime import ticks_diff, ticks_us | ||
from max30102 import MAX30102, MAX30105_PULSE_AMP_MEDIUM | from max30102 import MAX30102, MAX30105_PULSE_AMP_MEDIUM | ||
- | # ------------ 添加新代码 ----------- | ||
from spo2cal import calc_hr_and_spo2 | from spo2cal import calc_hr_and_spo2 | ||
行 317: | 行 322: | ||
BEATS = 0 # 存储心率 | BEATS = 0 # 存储心率 | ||
FINGER_FLAG = False # 默认表示未检测到手指 | FINGER_FLAG = False # 默认表示未检测到手指 | ||
- | # ------------ 添加新代码 ----------- | + | |
SPO2 = 0 # 存储血氧 | SPO2 = 0 # 存储血氧 | ||
TEMPERATURE = 0 # 存储温度 | TEMPERATURE = 0 # 存储温度 | ||
行 326: | 行 331: | ||
if FINGER_FLAG is False: | if FINGER_FLAG is False: | ||
return | return | ||
- | + | | |
- | # ------------ 修改代码 ----------- | + | |
print('Heart Rate: ', BEATS, " SpO2:", SPO2, " Temperture:", TEMPERATURE) | print('Heart Rate: ', BEATS, " SpO2:", SPO2, " Temperture:", TEMPERATURE) | ||
def main(): | def main(): | ||
- | # ------------ 修改代码 ----------- | ||
global BEATS, FINGER_FLAG, SPO2, TEMPERATURE # 如果需要对全局变量修改,则需要global声明 | global BEATS, FINGER_FLAG, SPO2, TEMPERATURE # 如果需要对全局变量修改,则需要global声明 | ||
| | ||
行 364: | 行 367: | ||
beats_history = [] | beats_history = [] | ||
beat = False | beat = False | ||
- | # ------------ 添加新代码 ----------- | + | |
red_list = [] | red_list = [] | ||
ir_list = [] | ir_list = [] | ||
行 407: | 行 410: | ||
beat = False | beat = False | ||
| | ||
- | # ------------ 添加新代码 ----------- | ||
# 计算血氧 | # 计算血氧 | ||
red_list.append(red_reading) | red_list.append(red_reading) | ||
行 421: | 行 423: | ||
SPO2 = int(sp) | SPO2 = int(sp) | ||
- | # ------------ 添加新代码 ----------- | ||
# 计算温度 | # 计算温度 | ||
TEMPERATURE = sensor.read_temperature() | TEMPERATURE = sensor.read_temperature() | ||
行 432: | 行 433: | ||
main() | main() | ||
- | + | </code> | |
- | + | ||
- | + | ||
- | + | ||