久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 10227|回復: 7
打印 上一主題 下一主題
收起左側

MAX30102芯片+心率血氧傳感器模塊+傳感器模塊 Arduino源程序

  [復制鏈接]
跳轉到指定樓層
樓主
ID:253493 發表于 2019-5-21 22:06 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本程序使用STM32F103C8T6最小系統開發板驗證。
MAX30102模塊接口:PB9-SDA,PB8-SCL,PB7-INT
PA2/PA3為串口傳輸口TX和RX,波特率設置為115200
PC13為顯示LED

軟件版本:
MDK FOR ARM 5.24

單片機源程序如下:
  1. #include "stm32f103c8t6.h"
  2. #include "mbed.h"
  3. #include "algorithm.h"
  4. #include "MAX30102.h"

  5. #define MAX_BRIGHTNESS 255

  6. uint32_t aun_ir_buffer[500]; //IR LED sensor data
  7. int32_t n_ir_buffer_length;    //data length
  8. uint32_t aun_red_buffer[500];    //Red LED sensor data
  9. int32_t n_sp02; //SPO2 value
  10. int8_t ch_spo2_valid;   //indicator to show if the SP02 calculation is valid
  11. int32_t n_heart_rate;   //heart rate value
  12. int8_t  ch_hr_valid;    //indicator to show if the heart rate calculation is valid
  13. uint8_t uch_dummy;

  14. Serial pc(SERIAL_TX, SERIAL_RX);    //initializes the serial port, TX-PA2, RX-PA3

  15. PwmOut pwmled(PB_3);  //initializes the pwm output PB3 that connects to the LED
  16. DigitalIn INT(PB_7);  //pin PB7 connects to the interrupt output pin of the MAX30102
  17. DigitalOut led(PC_13); //PC13 connects to the on board user LED


  18. // the setup routine runs once when you press reset:
  19. int main() {
  20.     uint32_t un_min, un_max, un_prev_data;  //variables to calculate the on-board LED brightness that reflects the heartbeats
  21.     int i;
  22.     int32_t n_brightness;
  23.     float f_temp;
  24.    
  25.     maxim_max30102_reset(); //resets the MAX30102
  26.     // initialize serial communication at 115200 bits per second:
  27.     pc.baud(115200);
  28.     pc.format(8,SerialBase::None,1);
  29.     wait(1);
  30.    
  31.     //read and clear status register
  32.     maxim_max30102_read_reg(0,&uch_dummy);
  33.    
  34.     //wait until the user presses a key
  35. //    while(pc.readable()==0)
  36. //    {
  37. //        pc.printf("\x1B[2J");  //clear terminal program screen
  38. //        pc.printf("Press any key to start conversion\n\r");
  39. //        wait(1);
  40. //    }
  41. //    uch_dummy=getchar();
  42.    
  43.     maxim_max30102_init();  //initializes the MAX30102
  44.         
  45.         
  46.     n_brightness=0;
  47.     un_min=0x3FFFF;
  48.     un_max=0;
  49.   
  50.     n_ir_buffer_length=500; //buffer length of 100 stores 5 seconds of samples running at 100sps
  51.    
  52.     //read the first 500 samples, and determine the signal range
  53.     for(i=0;i<n_ir_buffer_length;i++)
  54.     {
  55.         while(INT.read()==1);   //wait until the interrupt pin asserts
  56.         
  57.         maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));  //read from MAX30102 FIFO
  58.             
  59.         if(un_min>aun_red_buffer[i])
  60.             un_min=aun_red_buffer[i];    //update signal min
  61.         if(un_max<aun_red_buffer[i])
  62.             un_max=aun_red_buffer[i];    //update signal max
  63.         pc.printf("red=");
  64.         pc.printf("%i", aun_red_buffer[i]);
  65.         pc.printf(", ir=");
  66.         pc.printf("%i\n\r", aun_ir_buffer[i]);
  67.     }
  68.     un_prev_data=aun_red_buffer[i];
  69.    
  70.    
  71.     //calculate heart rate and SpO2 after first 500 samples (first 5 seconds of samples)
  72.     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);
  73.    
  74.     //Continuously taking samples from MAX30102.  Heart rate and SpO2 are calculated every 1 second
  75.     while(1)
  76.     {
  77.         i=0;
  78.         un_min=0x3FFFF;
  79.         un_max=0;
  80.         
  81.         //dumping the first 100 sets of samples in the memory and shift the last 400 sets of samples to the top
  82.         for(i=100;i<500;i++)
  83.         {
  84.             aun_red_buffer[i-100]=aun_red_buffer[i];
  85.             aun_ir_buffer[i-100]=aun_ir_buffer[i];
  86.             
  87.             //update the signal min and max
  88.             if(un_min>aun_red_buffer[i])
  89.             un_min=aun_red_buffer[i];
  90.             if(un_max<aun_red_buffer[i])
  91.             un_max=aun_red_buffer[i];
  92.         }
  93.         
  94.         //take 100 sets of samples before calculating the heart rate.
  95.         for(i=400;i<500;i++)
  96.         {
  97.             un_prev_data=aun_red_buffer[i-1];
  98.             while(INT.read()==1);
  99.             maxim_max30102_read_fifo((aun_red_buffer+i), (aun_ir_buffer+i));
  100.         
  101.             if(aun_red_buffer[i]>un_prev_data)//just to determine the brightness of LED according to the deviation of adjacent two AD data
  102.             {
  103.                 f_temp=aun_red_buffer[i]-un_prev_data;
  104.                 f_temp/=(un_max-un_min);
  105.                 f_temp*=MAX_BRIGHTNESS;
  106.                 n_brightness-=(int)f_temp;
  107.                 if(n_brightness<0)
  108.                     n_brightness=0;
  109.             }
  110.             else
  111.             {
  112.                 f_temp=un_prev_data-aun_red_buffer[i];
  113.                 f_temp/=(un_max-un_min);
  114.                 f_temp*=MAX_BRIGHTNESS;
  115.                 n_brightness+=(int)f_temp;
  116.                 if(n_brightness>MAX_BRIGHTNESS)
  117.                     n_brightness=MAX_BRIGHTNESS;
  118.             }

  119.             pwmled.write(1-(float)n_brightness/256);//pwm control led brightness
  120.                                                 if(n_brightness<120)
  121.                                                         led=1;
  122.                                                 else
  123.                                                         led=0;

  124.             //send samples and calculation result to terminal program through UART
  125.             pc.printf("red=");
  126.             pc.printf("%i", aun_red_buffer[i]);
  127.             pc.printf(", ir=");
  128.             pc.printf("%i", aun_ir_buffer[i]);
  129.             pc.printf(", HR=%i, ", n_heart_rate);
  130.             pc.printf("HRvalid=%i, ", ch_hr_valid);
  131.             pc.printf("SpO2=%i, ", n_sp02);
  132.             pc.printf("SPO2Valid=%i\n\r", ch_spo2_valid);
  133.         }
  134.         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);
  135.     }
  136. }
