极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 92461|回复: 56

arduino学习笔记40 - Arduino Uno + BMA180三轴加速度计演示实验

[复制链接]
发表于 2012-6-5 15:30:22 | 显示全部楼层 |阅读模式
今天想起了自己手上有了一个BMA180加速度传感器模块,论坛里之前弘毅已经写过ADXL345的模块使用方法,由于这些姿态方面的模块现在市面上已经不算少的了,比如ITG3200、ADXL345、ADXL335、HMC5883L、MPU6050、BMP085、MMA7361等等好多的这种芯片,这些芯片目前发现用的比较多的领域,应该是飞控方面的了,而我发现基于Arduino 的四轴方面的飞控在国内没多少,我也想多学习学习前辈的经验,可是见没多少资源,再次希望大家懂玩的朋友一起弄弄飞控的相关传感器的运用是不错的哦!接下来我写一下我在学习Bma180的一些学习笔记,如有什么错误请指出,谢谢!

1、概述
博世BMA180三轴超高性能数字加速度计,它提供了14位数字输出通过一个4线SPI或2线I 2 C接口。满量程的测量范围可设定为±1g平衡,1.5G,2G,3G,4G,8G或16G。其他功能还包括可编程唤醒,低g和高g检测,自来水检测,边坡检测,自检能力。该传感器还具有两种工作模式:低噪音,低功耗 BMA180采用3x3mm 12引脚LGA封装在一个微小的。该传感器可在1.62至3.6V之间的VDD和1.2至3.6V的VDDIO的供电,将通常只消耗650uA的标准模式。

2、一分场板是BMA180 这里。
各种各样的测算范围(±1g平衡,1.5G,2G,3G,4G,8G和16G)
14 - 位或12位ADC转换
2个可选的I 2 C地址
集成可编程数字滤波器(没有必要的外部元件)
8个低通滤波器
1高通滤波器
1带通滤波器
可编程中断功能:
唤醒
低g检测
高g检测
点击传感
边坡检测
2个主要的标准模式:低噪声和低功耗

睡眠模式
唤醒模式
自检能力

3、应用:
BMA180 是一款超高性能三轴数字加速度传感器, 主要是针对低能消费市场的应用。
BMA180具有高测量精度的3个互相垂直的轴的加速度传感器,因此在Sen-Ses倾斜、运动、 冲击和振动在手机、掌上电脑、电脑周边、人机交换-面孔、虚拟现实的特性和游戏控制 器都有相应的应用.

想知道更详细的资料,可以查询此芯片的datasheet哦。

4、BMA180的芯片引脚图

5、BMA180与ADXL345相比较:

6、本实验我们所用到的主控板还是Arduino Uno ,下面我们来看一下与BMA180连接时的连线图:


