Difference between revisions of "Matrix - 3-Axis Digital Accelerometer"

From FriendlyELEC WiKi
Jump to: navigation, search
(代码展示)
Line 1: Line 1:
 
[[Matrix - 3-Axis Digital Accelerometer/zh|查看中文]]
 
[[Matrix - 3-Axis Digital Accelerometer/zh|查看中文]]
  
==介绍==
+
==Introduction==
 
[[File:3AD.png|thumb|3-Axis Digital Accelerometer]]
 
[[File:3AD.png|thumb|3-Axis Digital Accelerometer]]
* 模块Matrix-3_Axis_Digital_Accelerometer用于测量x\y\z方向上的加速度,进而计算速度。
+
* This module measures the static acceleration of gravity in three axis x, y and z resulting from motion or shock.
* 搭载了一颗ADXL345芯片,可以使用IIC或SPI进行通信。
+
* Its digital interface is IIC or SPI.
* 13-bit精度,采集范围可以是+-2g,+-4g,+-8g和+-16g,既能测定动态加速度,也能测定静态加速度。
+
* It is integrated with an ADXL345 chip with high resolution (13-bit) measurement at ±2g, ±4g, ±8g and ±16g.
* 采用5V供电,PCB上的电源转换芯片输出3.3V给ADXL345。
+
* The module is powered by 5V and converts 5V to 3.3V to ADXL345.
 +
 
 +
 
  
 
==特性==
 
==特性==

Revision as of 07:52, 10 September 2015

查看中文

1 Introduction

3-Axis Digital Accelerometer
  • This module measures the static acceleration of gravity in three axis x, y and z resulting from motion or shock.
  • Its digital interface is IIC or SPI.
  • It is integrated with an ADXL345 chip with high resolution (13-bit) measurement at ±2g, ±4g, ±8g and ±16g.
  • The module is powered by 5V and converts 5V to 3.3V to ADXL345.


2 特性

  • I2C接口,3.3V
  • 13-bit,up to +-16g
  • 2.54mm排针接口,接线方便,通用性强
  • +-16g,13-bit精度
  • PCB尺寸(mm):16x32

重力加速度PCB

  • 引脚说明:
名称 描述
INT2 中断引脚
INT1 中断引脚
CS 使能引脚
SCL I2C SCL
SDA I2C SDA
SDO 设置slave address
5V 电源5V
GND

3 工作原理

  • ADXL345 是一款小巧纤薄的低功耗三轴加速度计,可以对高达±16 g的加速度进行高分辨率(13 位)测量。数字输出数据为 16 位二进制补码格式,可通过SPI (3 线或 4 线)或者I2C数字接口访问。
  • ADXL345 非常适合移动设备应用。它可以在倾斜检测应用中测量静态重力加速度,还可以测量运动或冲击导致的动态加速度。它具有高分辨率(4 mg/LSB),能够测量约 0.25°的倾角变化。
  • 由于这里使用的是I2C通信方式,所以只简单的介绍I2C的工作原理,具体时序的实现可自行去查看芯片手册。ADXL345遵循UM1024 I2C-总线规格,它支持标准的数据传输模式(100KHz),并且支持快速传输模式(400KHz),采用I2C模式,需要把CS引脚上拉,I2C引脚无连接时,默认模式不存在。
  • 这里采用I2C通信,接线方式如下图:

三轴重力加速度

4 下载Matrix源码

Matrix配件相关的代码是完全开源的,统一由一个仓库进行管理:git://github.com/friendlyarm/matrix.git
该仓库里不同的分支代表着Matrix配件所支持的不同开发板。

  • matrix-nanopi分支包含了Matrix对NanoPi的支持;
  • matrix-tiny4412分支包含了Matrix对Tiny4412的支持;
  • matrix-raspberrypi分支包含了Matrix对RaspberryPi的支持;

在主机PC上安装git,以Ubuntu14.04为例

$ sudo apt-get install git

克隆Matrix配件代码仓库

$ git clone git://github.com/friendlyarm/matrix.git

克隆完成后会得到一个matrix目录,里面存放着所有Matrix配件的代码。

5 与NanoPi连接使用

5.1 准备工作

