2455|0

428

帖子

4

TA的资源

纯净的硅(初级)

楼主
 

3、基于Nucleo-L476L的健康运动助手项目开发 [复制链接]

 
本帖最后由 北方 于 2019-7-17 16:57 编辑

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

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

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

 

2、采用的硬件

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

  1. LSM6DSO 用于计步器计数,
  2. LIS2DW12 用于从休眠中唤醒,进入传感器读取和计步器计数
  3. LPS22HH   用于读取大气压数据
  4. 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的传感器数据读取的几点说明和建议

演示视频:

VID_20190717_164203.mp4 (11.66 MB, 下载次数: 1)




此内容由EEWORLD论坛网友北方原创,如需转载或用于商业用途需征得作者同意并注明出处

查看本帖全部内容,请登录或者注册

15.PNG (24.78 KB, 下载次数: 0)

15.PNG

16.PNG (30.09 KB, 下载次数: 0)

16.PNG
点赞 关注(1)
 
 

回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
艾睿电子& Silicon Labs 有奖直播 | 全新蓝牙信道探测:从技术创新到实际应用
直播时间:3月12日(周三)上午10:00
直播奖励:多功能榨汁机、蓝牙音箱、手机支架

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表