当前位置:网站首页>Bluetooth health management device based on stm32

Bluetooth health management device based on stm32

2022-06-27 09:33:00 InfoQ

1.  Preface

With the development of mobile communication technology , Increasingly popular mobile Internet , The traditional Internet is already migrating to the mobile Internet , Intelligent wearable devices have developed very rapidly in recent years , Become a hot industry , By means of sensors , Information exchange with human body , It is an intelligent device born under the new concept , It has a wide range of applications , And can continuously upgrade according to user needs . Intelligent wearable devices are improving people's quality of life 、 It will play a very important role in promoting intelligent lifestyle .

According to different main functions , Intelligent wearable device products can be divided into the following categories : Sports and health 、 Somatosensory interaction class 、 Information information 、 Medical health and comprehensive function, etc , Each type of equipment is targeted at different market segments and consumer groups . Sports and medical health equipment include sports 、 Body side wrist strap and smart bracelet , The main consumers are mass consumers ; The devices of somatosensory control and comprehensive functions include smart glasses, etc , The consumer group is mainly young people ; Information consulting devices include smart watches , The main consumers are mass consumers . So far , There are many users of medical and sports health equipment .

With the increasingly fierce competition in the intelligent wearable industry , The phenomenon of homogeneous products is becoming more and more serious , All kinds of intelligent hardware with only a single function have begun to seek cooperation with other intelligent hardware . some time , As the technology of intelligent wearable products in a single field becomes more and more mature , Products in different fields and functional demands will complement each other in function according to the actual needs of users , So as to bring a more intelligent experience that meets the needs of users , The direction of development will be increasingly clear and diversified .

Current adoption STM32 Plus a variety of peripheral sensors with Bluetooth + mobile phone APP Designed a personal health monitoring and management equipment , adopt BLE Low power Bluetooth uploads the collected sensor data to the mobile phone APP Real time display .

null
null

2.  Function summary

The main function
(1) Development board selection STM32 Single chip microcomputer does data processing .

(2) Develop a Android mobile phone APP, Used to display data uploaded by Bluetooth

(3) Use Bluetooth to transmit data , Connect the temperature sensor 、 Heart rate pulse sensor 、 The data collected by the acceleration sensor is uploaded to the mobile phone for display .

Generally, the pulse is equal to the heart rate , Blood from the heart flows forward along the walls of the blood vessels , Form a pulse . Normal people, regardless of adults 、 The child 、 aged , Under normal conditions, the pulse and heart rate are consistent . If you have a heart attack , Because the heart's own conduction system has a protective effect , The ventricular rate cannot be the same as the atrial rate , The velocity of conduction in the blood vessels is also different , The pulse will be weak sometimes , Sometimes strong . You may not feel it when it is weak , In this state, the pulse will be less than the heart rate , Heart rate is higher than pulse in atrial fibrillation , So the pulse does not necessarily represent the heart rate .

(4) If the measured body temperature exceeds the warning value , The buzzer on the local device will sound a warning prompt .

Hardware to be used :

(1)STM32 System board

(2) Temperature sensor

(3) Gyroscope sensor

(4) Heart rate pulse sensor

3.  Hardware selection

3.1 MPU6050 gyroscope


null
MPU6050 characteristic :

(1) High performance triaxial acceleration + Six axis sensor module of three-axis gyroscope MPU6050 chip ;

(2) You can use your own digital motion processor (DMP) Hardware acceleration engine , Through the master IKC Interface , Output the data after attitude calculation to the application terminal , Use InvenSense Sports processing database provided by the company , Realize attitude calculation , It reduces the load of motion processing on the operating system and greatly reduces the difficulty of development ;

(3) Small volume , With temperature sensor ;

(4) Support IIC Slave address setting and interrupt ;

(5) compatible 3.3V/5V System ;

3.2 STM32 Development board


null

3.3  Female to female DuPont line


null

3.4  Temperature sensor


null
GY-MCU90615  Is a low-cost infrared temperature module . Working voltage  3-5v  Low power consumption , Small volume . How it works ,  Is to read the infrared temperature data through the single chip microcomputer , A serial port (TTL  level ) Communication mode output . The baud rate of the serial port is  9600bps  And  115200bps  There are two modes: continuous output and query output , Can adapt to different working environments , Connect with all microcontrollers and computers .

Communication protocol
Serial port sends command bytes :

(1)、 Serial communication parameters ( Default baud rate value 9600 bps, It can be set by software )
Baud rate :9600 bps  Check bit :N  Data bits :8  Stop bit :1

