打印
[信息]

基于Nucleo-L476L的健康运动助手项目开发

[复制链接]
372|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
jcky001|  楼主 | 2021-3-10 09:25 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

1、简述-基于Nucleo-L476L的健康运动助手

   基于Nucleo-L476L的健康运动助手是一个基于STM32L476L的便携运动健康电子助手的原型设计。实现以下功能:

   启动后不读取传感器数据,降低功耗。当检测到运动数据后,启动计步器,开始计算运动步数,同时读取运动环境的温度和湿度,同时读取大气压,折算运动位置的海拔。在中止运动一段时间后,停止计数,并输出运动量。


2、采用的硬件

    采用Nucleo-STM32L476和X-NUCLEO-IKS01A3。其中应用到的四种传感器有:

  • LSM6DSO 用于计步器计数,
  • LIS2DW12 用于从休眠中唤醒,进入传感器读取和计步器计数
  • LPS22HH   用于读取大气压数据
  • STTS751   用于读取环境温度

3、开发环境和工具

3.1 开发环境使用Arduino1.8.9

3.2 开发需要先安装以上4种传感器的arduino驱动程序,然后直接在程序中引用库就可以了。


4、实现代码

这个代码使用了2个标志位mems_event = 0 和 ped_event=0,分别启动中断,上升沿启动内部置位的变化。

同时设定了一个IDLEPERIOD,演示设置位10000ms,即10秒,之后就退出计数。


  • /**
  • ******************************************************************************
  • * @brief   Arduino test application for the STMicrolectronics X-NUCLEO-IKS01A3
  • ******************************************************************************
  • */
  • // Includes
  • #include <LSM6DSOSensor.h>
  • #include <LIS2DW12Sensor.h>
  • #include <LPS22HHSensor.h>
  • #include <STTS751Sensor.h>
  • #ifdef ARDUINO_SAM_DUE
  • #define DEV_I2C Wire1
  • #elif defined(ARDUINO_ARCH_STM32)
  • #define DEV_I2C Wire
  • #elif defined(ARDUINO_ARCH_AVR)
  • #define DEV_I2C Wire
  • #else
  • #define DEV_I2C Wire
  • #endif
  • #define SerialPort Serial
  • #define INT_1 4
  • #define IDLEPERIOD 10000
  • // Components
  • LSM6DSOSensor *AccGyr;
  • LIS2DW12Sensor *Acc2;
  • LPS22HHSensor *Press;
  • STTS751Sensor *Temp;
  • //Interrupts.
  • volatile int mems_event = 0;
  • volatile int ped_event = 0;
  • uint16_t step_count = 0;
  • char report[256];
  • uint32_t previous_tick;
  • void INT0Event_cb();
  • void INT1Event_cb();
  • void runningmode();
  • void setup() {
  •   // Led.
  •   pinMode(LED_BUILTIN, OUTPUT);
  •   // Initialize serial for output.
  •   SerialPort.begin(115200);
  •   // Initialize I2C bus.
  •   DEV_I2C.begin();
  •     //Interrupts.
  •   attachInterrupt(A3, INT0Event_cb, RISING);
  •   attachInterrupt(INT_1, INT1Event_cb, RISING);
  •   //1. Using LSM6DSOSensor for Pedometer
  •   AccGyr = new LSM6DSOSensor (&DEV_I2C);
  •   AccGyr->Enable_X();
  •   AccGyr->Enable_G();
  •     AccGyr->Enable_Pedometer();
  •     previous_tick = millis();
  •   //2. Using LIS2DW12Sensor for wakeup detection
  •   Acc2 = new LIS2DW12Sensor (&DEV_I2C);
  •   Acc2->Enable_X();
  •   Acc2->Enable_Wake_Up_Detection();
  •   //3. Using LPS22HHSensor
  •   Press = new LPS22HHSensor(&DEV_I2C);
  •   Press->Enable();
  •   //4. Using STTS751Sensor
  •   Temp = new STTS751Sensor (&DEV_I2C);
  •   Temp->Enable();
  • }
  • void loop() {
  •   if (mems_event)
  •   {
  •     mems_event=0;
  •     LIS2DW12_Event_Status_t status;
  •     Acc2->Get_Event_Status(&status);
  •     if (status.WakeUpStatus)
  •     {
  •       // Output data.
  •       SerialPort.println("Wake up Detected!");
  •       runningmode();
  •     }
  •   }
  • }
  • void runningmode()
  • {
  •   bool idel=1;
  •   while (idel){
  •   if (ped_event)
  •   {
  •     ped_event=0;
  •     LSM6DSO_Event_Status_t status;
  •     AccGyr->Get_X_Event_Status(&status);
  •     if (status.StepStatus)
  •     {
  •       // New step detected, so print the step counter
  •       AccGyr->Get_Step_Count(&step_count);
  •       //snprintf(report, sizeof(report), "Step counter: %d", step_count);
  •       //SerialPort.println(report);
  •     }
  •   }
  •   // Print the step counter in any case every 3000 ms
  •   uint32_t current_tick = millis();
  •   if((current_tick - previous_tick) >= IDLEPERIOD)
  •   {
  •     AccGyr->Get_Step_Count(&step_count);
  •     snprintf(report, sizeof(report), "Step counter: %d", step_count);
  •     SerialPort.println(report);
  •     previous_tick = millis();
  •         // Read pressure and temperature.
  •         float pressure = 0, temperature2 = 0;
  •         Press->GetPressure(&pressure);
  •         //Read temperature
  •         float temperature = 0;
  •         Temp->GetTemperature(&temperature);
  •         SerialPort.print("| Pres[hPa]: ");
  •         SerialPort.print(pressure, 2);
  •         SerialPort.print(" | Temp[C]: ");
  •         SerialPort.print(temperature, 2);
  •         SerialPort.print("\n ");
  •         // Quit the while loop,
  •         idel=0;
  •      }
  •   }
  • }
  • void INT1Event_cb()
  • {
  •   ped_event = 1;
  • }
  • void INT0Event_cb()
  • {
  •   mems_event = 1;
  • }

5、结果演示

5.1 初步显示计步器功能

5.2 综合计步器和环境温度和气压显示功能

显示唤醒后,开始计算运动步数,这里用手的摇动来显示结果,同时显示出环境温度和大气压。


6. 基于Nucleo-L476L的传感器数据读取的几点说明和建议


使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1465

主题

4148

帖子

6

粉丝