7、通过以上的连接后,我们可以进行代码的调试、编译了,在这里我们提供的代码是演示所用的代码,需其他用途,需要自己去写代码!
  1. #include <Wire.h>

  2. void setup()
  3. {
  4.   Serial.begin(115200);
  5.   Wire.begin();
  6.    
  7.   Serial.println("Demo started, initializing sensors");
  8.    
  9.   AccelerometerInit();
  10. //  GyroInit();
  11.    
  12.   Serial.println("Sensors have been initialized");
  13. }

  14. void AccelerometerInit()
  15. {
  16.   Wire.beginTransmission(0x40); // address of the accelerometer
  17.   // reset the accelerometer
  18.   Wire.send(0x10);
  19.   Wire.send(0xB6);
  20.   Wire.endTransmission();
  21.   delay(10);
  22.    
  23.   Wire.beginTransmission(0x40); // address of the accelerometer
  24.   // low pass filter, range settings
  25.   Wire.send(0x0D);
  26.   Wire.send(0x10);
  27.   Wire.endTransmission();
  28.    
  29.   Wire.beginTransmission(0x40); // address of the accelerometer
  30.   Wire.send(0x20); // read from here
  31.   Wire.endTransmission();
  32.   Wire.requestFrom(0x40, 1);
  33.   byte data = Wire.receive();
  34.   Wire.beginTransmission(0x40); // address of the accelerometer
  35.   Wire.send(0x20);
  36.   Wire.send(data & 0x0F); // low pass filter to 10 Hz
  37.   Wire.endTransmission();
  38.    
  39.   Wire.beginTransmission(0x40); // address of the accelerometer
  40.   Wire.send(0x35); // read from here
  41.   Wire.endTransmission();
  42.   Wire.requestFrom(0x40, 1);
  43.   data = Wire.receive();
  44.   Wire.beginTransmission(0x40); // address of the accelerometer
  45.   Wire.send(0x35);
  46.   Wire.send((data & 0xF1) | 0x04); // range +/- 2g
  47.   Wire.endTransmission();
  48. }

  49. void AccelerometerRead()
  50. {
  51.   Wire.beginTransmission(0x40); // address of the accelerometer
  52.   Wire.send(0x02); // set read pointer to data
  53.   Wire.endTransmission();
  54.   Wire.requestFrom(0x40, 6);
  55.    
  56.   // read in the 3 axis data, each one is 16 bits
  57.   // print the data to terminal
  58.   Serial.print("Accelerometer: X = ");
  59.   short data = Wire.receive();
  60.   data += Wire.receive() << 8;
  61.   Serial.print(data);
  62.   Serial.print(" , Y = ");
  63.   data = Wire.receive();
  64.   data += Wire.receive() << 8;
  65.   Serial.print(data);
  66.   Serial.print(" , Z = ");
  67.   data = Wire.receive();
  68.   data += Wire.receive() << 8;
  69.   Serial.print(data);
  70.   Serial.println();
  71. }

  72. /*void GyroInit()
  73. {
  74.   Wire.beginTransmission(0x69); // address of the gyro
  75.   // reset the gyro
  76.   Wire.send(0x3E);
  77.   Wire.send(0x80);
  78.   Wire.endTransmission();
  79.    
  80.   Wire.beginTransmission(0x69); // address of the gyro
  81.   // low pass filter 10 Hz
  82.   Wire.send(0x16);
  83.   Wire.send(0x1D);
  84.   Wire.endTransmission();
  85.    
  86.   Wire.beginTransmission(0x69); // address of the gyro
  87.   // use internal oscillator
  88.   Wire.send(0x3E);
  89.   Wire.send(0x01);
  90.   Wire.endTransmission();
  91. }

  92. void GyroRead()
  93. {
  94.   Wire.beginTransmission(0x69); // address of the gyro
  95.   Wire.send(0x1D); // set read pointer
  96.   Wire.endTransmission();
  97.    
  98.   Wire.requestFrom(0x69, 6);
  99.    
  100.   // read in 3 axis of data, 16 bits each, print to terminal
  101.   short data = Wire.receive() << 8;
  102.   data += Wire.receive();
  103.   Serial.print("Gyro: X = ");
  104.   Serial.print(data);
  105.   Serial.print(" , Y = ");
  106.   data = Wire.receive() << 8;
  107.   data += Wire.receive();
  108.   Serial.print(data);
  109.   Serial.print(" , Z = ");
  110.   data = Wire.receive() << 8;
  111.   data += Wire.receive();
  112.   Serial.print(data);
  113.   Serial.println();
  114. } */

  115. void loop()
  116. {
  117.   AccelerometerRead();
  118. //  GyroRead();
  119.    
  120.   delay(500); // slow down output   
  121. }
复制代码
通过串口监视窗口我们可以看到结果如下:


datasheet:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2012-6-6 09:49:46 | 显示全部楼层
01.#include <Wire.h>     Wire.h文件哪里下载?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-6-6 09:59:00 | 显示全部楼层
笨笨虎 发表于 2012-6-6 09:49
01.#include      Wire.h文件哪里下载?

这文件Arduino IDE里是自带的哦!
回复 支持 反对

使用道具 举报

发表于 2012-6-6 17:46:41 | 显示全部楼层










sketch_jun06a.cpp: In function 'void AccelerometerInit()':
sketch_jun06a:19: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a:20: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a:26: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a:27: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a:31: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a:34: error: 'class TwoWire' has no member named 'receive'

As of Arduino 1.0, the Wire.receive() function was renamed to Wire.read() for consistency with other libraries.

sketch_jun06a:36: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a:37: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a:41: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a:44: error: 'class TwoWire' has no member named 'receive'

As of Arduino 1.0, the Wire.receive() function was renamed to Wire.read() for consistency with other libraries.