Baud rate :115200 bps  Check bit :N  Data bits :8  Stop bit :1

(2)、 Module input commands , Sent by external controller to GY-MCU90615 modular ( Hexadecimal )

 1、 Frame head :0xa5

Command format : Frame head + Instructions + The checksum (8bit)( Such as automatically reading the temperature command =0xA5+0x45+0xEA)

2、 Command instruction : 

Continuous output instruction :0xA5+0x45+0xEA---------------- Temperature data ( The data type returned by the module is 0x45)

Query output instruction :

0xA5+0x15+0xBA --------------- Temperature data ( The data type returned by the module is 0x45)

Configuration instructions :( It takes effect after power failure and restart ) 

Baud rate configuration :

0xA5+0xAE+0x53 ---------------9600( Default )

0xA5+0xAF+0x54 ---------------115200

Whether to automatically send temperature data configuration when powered on :

0xA5+0x51+0xF6--------------- Automatically output temperature data after power on ( Default )

0xA5+0x52+0xF7--------------- No automatic output of temperature data after power on

 

Communication protocol

A serial port to receive :

(1)、 Serial communication parameters ( Default baud rate value 9600 bps, It can be set by software )

  Baud rate :9600 bps  Check bit :N  Data bits :8  Stop bit :1

Baud rate :115200 bps  Check bit :N  Data bits :8  Stop bit :1

 

(2)、 Module output format , Each frame contains 9 Bytes ( Hexadecimal ):

 ①.Byte0: 0x5A  Frame header flag  

 ②.Byte1: 0x5A  Frame header flag  

③.Byte2: 0X45  Data type of this frame (0X45: Temperature data )

 ④.Byte3: 0x04  Data volume ( following 4 Data 2 Group as an example )

 ⑤.Byte4: 0x00~0xFF  data 1 high 8 position

 ⑥.Byte5: 0x00~0xFF  data 1 low 8 position

 ⑦.Byte6: 0x00~0xFF  data 2 high 8 position

⑧.Byte7: 0x00~0xFF  data 2 low 8 position

⑨.Byte8: 0x00~0xFF  The checksum ( Previous data accumulation and , Leave only low 8 position ) 

(3)、 Data calculation method

Temperature calculation method  :

temperature =  high 8 position <<8  low 8 position ( The result is the actual angle multiplied by 100)

  example : Send instructions :A5 45 EA , Received a frame of data :

<5A- 5A- 45- 04- 0C- 78- 0D- 19- A7 >

  Express TO( A signed 16bit, Indicates the target temperature ):TO=0x0C78/100=31.92 ℃

  Express TA( A signed 16bit, Represents the ambient temperature ):TO=0x0D19/100=33.53 ℃

Usage method
This module outputs data for serial port , After the user connects through the serial port , Send output instructions , for example 0xA5+0x45+0xEA To module , The module will continuously output temperature data ; If you want to query the output, you can send 0xA5+0x15+0xBA To module , Every time it's sent , The module will return temperature data once , The query frequency should be less than 10hz, If higher than 10hz Please use continuous output mode , Send 0xA5+0x45+0xEA Instructions ;

3.5  Pulse sensor


null
PulseSensor  It is a photoelectric reflective analog sensor for pulse and heart rate measurement . Put it on your fingers 、 Earlobe, etc , Through wire connection, the collected analog signal can be transmitted to  Arduino  And other single chip computers are used to convert into digital signals , Re pass  arduino  After simple calculation by single chip microcomputer, the heart rate value can be obtained , In addition, the pulse waveform can be uploaded to the computer through the serial port to display the waveform . PulseSensor  Is an open source hardware ,  At present, there are corresponding on foreign official websites  arduino  Program and host computer  Processing  Program ,  It is suitable for scientific research and teaching demonstration of heart rate , It is also very suitable for secondary development .

null
Special reminder : On the back of the sensor are the electronic components , Please do not touch directly with your fingers ,  In order to avoid static electricity or perspiration causing back device damage .  You can paste black fasteners on the back ,  A transparent film is pasted on the front to protect the sensor .

null
The interface of the sensor is  3  individual ,  As shown in the red box above .  Please don't speculate by yourself according to the color of the line ,  It should be distinguished according to the identification on the back of the circuit board . The red box  3  Root line , Be marked with  S  Analog signal output line ( Leftmost ) ;  Be marked with + Is the power input line ( middle ); Be marked with - Is the ground wire ( Far right ) . To sum up :S →  Pulse signal output ( I want to connect to the MCU  AD  Interface )

