2443 views|1 replies

171

Posts

0

Resources
The OP
 

Temperature, humidity and air pressure detection function of pedometer wristband based on F103 and X-NUCLEO-IKS01A3 [Copy link]

 This post was last edited by sylar^z on 2019-8-12 00:21

This pedometer bracelet design is based on the F103 core board and the X-NUCLEO-IKS01A3 sensor development board. The temperature and humidity detection functions are realized by the HTS221 sensor on the X-NUCLEO-IKS01A3. The air pressure detection is realized by the LPS22HH sensor on the X-NUCLEO-IKS01A3.

HTS221 is an ultra-compact sensor for relative humidity and temperature detection. HTS221 has a supply voltage of 1.7-3.6V, a sampling frequency of 1Hz-12.5Hz, a humidity accuracy of ±3.5%RH, 20 to +80%RH, and a temperature accuracy of ±0.5°C, 15 to +40°C. It can communicate via the commonly used SPI and I2C.

LPS22HH is an ultra-small piezoresistive absolute pressure sensor that can be used as a digital output barometer. LPS22HH has a power supply voltage of 1.7-3.6V, an absolute pressure detection range of 260 to 1260 hPa, and an absolute pressure accuracy of 0.5 hPa. It can communicate via the commonly used SPI and I2C.

The pedometer bracelet uses HTS221 to realize the temperature and humidity detection function and LPS22HH to realize the air pressure detection function. The function is added based on the previous procedure for adding the pedometer function (see " Wake-up function of pedometer bracelet based on F103 and X-NUCLEO-IKS01A3 ").

First, some changes were made to the previous program. The HTS221 sensor and LPS22HH sensor were turned on, and a 1S event flag was generated through SysTick. Temperature data, humidity data, and air pressure data were collected every 1S, and the three most recent data were used for mean filtering to generate a relatively stable temperature, humidity, and air pressure value. At the same time, key event detection and application were added, including single-click, double-click, and long-press events. Currently, single-click is used to switch the display page. The step counter-temperature-humidity-air pressure interface is displayed in a loop.


//Environmental sensor data collection

if(currData.env_data_get_flag)

{

currData.env_data_get_flag = 0;

if(0 == HTS221_Get_HUM(&currData.humidity[currData.humidityPos]))

{

currData.oledShowData.humidity = 0;

for(uint16_t i = 0; i < DATA_MEAN_NUM; i++)

{

currData.oledShowData.humidity += currData.humidity;

}

currData.oledShowData.humidity /= DATA_MEAN_NUM;

}

if(0 == HTS221_Get_TEMP(&currData.temperature[currData.temperaturePos]))

{

currData.oledShowData.temperature = 0;

for(uint16_t i = 0; i < DATA_MEAN_NUM; i++)

{

currData.oledShowData.temperature += currData.temperature;

}

currData.oledShowData.temperature /= DATA_MEAN_NUM;

}

if(0 == LPS22HH_Get_PRESS(&currData.pressure[currData.pressurePos]))

{

currData.oledShowData.pressure = 0;

for(uint16_t i = 0; i < DATA_MEAN_NUM; i++)

{

currData.oledShowData.pressure += currData.pressure;

}

currData.oledShowData.pressure /= DATA_MEAN_NUM;

}

}


//Key event detection

if(KeyEventDetected)

{

KeyEventDetected = 0;

if(0 == KeyPressed)

{

if(KEY_PRESSED_GRADE_UNKNOW == keyPressedGrade)

{

if((HAL_GetTick() - keyPressedTick) > KEY_PRESSED_DELAY)

{

keyPressedGrade = KEY_PRESSED_GRADE_TAP;

}

}

else

{

keyPressedGrade = KEY_PRESSED_GRADE_UNKNOW;

}

}

}

else if(KeyPressed)

{

if(HAL_GPIO_ReadPin(USER_KEY_GPIO_Port, USER_KEY_Pin) == (uint32_t)GPIO_PIN_RESET)

{

if(KEY_PRESSED_GRADE_UNKNOW == keyPressedGrade)

{

if(keyPressedTick < (keyPressedTickLast + KEY_PRESSED_D_TAP_DELAY))

{

keyPressedGrade = KEY_PRESSED_GRADE_D_TAP;

}

else if((HAL_GetTick() - keyPressedTick) > KEY_PRESSED_L_TAP_DELAY)

{

keyPressedGrade = KEY_PRESSED_GRADE_L_TAP;

keyPressedTickLast = 0;

}

}

}

}


//Key processing function

void key_process(uint8_t currGrade)

{

static emKeyPressedGrade keyPressedGradeOld = KEY_PRESSED_GRADE_UNKNOW;

if(keyPressedGradeOld == currGrade)

{

return;

}

keyPressedGradeOld = currGrade;

switch(currGrade)

{

case KEY_PRESSED_GRADE_TAP:

currData.oledShowData.currPage++;

if(currData.oledShowData.currPage >= HMI_PAGE_UNKNOW)

{

currData.oledShowData.currPage = HMI_PAGE_TEMPERATURE;

}

keyPressedGrade = KEY_PRESSED_GRADE_UNKNOW;

break;

case KEY_PRESSED_GRADE_D_TAP:

break;

case KEY_PRESSED_GRADE_L_TAP:

break;

default:

break;

}

}

The first picture shows the button positions. The screen is usually off, but the program is designed to automatically turn off the display after 6 seconds of inactivity to save energy. Just tap lightly to wake up the screen.

Step counting interface display effect:

Temperature display interface

Humidity display interface

Air pressure display interface

Attached source code: CORE-STM32F103C8_FOR_X-NUCLEO_IKS01A3-ENV_SENSOR.rar (13.3 MB, downloads: 278)

HTS221 manual: hts221.pdf (741.71 KB, downloads: 3)

LPS22HH manual: lps22hh.pdf (1.21 MB, downloads: 4)

Latest reply

Thanks for sharing   Details Published on 2019-8-12 15:00
 

994

Posts

3

Resources
2
 

Thanks for sharing

 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list