MCU Design: TI Cup Undergraduate Electronic Design Contest Question A – Wireless Motion Sensing Node (ads1292 sensor + lmt70 temperature module + mpu6050 module + OLED + WiFi module + mobile app)
1. Main functions:
1. The ads1292 module detects the heart rate of the elderly, the mpu6050 module counts steps, and the lmt70 detects the body temperature
2. The oled screen and mobile app display the current detected data
3. Pure hand soldering or pcb
Of course other functions can also be added
~ Customized giftable materials:
1. Object
2. Source code and mobile app
3. Schematic
4. After-sales online service (code explanation)
Second, the physical map:
3. Part of the source code:
Main function source code:
int main(void)
{ /* USER CODE BEGIN 1 */ arm_fir_instance_f32 S1; arm_fir_instance_f32 S2; uint32_t p_num=0; // used to refresh the maximum and minimum values uint32_t min[2]={0xFFFFFFFF,0xFFFFFFFF}; uint32_t max[ 2]={0,0}; uint32_t Peak; // peak value uint32_t BPM_LH[3]; // used to judge the peak float BPM; // heart rate flog=0; /* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USART1_UART_Init();
MX_TIM2_Init();
MX_ADC1_Init();
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
OLED_Init(); // oled初始化
OLED_ShowChinese(32,16,0,16,1);//初
OLED_ShowChinese(48,16,1,16,1);//始
OLED_ShowChinese(64,16,2,16,1);//化
OLED_ShowChinese(80,16,3,16,1);//中
OLED_ShowString(0,0,(uint8_t *)" WIFI ",16,1);
OLED_Refresh();//刷新OLED
HAL_UART_Receive_DMA(&huart1, UART_RX_BUF, UART_RX_LEN);
__HAL_UART_ENABLE_IT(&huart1, UART_IT_IDLE);
HAL_Delay(1000);
Wifi_Init(); //wifi initialization function
// HAL_Delay(1000);// sprintf(buf,"buf:%s ",UART_RX_BUF);//Temperature data conversion
OLED_ShowString(0,32,(uint8_t *)"wifiwc",16,1);//Display current statusOLED_Refresh();//Refresh OLED
MPU_Init(); //MPU6050 initialization
mpu_dmp_init(); //dmp initialization
OLED_ShowString(0,32,(uint8_t *)"MPUwc",16,1);//Display current statusOLED_Refresh();//Refresh OLED
ADX922_PowerOnInit();
OLED_ShowString(0,48,(uint8_t *)"ADSwc",16,1);//Display current statusOLED_Refresh();//Refresh OLED
HAL_TIM_Base_Start_IT(&htim2);//Send heartbeat packet
HAL_ADC_Start_DMA(&hadc1,(uint32_t*)&AD_Value,2);
//HAL_ADCEx_Calibration_Start(&hadc1); //AD calibration//HAL_UART_Transmit(&huart2,(uint8_t *)xtb, 2, 200);//Send heartbeat packet
//Initialize structure S1
arm_fir_init_f32(&S1, NumTaps, (float32_t *)LPF_2Hz, firState1, blockSize);
//Initialize structure S2
arm_fir_init_f32(&S2, NumTaps, (float32_t *)BPF_5Hz_40Hz, firState2, blockSize);
CS_L;
Delay_1us(10);
SPI1_ReadWriteByte(RDATAC); // Send start continuous read data command
Delay_1us(10);
CS_H;
START_H; // start transition
CS_L;/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE *//* USER CODE BEGIN 3 */
if(UART_RX_STA & 0x8000)//Receive data sent by APP
{ if(UART_RX_BUF[0] == 0x30) { Data_Processing((uint8_t* )UART_RX_BUF);//Data processing } UART_RX_STA = 0;//clear the flag to 0 }
// OLED_ShowString(0,0,(uint8_t *)" end ",16,1);//Display current state
//OLED_Refresh();//Refresh OLED
if(flog==1)
{ Input_data1=(float32_t)( ch1_data^0x800000); // Implement FIR filtering arm_fir_f32(&S1, &Input_data1, &Output_data1, blockSize); Input_data2=(float32_t)(ch2_data^0x800000); // // Implement FIR filtering arm_fir_f32(&S2, &Input_data2, &Output_ data2, blockSize); // compare size // if(min[1]>Output_data2) // min[1]=Output_data2; // if(max[1]<Output_data2) // max[1]=Output_data2;
if(min[1]>Output_data2) min[1]=Output_data2;
if(max[1]<Output_data2) max[1]=Output_data2;
BPM_LH[0]=BPM_LH[1];
BPM_LH[1]=BPM_LH [2];
BPM_LH[2]=Input_data2;
if((BPM_LH[0]<BPM_LH[1])&&(BPM_LH[1]>max[0]-Peak/3)&&(BPM_LH[2]<BPM_LH[1]))
{
BPM=(float)(60000.0/(point_cnt*4)+50.221);
point_cnt=0;
// if(BPM<200)
// {
// sprintf(Heart_rate,"%.3f",BPM);
//
sprintf(Input1,"%.3f",Input_data2);
LCD_WriteString(124, 200, LCD_COLOR_BLACK, LCD_COLOR_WHITE, (uint8_t *)but);
// Release((char*)"Heart_rate",(char*)Heart_rate); //发布OLED_ShowString(0,48,(uint8_t *)"hr: ",16,1);//Display the current state
OLED_ShowString(48,48,(uint8_t *)Heart_rate,16,1);//Display the current state
OLED_ShowString(48 ,32,(uint8_t *)Input1,16,1);//Display the current status
OLED_Refresh();//Refresh OLED
//
// }
} // Re-measure the maximum and minimum values p_num++
every 2000 points ;; if (p_num>2000) { min[0]=min[1]; max[0]=max[1]; min[1]=0xFFFFFFFF; max[1]=0; Peak=max[0]-min[0 ]; p_num=0;
}
// Data: respiratory wave, ECG signal, heart rate
// printf("B: %8d",(u32)Output_data1);
// printf("A: %8d",((u32)Output_data2));
/ / printf("C: %6.2f",(BPM));
sprintf(Heart_rate,"%.3f",BPM);
OLED_ShowString(0,48,(uint8_t *)"hr: ",16,1);/ /Display the current state
OLED_ShowString(48,48,(uint8_t *)Heart_rate,16,1);//Display the current state
OLED_Refresh();//Refresh OLEDflog=0;
}
HAL_Delay (500);
// HAL_ADC_Start_DMA(&hadc1,(uint32_t*)&AD_Value,1);
// Voltage=(double)AD_Value[0]*(3.3/4096)*1000;//Convert actual voltage Within 3.3V
// temp=204.6398-(7.857923E-06*Voltage*Voltage)-(1.777501E-1*Voltage);//The specific calculation method of temperature calculation and fitting second-order transfer function can refer to the chip manual 11-14 Page
while(mpu_dmp_get_data(&pitch, &roll, &yaw)); //You must wait with while to read successfully
// mpu_dmp_get_data(&pitch, &roll, &yaw);
MPU_Get_Accelerometer(&aacx,&aacy, &aacz); //Get the acceleration sensor Data
MPU_Get_Gyroscope(&gyrox, &gyroy, &gyroz); //get gyroscope data
step(&pitch, &roll, &yaw); //calculation steps
dis = MPU_count*20;
sprintf(Distance,"%dcm",dis);//distance data conversion
sprintf(MPU_step,"%d",MPU_count);//step data conversion
sprintf(Temp,"%2d.%02dC ",(uint16_t) temp,(uint16_t)(fabs(temp)*100)%100);//Temperature data conversion
OLED_ShowString(0,0,(uint8_t *)"dis: ",16,1);//Display current status
OLED_ShowString(48 ,0,(uint8_t *)Distance,16,1);//Display the current stateOLED_ShowString(0,16,(uint8_t *)"step: ",16,1);//Display the current state
OLED_ShowString(64,16,(uint8_t *)MPU_step,16,1);//Display the current state
OLED_ShowString(0 ,32,(uint8_t *)"temp: ",16,1);//Display the current state
OLED_ShowString(64,32,(uint8_t *)Temp,16,1);//Display the current stateOLED_Refresh();//刷新OLED
Release((char*)"MPU_step",(char*)MPU_step);
Release((char*)"Heart_rate",(char*)Heart_rate); //发布
}
/* USER CODE END 3 */
}
4. Schematic diagram:
The following is the schematic diagram of each module of the whole project:
Five, more:
If you want to understand the whole project in more detail, you can go to station b to watch this video demonstration, the following is the video link:
Give a free triple! ! !