VCC→ 5v( or  3.3v) Power input

GND→ GND  The earth

3.6 PCB Hole board


null

3.7 BLE Low power Bluetooth module


null

4.  PC programming

4.1  development environment

The upper computer software adopts Qt framework design ,Qt It's a cross platform C++ GUI application framework .Qt It's a 1991 Year by year Qt Company Cross platform development C++ GUI application development framework . It can develop GUI Program , It can also be used to develop non GUI Program , For example, console tools and servers . Simply speaking ,QT It can easily help you make software with interface , It doesn't even require you to put a lot of energy .

QT Official website :
 
https://www.qt.io/

null
QT5.12.6 Download address :
https://download.qt.io/archive/qt/5.12/5.12.6/

Open the download link and select the following version to download :

qt-opensource-windows-x86-5.12.6.exe 13-Nov-2019 07:28 3.7G Details

Installation of network software is interrupted , Otherwise, you will be prompted to enter the account .

During installation , Check one in the first check box mingw 32 The compiler can , The others are OK by default , Click next to continue the installation .

null
choice MinGW 32-bit  compiler :

null
choice MinGW 32-bit  compiler :

null
null
null

4.2  Design effect

null

5. STM32 Development

The following is just a screenshot of the schematic diagram , Running effect , Part of the code , It is difficult to upload the hardware demonstration video , If a complete project is required 、 System schematic diagram 、 Relevant hardware information , You can download it here :
https://download.csdn.net/download/xiaolong1126626497/85793557

5.1  Hardware wiring

The hardware wiring instructions of this design : 
(1)BLE Low power Bluetooth module
PA2(TX)--RXD  Module receiving pin
PA3(RX)--TXD  Module sending pin
GND---GND  The earth
VCC---VCC  Power Supply (3.3V)

(2) Infrared temperature measurement module
PB10(TX)--RXD  Module receiving pin
PB11(RX)--TXD  Module sending pin
GND---GND  The earth
VCC---VCC  Power Supply (3.3V)

(3)MPU6050 gyroscope
1 VCC 3.3V/5V  Power input  ----> Pick up 3.3V
2 GND  Ground wire  ---> Pick up GND
3 IIC_SDA IIC  Communication data line  -->PB6
4 IIC_SCL IIC  Communication clock line  -->PB7
5 MPU_INT  Interrupt output pin  ----> Unanswered
6 MPU_AD0 IIC  Slave address setting pin --> Unanswered
 AD0 Pin description :ID=0X68( In the air / Pick up  GND) ID=0X69( Pick up  VCC)
 
 (4) Heart rate detection module
PA1--- Heart rate module DAT Output pin
GND---GND  The earth
VCC---VCC  Power Supply (3.3V)


(--) On board LED The lamp : Low level light
LED1--PC13 
BEEP2--PC14

(--) Onboard keys : 
KEY1--PA0  Press to high level

5.2  Program download

Connect the development board to the computer , Open the program to download the software , Follow the instructions below to download .

null

5.3  System schematic diagram

null

5.4 keil engineering

null
null

5.5  Function code

#include &quot;stm32f10x.h&quot;
#include &quot;delay.h&quot;
#include &quot;led.h&quot;
#include &quot;key.h&quot;
#include &quot;sys.h&quot;
#include &quot;usart.h&quot;
#include <string.h>
#include <stdlib.h>
#include &quot;timer.h&quot;
#include &quot;adc.h&quot;
#include &quot;mpu6050.h&quot;

/*--------- Heart rate related data values ---------------*/
extern int IBI; // Adjacent beat time
extern int BPM; // Heart rate  
extern int Signal; // Raw signal value  
extern unsigned char QS; // Found heartbeat sign

short aacx,aacy,aacz; // Acceleration sensor raw data
short gyrox,gyroy,gyroz; // Gyroscope raw data
float TO=0; // Infrared temperature measurement - Target temperature
float TA=0; // Infrared temperature measurement - Object temperature
 

// Bluetooth send buffer
u8 BLE_TX_BUFF[100];

