感谢EEPW推出的“ST NUCLEO-WBA55CG无线MCU开发大作战”活动,之前分享的过程贴链接:
【STM32WBA55CG开发板】便携式健康仪-TFT屏幕驱动【过程贴】 https://forum.eepw.com.cn/thread/388989/1
【STM32WBA55CG开发板】便携式健康仪-DHT11温湿度传感器驱动【过程贴】 https://forum.eepw.com.cn/thread/389137/1
【STM32WBA55CG开发板】便携式健康仪-MAX30102心跳血氧传感器驱动【过程贴】 https://forum.eepw.com.cn/thread/389138/1
本次完成的小制作是利用WBA55CG的强大性能和丰富外设接口,分别驱动了SPI接口的屏幕,I2C接口的传感器与单总线接口的温湿度传感器。成功实现了心率、心跳、环境温湿度数据的采集。并且利用板卡的BLE特性,上报了心率与心跳数据到上位机的BLE客户端。实现了数据的无线传输。
项目的软件流程图如下:
项目的主程序如下:
int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* Config code for STM32_WPAN (HSE Tuning must be done before system clock configuration) */ MX_APPE_Config(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* Configure the peripherals common clocks */ PeriphCommonClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_GPDMA1_Init(); MX_RAMCFG_Init(); MX_RTC_Init(); MX_RNG_Init(); MX_ICACHE_Init(); MX_SPI1_Init(); MX_I2C1_Init(); /* USER CODE BEGIN 2 */ LOG_INFO_APP("\r\n Version 0.3"); u8 i,j; float t=0; LCD_Init();//LCD LCD_Fill(0,0,LCD_W,LCD_H,WHITE); LCD_ShowString(0,0,"MAX30102 Pulse Oximiter Data",RED,WHITE,16,0); LCD_ShowString(180,10,"ver:0.3",RED,WHITE,16,0); LCD_ShowString(0,40,"LCD_W:",RED,WHITE,16,0); LCD_ShowIntNum(48,40,LCD_W,3,RED,WHITE,16); LCD_ShowString(80,40,"LCD_H:",RED,WHITE,16,0); LCD_ShowIntNum(128,40,LCD_H,3,RED,WHITE,16); LCD_ShowString(80,40,"LCD_H:",RED,WHITE,16,0); LCD_ShowString(0,70,"Increaseing Nun:",RED,WHITE,16,0); #ifdef USE_FULL_ASSERT LCD_ShowString(0,90,"USE FULL ASSERT DEFINED",RED,WHITE,16,0); #else LCD_ShowString(0,90,"USE FULL ASSERT NOT DEFINED",RED,WHITE,16,0); #endif LCD_ShowFloatNum1(128,70,t,4,RED,WHITE,16); t+=0.11; LCD_ShowPicture(40*0,120+0*40,40,40,gImage_1); LCD_ShowString(80,120,"Temperature: °C",RED,WHITE,16,0); LCD_ShowString(80,140,"Humidity: %RH",RED,WHITE,16,0); LCD_ShowString(0,190,"Heart Rate (BPM): ",RED,WHITE,16,0); LCD_ShowString(0,210,"Oxygen Saturation SpO2(%):",RED,WHITE,16,0); HAL_Delay(1000); long currentMillis = 0; long lastMillis = 0; /* USER CODE END 2 */ /* Init code for STM32_WPAN */ MX_APPE_Init(NULL); /* Infinite loop */ /* USER CODE BEGIN WHILE */ Max30102_reset(); MAX30102_Config(); currentMillis = millis(); DHT11_Init(); while (1) { MX_APPE_Process(); //blood_Loop(); /* USER CODE BEGIN 3 */ LCD_ShowFloatNum1(128,70,t,4,RED,WHITE,16); t+=0.11; currentMillis = millis(); if( currentMillis - lastMillis > 5000 ){ DHT11_Read_Data(&temperature, &humidity); //读取温湿度值 printf("温度:%d℃ 湿度:%d%%RH\r\n", temperature, humidity); LCD_ShowIntNum(180,120,temperature,2,RED,WHITE,16); LCD_ShowIntNum(180,140,humidity,2,RED,WHITE,16); lastMillis = currentMillis; } } while (1) { blood_Loop(); currentMillis = millis(); if( currentMillis - lastMillis > 1000 ) { LCD_ShowFloatNum1(200,170,0,4,RED,WHITE,16); LCD_ShowFloatNum1(200,190,heart,4,RED,WHITE,16); LCD_ShowFloatNum1(200,210,SpO2,4,RED,WHITE,16); printf("心率%3d/min 血氧%2d%%\n\r", heart, (int)SpO2); lastMillis = currentMillis; } /* USER CODE END WHILE */ MX_APPE_Process(); /* USER CODE BEGIN 3 */ LCD_ShowFloatNum1(128,70,t,4,RED,WHITE,16); t+=0.11; } /* USER CODE END 3 */ }
实物效果:温湿度数据与小米的米家温湿度数据做比对,比较接近。
心率76,血氧 99与medisana (73 BPM, 98% SpO2)做比较。
上位机采用ST的官方app ST BLE Toolbox:
项目演示视频和完整代码见附件: