標(biāo)題:
MAX30102芯片+心率血氧傳感器模塊+傳感器模塊 Arduino源程序
[打印本頁(yè)]
作者:
1183953327
時(shí)間:
2019-5-21 22:06
標(biāo)題:
MAX30102芯片+心率血氧傳感器模塊+傳感器模塊 Arduino源程序
本程序使用STM32F103C8T6最小系統(tǒng)開發(fā)板驗(yàn)證。
MAX30102模塊接口:PB9-SDA,PB8-SCL,PB7-INT
PA2/PA3為串口傳輸口TX和RX,波特率設(shè)置為115200
PC13為顯示LED
軟件版本:
MDK FOR ARM 5.24
單片機(jī)源程序如下:
#include "stm32f103c8t6.h"
#include "mbed.h"
#include "algorithm.h"
#include "MAX30102.h"
#define MAX_BRIGHTNESS 255
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;
Serial pc(SERIAL_TX, SERIAL_RX); //initializes the serial port, TX-PA2, RX-PA3
PwmOut pwmled(PB_3); //initializes the pwm output PB3 that connects to the LED
DigitalIn INT(PB_7); //pin PB7 connects to the interrupt output pin of the MAX30102
DigitalOut led(PC_13); //PC13 connects to the on board user LED
// the setup routine runs once when you press reset:
int main() {
uint32_t un_min, un_max, un_prev_data; //variables to calculate the on-board LED brightness that reflects the heartbeats
int i;
int32_t n_brightness;
float f_temp;
maxim_max30102_reset(); //resets the MAX30102
// initialize serial communication at 115200 bits per second:
pc.baud(115200);
pc.format(8,SerialBase::None,1);
wait(1);
//read and clear status register
maxim_max30102_read_reg(0,&uch_dummy);
//wait until the user presses a key
// while(pc.readable()==0)
// {
// pc.printf("\x1B[2J"); //clear terminal program screen
// pc.printf("Press any key to start conversion\n\r");
// wait(1);
// }
// uch_dummy=getchar();
maxim_max30102_init(); //initializes the MAX30102
n_brightness=0;
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(INT.read()==1); //wait until the interrupt pin asserts
maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i)); //read from MAX30102 FIFO
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
pc.printf("red=");
pc.printf("%i", aun_red_buffer[i]);
pc.printf(", ir=");
pc.printf("%i\n\r", aun_ir_buffer[i]);
}
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);
//Continuously taking samples from MAX30102. Heart rate and SpO2 are calculated every 1 second
while(1)
{
i=0;
un_min=0x3FFFF;
un_max=0;
//dumping the first 100 sets of samples in the memory and shift the last 400 sets of samples to the top
for(i=100;i<500;i++)
{
aun_red_buffer[i-100]=aun_red_buffer[i];
aun_ir_buffer[i-100]=aun_ir_buffer[i];
//update the signal min and max
if(un_min>aun_red_buffer[i])
un_min=aun_red_buffer[i];
if(un_max<aun_red_buffer[i])
un_max=aun_red_buffer[i];
}
//take 100 sets of samples before calculating the heart rate.
for(i=400;i<500;i++)
{
un_prev_data=aun_red_buffer[i-1];
while(INT.read()==1);
maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));
if(aun_red_buffer[i]>un_prev_data)//just to determine the brightness of LED according to the deviation of adjacent two AD data
{
f_temp=aun_red_buffer[i]-un_prev_data;
f_temp/=(un_max-un_min);
f_temp*=MAX_BRIGHTNESS;
n_brightness-=(int)f_temp;
if(n_brightness<0)
n_brightness=0;
}
else
{
f_temp=un_prev_data-aun_red_buffer[i];
f_temp/=(un_max-un_min);
f_temp*=MAX_BRIGHTNESS;
n_brightness+=(int)f_temp;
if(n_brightness>MAX_BRIGHTNESS)
n_brightness=MAX_BRIGHTNESS;
}
pwmled.write(1-(float)n_brightness/256);//pwm control led brightness
if(n_brightness<120)
led=1;
else
led=0;
//send samples and calculation result to terminal program through UART
pc.printf("red=");
pc.printf("%i", aun_red_buffer[i]);
pc.printf(", ir=");
pc.printf("%i", aun_ir_buffer[i]);
pc.printf(", HR=%i, ", n_heart_rate);
pc.printf("HRvalid=%i, ", ch_hr_valid);
pc.printf("SpO2=%i, ", n_sp02);
pc.printf("SPO2Valid=%i\n\r", ch_spo2_valid);
}
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);
}
}
復(fù)制代碼
所有資料51hei提供下載:
測(cè)試程序.7z
(1.17 MB, 下載次數(shù): 132)
2019-5-22 00:05 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
作者:
LIHUA李華
時(shí)間:
2019-7-26 19:46
正在調(diào)試,需要這個(gè)
作者:
luy3728000
時(shí)間:
2020-4-15 09:29
謝謝分享
作者:
zxy1004211072
時(shí)間:
2020-4-15 16:19
請(qǐng)問(wèn)有Arduino的源程序嗎
作者:
tom1234516
時(shí)間:
2020-4-15 23:00
正在研究這個(gè)希望有幫助
作者:
hjyg
時(shí)間:
2020-4-28 21:41
感謝分享
作者:
dongfang08
時(shí)間:
2020-5-16 11:17
謝謝分享
作者:
ljl-2003
時(shí)間:
2022-8-13 13:01
max30105的庫(kù)max30102能用嗎
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1