功能实现:通过mx30102采集手指血氧浓度,显示在0.96OLED屏上。
完整工程关注微信公众号:dlrcclub,回复关键字"mx30102"
演示视频:B站视频
硬件:stm32f103最小系统。
mx30102血氧采集模块,0.96OLED屏。
一、引言
血氧饱和度(SpO2)是衡量血液中携氧能力的重要指标,对于病人的生命体征监测具有重要意义。目前,市场上的血氧仪大多数采用红外和光电二极管技术进行血氧测量。然而,这些设备通常价格较高,不适合家庭使用。因此,本文提出了一种基于STM32F103微控制器、MX30102血氧传感器和OLED显示屏的血氧采样显示系统,旨在降低血氧仪的成本,使其更适合家庭使用。
二、系统设计
- STM32F103微控制器
STM32F103是一款基于ARM Cortex-M3内核的32位微控制器,具有高性能、低功耗、丰富的外设接口等特点。在本系统中,STM32F103作为主控芯片,负责控制MX30102血氧传感器进行血氧采样,并将采样数据发送到OLED显示屏进行显示。
- MX30102血氧传感器
MX30102是一款基于红外和光电二极管技术的血氧传感器,具有高精度、低功耗、小尺寸等特点。在本系统中,MX30102负责采集血氧饱和度数据,并通过I2C接口将数据发送到STM32F103微控制器。
- OLED显示屏
OLED显示屏具有自发光、低功耗、高对比度、宽视角等特点,非常适合用于便携式设备的显示。在本系统中,OLED显示屏用于显示血氧饱和度数据。为了简化设计,我们选择了一个带有SSD1306驱动模块的OLED显示屏。
主程序:
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "max30102.h"
#include "myiic.h"
#include "algorithm.h"
#include "oled.h"
uint32_t aun_ir_buffer[500]; //IR LED sensor data
int32_t n_ir_buffer_length; //data length
uint32_t aun_red_buffer[500]; //Red LED sensor data
int32_t n_sp02; //SPO2 value
int8_t ch_spo2_valid; //indicator to show if the SP02 calculation is valid
int32_t n_heart_rate; //heart rate value
int8_t ch_hr_valid; //indicator to show if the heart rate calculation is valid
uint8_t uch_dummy;
#define MAX_BRIGHTNESS 255
void dis_DrawCurve(u32* data,u8 x);
int main(void)
{
//variables to calculate the on-board LED brightness that reflects the heartbeats
uint32_t un_min, un_max, un_prev_data;
int i;
int32_t n_brightness;
float f_temp;
u8 temp_num=0;
u8 temp[6];
u8 str[100];
u8 dis_hr=0,dis_spo2=0;
NVIC_Configuration();
delay_init(); //延时函数初始化
uart_init(115200); //串口初始化为115200
LED_Init();
//OLED
OLED_Init();
OLED_ShowString(0,0," initializing ",16);
OLED_Refresh_Gram();//更新显示到OLED
max30102_init();
printf("\r\n MAX30102 init \r\n");
un_min=0x3FFFF;
un_max=0;
n_ir_buffer_length=500; //buffer length of 100 stores 5 seconds of samples running at 100sps
//read the first 500 samples, and determine the signal range
for(i=0;i<n_ir_buffer_length;i++)
{
while(MAX30102_INT==1); //wait until the interrupt pin asserts
max30102_FIFO_ReadBytes(REG_FIFO_DATA,temp);
aun_red_buffer[i] = (long)((long)((long)temp[0]&0x03)<<16) | (long)temp[1]<<8 | (long)temp[2]; // Combine values to get the actual number
aun_ir_buffer[i] = (long)((long)((long)temp[3] & 0x03)<<16) |(long)temp[4]<<8 | (long)temp[5]; // Combine values to get the actual number
if(un_min>aun_red_buffer[i])
un_min=aun_red_buffer[i]; //update signal min
if(un_max<aun_red_buffer[i])
un_max=aun_red_buffer[i]; //update signal max
}
un_prev_data=aun_red_buffer[i];
//calculate heart rate and SpO2 after first 500 samples (first 5 seconds of samples)
maxim_heart_rate_and_oxygen_saturation(aun_ir_buffer, n_ir_buffer_length, aun_red_buffer, &n_sp02, &ch_spo2_valid, &n_heart_rate, &ch_hr_valid);