在NanoPi上运行Debian系统,然后在主机PC上安装并使用相应的编译器。参考wiki:NanoPi

5.2 硬件连接

参考下图连接模块Matrix-3_Axis_Digital_Accelerometer和NanoPi
matrix-3_axis_digital_accelerometer_nanopi

连接说明:

Matrix-3_Axis_Digital_Accelerometer NanoPi
INT2 留空
INT1 留空
CS Pin1
SCL Pin5
SDA Pin3
SDO Pin2
5V Pin4
GND Pin6

5.3 编译测试程序

进入Matrix代码仓库,切换到matrix-nanopi分支

$ cd matrix
$ git checkout matrix-nanopi

编译Matrix配件代码

$ make CROSS_COMPILE=arm-linux- clean
$ make CROSS_COMPILE=arm-linux-
$ make CROSS_COMPILE=arm-linux- install

注意:请确保你的主机PC当前使用的交叉编译器为NanoPi-Debian配套的arm-linux-gcc-4.4.3。
编译出来的库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-3_Axis_Digital_Accelerometer对应的测试程序为matrix-3_axis_digital_accelerometer。

5.4 运行测试程序

拷贝库文件和测试程序到NanoPi的文件系统上

$ cp install/usr/bin/* nanopi_rootfs/usr/bin/
$ cp install/lib/* nanopi_rootfs/lib/ -d

然后启动NanoPi,在Debian的shell终端中执行如下命令运行模块Matrix-3_Axis_Digital_Accelerometer的测试程序
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。

$ matrix-3_axis_digital_accelerometer

5.5 代码展示

int main(int argc, char ** argv) 
{
    char position[BUF_SIZE];
    memset(position, 0, BUF_SIZE);
 
    if (adxl34xRead(position) > 0) {
        printf("Get position: %s", position);
    } else {
        printf("Fail to get position\n");        
    }
    return 0;
}

6 与Tiny4412连接使用

6.1 准备工作

参考Tiny4412光盘里的《友善之臂Ubuntu使用手册》,在Tiny4412上运行UbuntuCore系统,然后在主机PC上安装并使用相应的编译器。
注意:只能使用Tiny4412SDK-1506的底板。

6.2 硬件连接

参考下图连接模块Matrix-3_Axis_Digital_Accelerometer和Tiny4412
matrix-3_axis_digital_accelerometer_tiny4412

连接说明:

Matrix-3_Axis_Digital_Accelerometer Tiny4412
INT2 留空
INT1 留空
CS CON16 5V
SCL CON18 SCL
SDA CON18 SDA
SDO CON14 5V
5V CON18 5V
GND CON18 GND

6.3 编译测试程序

进入Matrix代码仓库,切换到matrix-tiny4412分支

$ cd matrix
$ git checkout matrix-tiny4412

编译Matrix配件代码

$ make CROSS_COMPILE=arm-linux-gnueabihf- clean
$ make CROSS_COMPILE=arm-linux-gnueabihf-
$ make CROSS_COMPILE=arm-linux-gnueabihf- install

注意:请确保你的主机PC当前使用的交叉编译器为Tiny4412-UbuntuCore配套的arm-linux-gnueabihf-gcc-4.7.3。
编译出来的库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-3_Axis_Digital_Accelerometer对应的测试程序为matrix-3_axis_digital_accelerometer。

6.4 运行测试程序

拷贝库文件和测试程序到Tiny4412的UbuntuCore的文件系统上

$ cp install/usr/bin/* tiny4412_rootfs/usr/bin/
$ cp install/lib/* tiny4412_rootfs/lib/ -d

然后启动Tiny4412,在UbuntuCore的shell终端中执行如下命令运行模块Matrix-3_Axis_Digital_Accelerometer的测试程序
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。

$ matrix-3_axis_digital_accelerometer

6.5 代码展示

int main(int argc, char ** argv) 
{
    char position[BUF_SIZE];
    memset(position, 0, BUF_SIZE);
 
    if (adxl34xRead(position) > 0) {
        printf("Get position: %s", position);
    } else {
        printf("Fail to get position\n");        
    }
    return 0;
}

7 与RaspberryPi连接使用

8 与Arduino连接使用

9 相关资料

ADXL345.pdf