Engineer safety black box
Author: sipower
- Project Background ( 100-200 words )
As China's title of "infrastructure maniac" becomes widely known, more and more workers are engaged in some dangerous work, such as high altitude, underground, tunnel, and engineering vehicles. In order to ensure the safety of these construction workers and to get timely rescue in case of accidents, I designed this engineering safety black box. The device can collect the heart rate of construction workers, the temperature and humidity of the surrounding environment, identify the movement state, and determine whether a fall or collision accident has occurred. It is transmitted to the remote monitoring center through the network. Once the monitoring personnel find an abnormality, they can immediately organize rescue.
- Brief introduction of the work ( 100-200 words)
The device uses the sensors on the SensorTile.box to collect the temperature, humidity, and atmospheric pressure of the environment, and uses the inertial module LSM6DSOX to identify the wearer's movement status. By converting the atmospheric pressure into altitude, the change in altitude can remind the remote monitoring personnel to pay attention to whether the wearer is working at high altitude. The movement status can be used to determine whether the wearer has fallen or collided. Two serial ports are connected to the SensorTile.box , one of which is connected to the heart rate sensor to detect the wearer's physiological parameters. The other serial port is connected to the communication module for uploading data.
At first, I planned to use the " ST BLE Sensor " APP to upload data. After a lot of research and testing, I found that it could not meet my design requirements, could not add heart rate, and the remote platform was not friendly enough. Finally, I decided to use the WIFI module to upload data for easy debugging. The actual application can be replaced with a GSM communication module for outdoor applications. The remote monitoring platform uses China Mobile's onenet Internet of Things platform, which is rich in functions and has a simple and intuitive interface. You can view real-time data directly through the web page. The final display effect is as follows:
3. System Block Diagram (Combined Graphics and Text)
The whole system is mainly divided into four parts. The main control is the SensorTile.box module. Since the IO port is 1.8 V , I chose a Shengbangwei SGM4564 level conversion evaluation board to convert the level to 3.3 V , which is convenient for connecting to the WiFi module and heart rate module. A USB-UART adapter board interface is also reserved on the board to monitor whether the received and sent data is normal during debugging.
4. Functional description of each part (combined with pictures and text)
The two modules used are introduced below.
Heart Rate Sensor:
http://www.jingfantech.com/
JFH111 is a multi-spectral physiological data measurement module developed by Jingfan Technology, which can accurately measure information such as pulse waveform, heart rate, blood oxygen value and vascular microcirculation parameters. Thanks to the patented front-end sensor technology, the module sensitivity and signal-to-noise ratio have been greatly improved among similar products. The module combines Jingfan's unique signal conditioning technology and algorithm to directly output pulse waveform, heart rate, blood oxygen value and vascular microcirculation parameters, greatly reducing the complexity of the system. The user system only needs to communicate with the module through the serial port and directly obtain the measurement results. While being accurate and easy to use, the JFH111 module also has the characteristics of ultra-small size and ultra-low power consumption, which improves the battery life and appearance design flexibility of smart wearable devices.
WiFi Module:
https://www.ai-thinker.com/product/esp8266
The ESP-12S WiFi module is developed by Essence Technology. The core processor of the module, ESP8266, integrates the industry-leading Tensilica L106 ultra-low power 32 -bit micro MCU in a smaller package , with a 16- bit streamlined mode, a main frequency of 80 MHz and 160 MHz , supports RTOS , and integrates Wi-Fi MAC/BB/RF/PA/LNA . The ESP-12S WiFi module supports standard IEEE802.11 b/g/n protocols and a complete TCP/IP protocol stack. Users can use this module to add networking capabilities to existing devices or build independent network controllers. ESP8266 is a high-performance wireless SOC that provides maximum practicality at the lowest cost, providing unlimited possibilities for embedding WiFi functions into other systems.
Shengbang Micro SGM4564 Level Shifter Evaluation Board
The evaluation board is soldered with a four-channel level conversion chip SGM4564 , which has power and signal interfaces, just meeting the needs of two serial ports. The other model pads reserved next to it are just enough to solder the connector of the heart rate sensor, and there is enough space on the other side to solder the wifi module. Finding this board is just right, and one board can handle both external modules. The picture below is the final soldered evaluation board.
Power supply transformation plan:
Since the 3.3V power supply provided by the SensorTileBox itself is only 150mA , which cannot reach the current required by WiFi , I decided to use the TF card for power supply. This DC-DC uses the STBB3J chip, and the single inductor supports buck-boost . The nominal current of the board can reach 400mA , which is an ideal choice. However, the default setting is 2.9V voltage, which is slightly insufficient. I decided to modify the feedback resistor and adjust it to 3.3V . After checking the information, a 680K resistor in parallel with R45 can achieve the purpose. After modification, this is used to power the WiFi module and the heart rate sensor.
The picture below shows a resistor being soldered.
Debugging family portrait:
In the family photo, the protagonist SensorTile.Box is in the middle , and on the right is the level conversion board and the heart rate sensor and wifi module soldered on it. On the left is st-link , and on top are the USB hub and USB-UART conversion board. The heart rate module uses serial port 1 , which is derived from the jtag interface. The wifi module uses serial port 2 , which was originally connected to the Bluetooth module. Since Bluetooth actually uses spi , the serial port is idle, so I disconnected the resistor and connected the wifi module.
The entire hardware modification took me 2 weeks of my spare time. The workmanship was poor and the workmanship was a bit rough, but fortunately it works fine.
5. Source code and sensor data processed in the case study
The entire software is modified based on the official routine BLEMLC . The directory is as follows:
STM32CubeFunctionPack_STBOX1_V1.1.0\Projects\STM32L4R9ZI-SensorTile.box\Applications\BLEMLC
First, I studied the characteristics and parameters of the LSM6DSOX sensor. This smart sensor can automatically detect the state of motion by configuring parameters, which greatly saves the operation complexity of the microcontroller, ensures consistency, and facilitates low-power design. After learning about the FSM and MLC configuration and training process, I also tried to train the parameters myself, but found that it was still a bit difficult, mainly because I didn't understand it deeply enough, and the data recognition after configuration was not very accurate. Due to limited time, I directly used the trained data that came with the BLEMLC routine, because this data happened to be consistent with my needs. The sensor initialization function is as follows:
/** @brief Initialize the LSM6SDOX MEMS Sensor for MLC
* @param None
* @retval None
*/
void Init_MEMS_MLC(void)
{
ucf_line_t *ProgramPointer;
int32_t LineCounter;
int32_t TotalNumberOfLine;
int32_t RetValue;
/* Init Accelero */
if (BSP_MOTION_SENSOR_Init(LSM6DSOX_0, MOTION_ACCELERO) == BSP_ERROR_NONE) {
STBOX1_PRINTF("OK Init Accelero Sensor\n\r");
} else {
STBOX1_PRINTF("Error Init Accelero Sensor\n\r");
Error_Handler();
}
/* Feed the program to Machine Learning Core */
/* Activity Recognition Default program */
ProgramPointer = (ucf_line_t *)lsm6dsox_activity_recognition_for_mobile;
TotalNumberOfLine = sizeof(lsm6dsox_activity_recognition_for_mobile) / sizeof(ucf_line_t);
STBOX1_PRINTF("-->Activity Recognition for LSM6DSOX MLC\r\n");
STBOX1_PRINTF("UCF Number Line=%ld\r\n",TotalNumberOfLine);
for (LineCounter=0; LineCounter<TotalNumberOfLine; LineCounter++) {
RetValue = BSP_MOTION_SENSOR_Write_Register(LSM6DSOX_0,
ProgramPointer[LineCounter].address,
ProgramPointer[LineCounter].data);
if(RetValue!=BSP_ERROR_NONE) {
STBOX1_PRINTF("Error loading the Program to LSM6DSOX [%ld]->%lx\n\r",LineCounter,RetValue);
Error_Handler();
}
}
STBOX1_PRINTF("Program loaded inside the LSM6DSOX MLC\n\r");
{
/* Enable interrupts from INT1 LSM6DSOX */
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOA_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_2;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI2_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI2_IRQn);
STBOX1_PRINTF("Enabled LSM6DSOX INT1 Detection \n\r");
}
{
/* Enable interrupts from INT2 LSM6DSOX */
GPIO_InitTypeDef GPIO_InitStruct;
__HAL_RCC_GPIOE_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_3;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
/* EXTI interrupt init*/
HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
STBOX1_PRINTF("Enabled LSM6DSOX INT2 Detection \n\r");
}
}
|
The next step is to transplant the function of the environmental sensor. First,
The sensor driver files in STM32CubeFunctionPack_STBOX1_V1.1.0\Projects\STM32L4R9ZI-SensorTile.box\Applications\BLESensors are transplanted, see the figure below.
Then modify the code, mainly modify main.c and TargetPlatform.c . First, comment out all Bluetooth-related initialization. Then extract the required sensor initialization function from the Bluetooth initialization code and put it directly in front of the while loop. After error checking and modification, the environmental sensor data and activity status recognition functions are combined. Finally, modify the event processing code in the loop function and callback function to serial port output, and you are done. The main modifications are shown in the figure below.
Next, add the serial port driver to realize the heart rate sensor reading and WiFi module operation. First, add two serial port initialization codes in TargetPlatform.c
Enable serial port interrupt in the main program
Define serial port sending and receiving parameters
Write a serial port receiving interrupt callback function. For the simpler heart rate sensor data packet, directly divide the packet. Each time a complete packet is received, a flag is generated to facilitate the main program processing. For the wifi module, the official serial port interrupt processing code is transplanted to realize data reception.
In the main program, I process and display the data, and I still use the USB virtual serial port output.
After realizing the heart rate reception and WiFi module communication, only the following function is needed to complete the data interaction with the onenet platform:
void ESP8266_Post_OneNet(char *devices_id,char *api_key,char *datastream_id,char *point_value)
{
char cStr[1500] = {0};
u16 length=0;
char post_str[100]={0};
char *post_p1=0;
char *post_p2=0;
char check[1]={0};
sprintf((char*)post_str,"{\"%s\":%s}",datastream_id,point_value);
length = strlen(post_str);
sprintf ( cStr,"POST /devices/%s/datapoints?type=3 HTTP/1.1\r\napi-key: %s\r\nHost: api.heclouds.com\r\nContent-Length: %d\r \n\r\n%s",devices_id,api_key,length,post_str );
if(ESP8266_Get_LinkStatus()==3)
{
// PC_Usart("\r\nSend data ......\r\n");
ESP8266_UnvarnishSend (); // Transparent transmission
ESP8266_SendString ( ENABLE, cStr, 0, Single_ID_0 );
HAL_Delay ( 500 );
if((post_p1=(char*)strstr((const char*)strEsp8266_Fram_Record .Data_RX_BUF,"errno")),(post_p1!=NULL)) // Find the start character returned by OneNet after POST
{
if((post_p2=(char*)strstr((const char*)post_p1,"}")),(post_p2!=NULL))// Find the end character returned by OneNet after POST
{
post_p2=strtok((post_p1),":");
post_p2=(char*)strtok(NULL,",");
sprintf((char*)check,"%s",post_p2);
if(check[0]=='0')// Judge whether OneNET has received data, errno:0 means no error, OneNET has received data
{
// PC_Usart("\r\nOneNET received data !\r\n");
}
else
PC_Usart("\r\nOneNET did not receive data !\r\n");
}
}
ESP8266_ExitUnvarnishSend (); // Exit transparent transmission
ESP8266_Cmd ( "AT+CIPMODE=0", "OK", 0, 200 ); // Turn off transparent transmission mode
}
else{
//
ESP8266_ExitUnvarnishSend (); // Exit transparent transmission
ESP8266_Cmd ( "AT+CIPMODE=0", "OK", 0, 200 ); // Turn off transparent transmission mode
PC_Usart(" Reconnect... ");
while (!ESP8266_JoinAP ( User_ESP8266_ApSsid, User_ESP8266_ApPwd ) );
while ( !ESP8266_Link_Server ( enumTCP, User_ESP8266_TcpServer_IP, User_ESP8266_TcpServer_Port, Single_ID_0 ) );
}
}
|
The actual output effect is as follows:
In the activity type output, the onenet application provides a way to use pictures to represent the status. Different values display different pictures. I designed pictures of different states, and after adding them, they are shown as follows:
The actual output results can be found in the following link:
https://open.iot.10086.cn/iotbox/appsquare/appview?openid=ae3a82fa234ecb8be11a091200637fb0
6. Video Demonstration (Video Introduction + Link)
The video introduces the composition of the system and demonstrates how the work works. It can be seen that from the collection of environment, movement, and heart rate information to the final output to the Internet of Things platform, the work fully realizes the requirements of remote monitoring.
7. Project Summary (Project Text Summary + Post Sharing Link Summary)
Through this competition, I first learned that ST actually has such a NB sensor. I really didn't pay much attention to it before. In the future, when I design, I can use it when I need it, without having to look for it all over the world. Secondly, I learned a lot about the Internet of Things. I learned from the ST APP and also understood the current status of the Internet of Things. Now all major Internet companies are scrambling to seize the high ground of the Internet of Things. I also made a comparison and found that China Mobile's onenet is the most friendly for beginners. It is not only free, but also has complete documentation and code. Students in need may wish to try it. Finally, I would like to give ST some suggestions. This set of sensor kits is quite comprehensive and powerful, but the supporting software and documents feel too dogmatic. Although they are rich, they are not flexible enough to use and are not simple and easy to understand. If some example resources based on open source platforms such as Arduino can be provided , it is estimated that everyone will be more convenient and labor-saving to evaluate.
Here is a summary of the posts:
SensorTile.box IoT-related applications (how to connect to Microsoft Azure IoT cloud service)
https://bbs.eeworld.com.cn/thread-1118522-1-1.html
SensorTile.box IoT-related application supplementary content
https://bbs.eeworld.com.cn/thread-1119136-1-1.html
In programming mode, output sensor data from the USB virtual serial port
https://bbs.eeworld.com.cn/thread-1121410-1-1.html
Programming mode, realize activity status recognition and environmental data collection, and output through USB virtual serial port
https://bbs.eeworld.com.cn/thread-1121600-1-1.html
Design of the black box for engineer safety
https://bbs.eeworld.com.cn/thread-1122080-1-1.html
How to connect ESP8266 to OneNet cloud platform as a safety black box for engineers
https://bbs.eeworld.com.cn/thread-1123040-1-1.html
The main functions of the engineering safety black box have been completed
https://bbs.eeworld.com.cn/thread-1127604-1-1.html
8.
None other.
工程人员安全黑匣子.docx
(1.6 MB, downloads: 5)
|