sketch_jun06a:46: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a:47: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a.cpp: In function 'void AccelerometerRead()':
sketch_jun06a:54: error: 'class TwoWire' has no member named 'send'

As of Arduino 1.0, the Wire.send() function was renamed to Wire.write() for consistency with other libraries.

sketch_jun06a:61: error: 'class TwoWire' has no member named 'receive'

As of Arduino 1.0, the Wire.receive() function was renamed to Wire.read() for consistency with other libraries.

sketch_jun06a:62: error: 'class TwoWire' has no member named 'receive'

As of Arduino 1.0, the Wire.receive() function was renamed to Wire.read() for consistency with other libraries.

sketch_jun06a:65: error: 'class TwoWire' has no member named 'receive'

As of Arduino 1.0, the Wire.receive() function was renamed to Wire.read() for consistency with other libraries.

sketch_jun06a:66: error: 'class TwoWire' has no member named 'receive'

As of Arduino 1.0, the Wire.receive() function was renamed to Wire.read() for consistency with other libraries.

sketch_jun06a:69: error: 'class TwoWire' has no member named 'receive'

As of Arduino 1.0, the Wire.receive() function was renamed to Wire.read() for consistency with other libraries.

sketch_jun06a:70: error: 'class TwoWire' has no member named 'receive'

As of Arduino 1.0, the Wire.receive() function was renamed to Wire.read() for consistency with other libraries.


编译通不过
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-6-6 18:20:49 | 显示全部楼层
笨笨虎 发表于 2012-6-6 17:46
sketch_jun06a.cpp: In function 'void AccelerometerInit()':
sketch_jun06a:19: er ...

  你用的IDE是什么版本的啊!
回复 支持 反对

使用道具 举报

发表于 2012-6-7 09:04:44 | 显示全部楼层
Randy 发表于 2012-6-6 18:20
你用的IDE是什么版本的啊!

1.0.1 最新的 是不是版本问题
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-6-7 09:10:48 | 显示全部楼层
笨笨虎 发表于 2012-6-7 09:04
1.0.1 最新的 是不是版本问题

建议你用一下0023版本的试一下!
回复 支持 反对

使用道具 举报

发表于 2012-6-7 09:13:59 | 显示全部楼层
换了个022 正常了{:soso_e134:}
回复 支持 反对

使用道具 举报

发表于 2012-6-7 09:16:19 | 显示全部楼层
怎样才能转换成角度呢{:soso_e125:}
回复 支持 反对

使用道具 举报

发表于 2012-6-7 09:21:34 | 显示全部楼层
本帖最后由 pww999 于 2012-6-7 09:46 编辑

http://wenku.baidu.com/view/274629ef998fcc22bcd10d6c.html


另外  4楼 将所有 Wire.send  改成Wire.write,      Wire.receive 改成Wire.read         ,    1.01版都可以用了~
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-6-7 09:43:04 | 显示全部楼层
笨笨虎 发表于 2012-6-7 09:13
换了个022 正常了

是的,因为在新版本的IDE里和老版本的IDE里的程序后缀名都不一样了,不知你是否发现,老版本的是.pde    .新版本的是.ino结尾的哦!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-6-7 10:08:37 | 显示全部楼层
pww999 发表于 2012-6-7 09:16
怎样才能转换成角度呢

你不用看得那么麻烦,这个BMA180和ADXL345差不多的,转换角度都是先去看一下它的datasheet上的相关灵敏度,还有要注意的是,测BMA180模块是放静止时是否是1g.接着就是你把输出的原始数字除以datasheet相对应的灵敏度就是角度了。如有什么变化,请注意看它的datasheet.
回复 支持 反对

使用道具 举报

发表于 2012-6-7 10:57:32 | 显示全部楼层
pww999 发表于 2012-6-7 09:21
http://wenku.baidu.com/view/274629ef998fcc22bcd10d6c.html

多谢{:3_48:}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-6-7 10:59:00 | 显示全部楼层
笨笨虎 发表于 2012-6-7 10:57
多谢

请问一下你也在玩这个模块?
回复 支持 反对

使用道具 举报

发表于 2012-6-7 11:01:56 | 显示全部楼层
Randy 发表于 2012-6-7 10:59
请问一下你也在玩这个模块?

手里有一些 飞思卡尔的 MMA7660 闲置 看能不能用上
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-19 11:22 , Processed in 0.047212 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表