查看: 1681|回复: 0

[评测分享] [ Wio Terminal开发板测评]+3轴加速度传感器检测

[复制链接]
  • TA的每日心情
    奋斗
    2023-5-10 20:09
  • 签到天数: 1742 天

    连续签到: 1 天

    [LV.Master]伴坛终老

    发表于 2021-8-16 00:30:30 | 显示全部楼层 |阅读模式
    分享到:
    在Wio终端,配有3轴加速度传感器,其工作原理图如图1所示。

    1.jpg
    图1 传感器原理图
    在使用该传感器时,需预先下载其支持库的压缩文件Seeed_Arduino_ LIS3DHTR_master.zip,然后在IDE中添加该文件,见图2所示。

    2.jpg
    图2 添加支持库

    检测3轴加速度传感器的程序如下:
    1. #include"LIS3DHTR.h"
    2. LIS3DHTR<TwoWire> lis;
    3. void setup() {
    4. Serial.begin(115200);
    5. lis.begin(Wire1);
    6. if (!lis) {
    7. Serial.println("ERROR");
    8. while(1);
    9. }
    10. lis.setOutputDataRate(LIS3DHTR_DATARATE_25HZ); //Data output rate
    11. lis.setFullScaleRange(LIS3DHTR_RANGE_2G); //Scale range set to 2g
    12. }

    13. void loop() {
    14. float x_values, y_values, z_values;
    15. x_values = lis.getAccelerationX();
    16. y_values = lis.getAccelerationY();
    17. z_values = lis.getAccelerationZ();
    18. Serial.print("X: "); Serial.print(x_values);
    19. Serial.print(" Y: "); Serial.print(y_values);
    20. Serial.print(" Z: "); Serial.print(z_values);
    21. Serial.println();
    22. delay(50);
    23. }
    复制代码

    经编译上传,其结果如图3和图4所示。

    3.jpg
    图3 完成上传

    4.jpg
    图4 检测结果
    此外,在添加“Seeed_Line_Chart”支持库的情况下,还可以在Wio终端来绘制其数据波形图,其程序如下:
    1. #include"LIS3DHTR.h" //include the accelerator library
    2. #include"seeed_line_chart.h" //include the line chart library
    3. TFT_eSPI tft;
    4. LIS3DHTR<TwoWire>  lis;
    5. #define max_size 50 //maximum size of data
    6. doubles accelerator_readings[3];
    7. TFT_eSprite spr = TFT_eSprite(&tft);  // Sprite
    8. void setup() {
    9. tft.begin();
    10. tft.setRotation(3);
    11. spr.createSprite(TFT_HEIGHT,TFT_WIDTH);
    12. lis.begin(Wire1);
    13. lis.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
    14. lis.setFullScaleRange(LIS3DHTR_RANGE_2G);
    15. Serial.begin(115200);
    16. }

    17. void loop() {
    18. spr.fillSprite(TFT_WHITE);
    19. float x_raw = lis.getAccelerationX();
    20. float y_raw = lis.getAccelerationY();
    21. float z_raw = lis.getAccelerationZ();
    22. Serial.print(x_raw);
    23. Serial.print(",");
    24. Serial.print(y_raw);
    25. Serial.print(",");
    26. Serial.println(z_raw);
    27. if (accelerator_readings[0].size() == max_size) {
    28. for (uint8_t i = 0; i<3; i++){
    29. accelerator_readings[i].pop(); //this is used to remove the first read variable
    30. }
    31. }
    32. accelerator_readings[0].push(x_raw); //read variables and store in data
    33. accelerator_readings[1].push(y_raw);
    34. accelerator_readings[2].push(z_raw);
    35. auto header =  text(0, 0)
    36. .value("Accelerator Readings")
    37. .align(center)
    38. .valign(vcenter)
    39. .width(tft.width())
    40. .thickness(2);
    41. header.height(header.font_height() * 2);
    42. header.draw();
    43. auto content = line_chart(20, header.height());
    44.                 .height(tft.height() - header.height() * 1.5)
    45.                 .width(tft.width() - content.x() * 2)
    46. .based_on(-2.0)
    47. .show_circle(false)
    48. .value({accelerator_readings[0],accelerator_readings[1], accelerator_readings[2]})
    49.                 .color(TFT_BLUE, TFT_RED, TFT_GREEN)
    50. .draw();
    51. spr.pushSprite(0, 0);
    52. delay(50);
    53. }
    复制代码

    程序上传及检测效果如图5和图6所示。
    比较有意思的是,我们是否可以用3轴加速度传感器来检测地震呢?那波形曲线可是十分明显的!
    此外,用3轴加速度传感器还可进行智能识别处理,以确定物体的倾斜及旋转等。

    5.jpg
    图5 程序及上传

    6.jpg
    图6 运动波形图

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-5-2 05:33 , Processed in 0.116799 second(s), 17 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.