/*
The main function :  The entry of program execution
*/
int main(void)
{
 u32 i=0;
 u8 key_val;
 u32 wifi_TimeCnt=0;
 JTAG_Set();
 USART1_Init(115200); // A serial port 1 The initialization
 USART2_Init(9600); // A serial port - bluetooth
 TIMER2_Init(72,20000); // Timeout time 20ms
 USART3_Init(9600); // A serial port - Infrared temperature measurement module
 TIMER3_Init(36,20000); // Timeout time 20ms
 
 // On board button initialization
 KEY_Init();
 // On board LED Lamp initialization
 LED_Init();
 
 //ADC initialization
 ADC_Init(); 
 // Timeout time 2ms 
 TIMER1_Init(72,2000); 
 // initialization MPU6050
 while(MPU6050_Init()) 
 {
 printf(&quot; Three axis accelerometer 、 Gyro initialization failed !\r\n&quot;);
 DelayMs(1000);
 }

 printf(&quot; The system works normally ..\r\n&quot;);
 
 while(1)
 { 
 // Onboard key detection
 key_val=KEY_GetValue();
 if(key_val)
 {
 printf(&quot; Press the key ...\r\n&quot;);
 }
 
 // Time record
 DelayMs(10);
 wifi_TimeCnt++;
 if(wifi_TimeCnt>=100) //1000 One millisecond
 {
 wifi_TimeCnt=0;
 LED1=!LED1;
 MPU6050_Get_Gyroscope(&gyrox,&gyroy,&gyroz); // Get the original data of the gyroscope
 MPU6050_Get_Accelerometer(&aacx,&aacy,&aacz); // Get the acceleration sensor data
 printf(&quot; Three axis gyroscope :x=%d y=%d z=%d\r\n&quot;,gyrox,gyroy,gyroz);
 printf(&quot; Triaxial acceleration :x=%d y=%d z=%d\r\n&quot;,aacx,aacy,aacz);
 printf(&quot;( heart rate )BPM=%d\r\n&quot;,BPM);
 
 // Send data to Bluetooth , Send it to the upper computer
 // for example : update,12,13,14,15,20.5
 // respectively : The acceleration X Axis , The acceleration Y Axis , The acceleration Z Axis , heart rate 、 Temperature
 sprintf((char*)BLE_TX_BUFF,&quot;update,%d,%d,%d,%d,%f&quot;,aacx,aacy,aacz,BPM,TO);
 USARTx_StringSend(USART2,(char*)BLE_TX_BUFF);
 }

 //  Receive the data returned by Bluetooth
 if(USART2_RX_FLAG)
 {
 USART2_RX_BUFFER[USART2_RX_CNT]='\0';
 
 printf(&quot; Bluetooth receives data :\r\n&quot;);
 // The data returned to the serial port print server
 for(i=0;i<USART2_RX_CNT;i++)
 {
 printf(&quot;%c&quot;,USART2_RX_BUFFER[i]);
 }
 USART2_RX_CNT=0;
 USART2_RX_FLAG=0;
 }
 
 // Receive the data received by the infrared temperature measurement module in real time
 if(USART3_RX_FLAG)
 {
 printf(&quot;\r\n Infrared temperature measurement starts :&quot;);
 for(i=0;i<USART3_RX_CNT;i++)
 {
 printf(&quot;%#x &quot;,USART3_RX_BUFFER[i]);
 }
 printf(&quot; End of infrared temperature measurement .\r\n&quot;);
 
 u8 sum=0,i=0;
 for(sum=0,i=0;i<(USART3_RX_BUFFER[3]+4);i++)
 {
 sum+=USART3_RX_BUFFER[i]; 
 }
 
 /*
Temperature calculation method  :
temperature = high  8  position <<8| low  8  position ( The result is the actual angle multiplied by  100)
example : Send instructions : A5 45 EA , Received a frame of data : <5A- 5A- 45- 04- 0C- 78- 0D- 19- A7 >
Express  TO( A signed  16bit, Indicates the target temperature ): TO=0x0C78/100=31.92 ℃
Express  TA( A signed  16bit, Represents the ambient temperature ): TO=0x0D19/100=33.53 ℃
 */
 if(sum==USART3_RX_BUFFER[i])// Checksum judgment
 {
 TO=(float)((USART3_RX_BUFFER[4]<<8)|USART3_RX_BUFFER[5])/100.0; // Get the real temperature
 TA=(float)((USART3_RX_BUFFER[6]<<8)|USART3_RX_BUFFER[7])/100.0; // Get the real temperature  
 }
 
 printf(&quot;TO: %f\r\n&quot;,TO);
 printf(&quot;TA: %f\r\n&quot;,TA);
 
 memset(USART3_RX_BUFFER,0,sizeof(USART3_RX_BUFFER));
 USART3_RX_CNT=0;
 USART3_RX_FLAG=0;
 } 
 } 
}

原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/178/202206270924478315.html