arduino学习笔记40 - Arduino Uno + BMA180三轴加速度计演示实验
今天想起了自己手上有了一个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、通过以上的连接后,我们可以进行代码的调试、编译了,在这里我们提供的代码是演示所用的代码,需其他用途,需要自己去写代码!#include <Wire.h>
void setup()
{
Serial.begin(115200);
Wire.begin();
Serial.println("Demo started, initializing sensors");
AccelerometerInit();
//GyroInit();
Serial.println("Sensors have been initialized");
}
void AccelerometerInit()
{
Wire.beginTransmission(0x40); // address of the accelerometer
// reset the accelerometer
Wire.send(0x10);
Wire.send(0xB6);
Wire.endTransmission();
delay(10);
Wire.beginTransmission(0x40); // address of the accelerometer
// low pass filter, range settings
Wire.send(0x0D);
Wire.send(0x10);
Wire.endTransmission();
Wire.beginTransmission(0x40); // address of the accelerometer
Wire.send(0x20); // read from here
Wire.endTransmission();
Wire.requestFrom(0x40, 1);
byte data = Wire.receive();
Wire.beginTransmission(0x40); // address of the accelerometer
Wire.send(0x20);
Wire.send(data & 0x0F); // low pass filter to 10 Hz
Wire.endTransmission();
Wire.beginTransmission(0x40); // address of the accelerometer
Wire.send(0x35); // read from here
Wire.endTransmission();
Wire.requestFrom(0x40, 1);
data = Wire.receive();
Wire.beginTransmission(0x40); // address of the accelerometer
Wire.send(0x35);
Wire.send((data & 0xF1) | 0x04); // range +/- 2g
Wire.endTransmission();
}
void AccelerometerRead()
{
Wire.beginTransmission(0x40); // address of the accelerometer
Wire.send(0x02); // set read pointer to data
Wire.endTransmission();
Wire.requestFrom(0x40, 6);
// read in the 3 axis data, each one is 16 bits
// print the data to terminal
Serial.print("Accelerometer: X = ");
short data = Wire.receive();
data += Wire.receive() << 8;
Serial.print(data);
Serial.print(" , Y = ");
data = Wire.receive();
data += Wire.receive() << 8;
Serial.print(data);
Serial.print(" , Z = ");
data = Wire.receive();
data += Wire.receive() << 8;
Serial.print(data);
Serial.println();
}
/*void GyroInit()
{
Wire.beginTransmission(0x69); // address of the gyro
// reset the gyro
Wire.send(0x3E);
Wire.send(0x80);
Wire.endTransmission();
Wire.beginTransmission(0x69); // address of the gyro
// low pass filter 10 Hz
Wire.send(0x16);
Wire.send(0x1D);
Wire.endTransmission();
Wire.beginTransmission(0x69); // address of the gyro
// use internal oscillator
Wire.send(0x3E);
Wire.send(0x01);
Wire.endTransmission();
}
void GyroRead()
{
Wire.beginTransmission(0x69); // address of the gyro
Wire.send(0x1D); // set read pointer
Wire.endTransmission();
Wire.requestFrom(0x69, 6);
// read in 3 axis of data, 16 bits each, print to terminal
short data = Wire.receive() << 8;
data += Wire.receive();
Serial.print("Gyro: X = ");
Serial.print(data);
Serial.print(" , Y = ");
data = Wire.receive() << 8;
data += Wire.receive();
Serial.print(data);
Serial.print(" , Z = ");
data = Wire.receive() << 8;
data += Wire.receive();
Serial.print(data);
Serial.println();
} */
void loop()
{
AccelerometerRead();
//GyroRead();
delay(500); // slow down output
}
通过串口监视窗口我们可以看到结果如下:
datasheet:
01.#include <Wire.h> Wire.h文件哪里下载? 笨笨虎 发表于 2012-6-6 09:49 static/image/common/back.gif
01.#include Wire.h文件哪里下载?
这文件Arduino IDE里是自带的哦!
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 17:46 static/image/common/back.gif
sketch_jun06a.cpp: In function 'void AccelerometerInit()':
sketch_jun06a:19: er ...
:o你用的IDE是什么版本的啊! Randy 发表于 2012-6-6 18:20 static/image/common/back.gif
你用的IDE是什么版本的啊!
1.0.1 最新的 是不是版本问题 笨笨虎 发表于 2012-6-7 09:04 static/image/common/back.gif
1.0.1 最新的 是不是版本问题
建议你用一下0023版本的试一下! 换了个022 正常了{:soso_e134:} 怎样才能转换成角度呢{:soso_e125:} 本帖最后由 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:13 static/image/common/back.gif
换了个022 正常了
是的,因为在新版本的IDE里和老版本的IDE里的程序后缀名都不一样了,不知你是否发现,老版本的是.pde .新版本的是.ino结尾的哦! pww999 发表于 2012-6-7 09:16 static/image/common/back.gif
怎样才能转换成角度呢
你不用看得那么麻烦,这个BMA180和ADXL345差不多的,转换角度都是先去看一下它的datasheet上的相关灵敏度,还有要注意的是,测BMA180模块是放静止时是否是1g.接着就是你把输出的原始数字除以datasheet相对应的灵敏度就是角度了。如有什么变化,请注意看它的datasheet. pww999 发表于 2012-6-7 09:21 static/image/common/back.gif
http://wenku.baidu.com/view/274629ef998fcc22bcd10d6c.html
多谢{:3_48:} 笨笨虎 发表于 2012-6-7 10:57 static/image/common/back.gif
多谢
请问一下你也在玩这个模块? Randy 发表于 2012-6-7 10:59 static/image/common/back.gif
请问一下你也在玩这个模块?
手里有一些 飞思卡尔的 MMA7660 闲置 看能不能用上