復制代碼

所有資料51hei提供下載:
測試程序.7z (1.17 MB, 下載次數: 132)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏4 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:121029 發表于 2019-7-26 19:46 | 只看該作者
正在調試,需要這個
回復

使用道具 舉報

板凳
ID:344943 發表于 2020-4-15 09:29 | 只看該作者
謝謝分享
回復

使用道具 舉報

地板
ID:720776 發表于 2020-4-15 16:19 | 只看該作者
請問有Arduino的源程序嗎
回復

使用道具 舉報

5#
ID:686387 發表于 2020-4-15 23:00 | 只看該作者
正在研究這個希望有幫助
回復

使用道具 舉報

6#
ID:591719 發表于 2020-4-28 21:41 | 只看該作者
感謝分享
回復

使用道具 舉報

7#
ID:230374 發表于 2020-5-16 11:17 | 只看該作者
謝謝分享
回復

使用道具 舉報

8#
ID:25178 發表于 2022-8-13 13:01 | 只看該作者
max30105的庫max30102能用嗎
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 日韩视频精品在线 | 国户精品久久久久久久久久久不卡 | 一级特黄a大片 | 亚洲国产成人一区二区 | 久久高清精品 | 精品国产黄a∨片高清在线 成人区精品一区二区婷婷 日本一区二区视频 | 在线国产视频 | av入口| 日本a在线| 中文字幕高清av | 国产精品视频不卡 | 美女久久 | 久久国产欧美日韩精品 | 久久国产一区 | 午夜电影一区二区 | 中文字幕视频在线观看 | 日韩视频在线播放 | 亚洲综合色视频在线观看 | 欧美精品一区三区 | 国产欧美一区二区在线观看 | 久久久国产亚洲精品 | 久久久久久亚洲精品 | 午夜在线电影网 | 日韩高清中文字幕 | 国产色片在线 | 成人免费视频网址 | 天天射网站 | 欧美一级二级视频 | 99精品一级欧美片免费播放 | 午夜免费在线观看 | 欧美一区二区三区的 | 99久久精品免费视频 | a爱视频 | 国产乱码久久久久久 | 国产精品日产欧美久久久久 | 精品9999 | 日本精品一区二区三区四区 | 日韩精品一区二区三区中文字幕 | 美女日皮网站 | 精品福利在线 | 不卡在线一区 |