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

From FriendlyELEC WiKi
Jump to: navigation, search
(Connect to Tiny4412)
Line 168: Line 168:
 
|}
 
|}
  
===编译测试程序===
+
===Compile Test Program===
进入Matrix代码仓库,切换到matrix-tiny4412分支
+
Please login the Matrix git and enter the matrix-tiny4412 branch
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
Line 175: Line 175:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
编译Matrix配件代码
+
Compile the Matrix code
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ make CROSS_COMPILE=arm-linux-gnueabihf- clean
 
$ make CROSS_COMPILE=arm-linux-gnueabihf- clean
Line 181: Line 181:
 
$ make CROSS_COMPILE=arm-linux-gnueabihf- install
 
$ make CROSS_COMPILE=arm-linux-gnueabihf- install
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:请确保你的主机PC当前使用的交叉编译器为Tiny4412-UbuntuCore配套的arm-linux-gnueabihf-gcc-4.7.3。<br>
+
Note: please make sure to install the cross compiler "arm-linux-gnueabihf-gcc-4.7.3" on your PC, which is used to compile files for the Tiny4412-UbuntuCore.<br>
编译出来的库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-3_Axis_Digital_Accelerometer对应的测试程序为matrix-3_axis_digital_accelerometer。
+
Generated library files are under the "install/lib" directory. Applications are under the "install/usr/bin" directory. The test program for the "Matrix-3_Axis_Digital_Accelerometer" module is "matrix-3_axis_digital_accelerometer".<br>
  
===运行测试程序===
+
===Run Test Program===
拷贝库文件和测试程序到Tiny4412的UbuntuCore的文件系统上
+
Please copy the library files and test program to the Tiny4412
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cp install/usr/bin/* tiny4412_rootfs/usr/bin/
 
$ cp install/usr/bin/* tiny4412_rootfs/usr/bin/
Line 191: Line 191:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
然后启动Tiny4412,在UbuntuCore的shell终端中执行如下命令运行模块Matrix-3_Axis_Digital_Accelerometer的测试程序 <br>
+
Power on the Tiny4412 and run the following command in UbuntuCore's terminal<br>
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。
+
Note: this module is not plug and play therefore before running the module please make sure it is connected to a Tiny4412.
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ matrix-3_axis_digital_accelerometer
 
$ matrix-3_axis_digital_accelerometer
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===代码展示===
+
===Code Sample===
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
 
int main(int argc, char ** argv)  
 
int main(int argc, char ** argv)  
Line 214: Line 214:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==与RaspberryPi连接使用==
+
==Connect to RaspberryPi==
  
==与Arduino连接使用==
+
==Connect to Arduino==
  
==相关资料==
+
==Resources==
 
[http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf ADXL345.pdf]
 
[http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf ADXL345.pdf]
  

Revision as of 06:20, 16 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 Features

  • I2C, 3.3V
  • 13-bit, up to +-16g
  • 2.54mm spacing pin interface
  • PCB dimension(mm): 16 x 32

重力加速度PCB

  • Pin Spec:
Pin Comment
INT2 Interrupt
INT1 Interrupt
CS Enable
SCL I2C SCL
SDA I2C SDA
SDO Set Slave Address
5V Power 5V
GND Ground

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 Download Matrix Source Code

Matrix family members' code samples are open source which are maintained at: git://github.com/friendlyarm/matrix.git
In this warehouse each branch represents an ARM board that this matrix member can work with

  • matrix-nanopi includes code samples for Matrix members that can work with the NanoPi;
  • matrix-tiny4412 includes code samples for Matrix members that can work with the Tiny4412;
  • matrix-raspberrypi includes code samples for Matrix members that can work with the RaspberryPi;

Here are the steps for installing git on a PC running Ubuntu14.04

$ sudo apt-get install git

Clone Matrix code warehouse

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

If this is a success a matrix directory will be generated, which will contain all available Matrix code samples.

5 Connect to NanoPi

5.1 Preparations

You need to install a Debian on the NanoPi and have a PC which has an appropriate cross compiler ready. For details you can refer to wiki:NanoPi

5.2 Hardware Connection

Please refer to the following diagrams to connect "Matrix-3_Axis_Digital_Accelerometer" to the NanoPi
matrix-3_axis_digital_accelerometer_nanopi

Connection Details:

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

5.3 Compile Test Program

Please login the Matrix git and enter the matrix-nanopi branch

$ cd matrix
$ git checkout matrix-nanopi

Compile the Matrix code

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

Note: please make sure to install the cross compiler "arm-linux-gcc-4.4.3" on your PC, which is used to compile files for the NanoPi-Debian.
Generated library files are under the "install/lib" directory. Applications are under the "install/usr/bin" directory. The test program for the "Matrix-3_Axis_Digital_Accelerometer" module is "matrix-3_axis_digital_accelerometer".

5.4 Run Test Program

Please copy the library files and test program to the NanoPi

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

Power on the NanoPi and run the following command in Debian's terminal
Note: this module is not plug and play therefore before running the module please make sure it is connected to a NanoPi.

$ matrix-3_axis_digital_accelerometer

5.5 Code Sample

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 Connect to Tiny4412

6.1 Preparations

Please refer to the Tiny4412's user's manual to install a UbuntuCore on the Tiny4412 and install an appropriate cross compiler on a PC.
Note: only the Tiny4412SDK-1506 carrier board can work with this module.

6.2 Hardware Connection

Please refer to the following diagrams to connect the Matrix-3_Axis_Digital_Accelerometer to the Tiny4412
matrix-3_axis_digital_accelerometer_tiny4412

Connection Details:

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

6.3 Compile Test Program

Please login the Matrix git and enter the matrix-tiny4412 branch

$ cd matrix
$ git checkout matrix-tiny4412

Compile the Matrix code

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

Note: please make sure to install the cross compiler "arm-linux-gnueabihf-gcc-4.7.3" on your PC, which is used to compile files for the Tiny4412-UbuntuCore.
Generated library files are under the "install/lib" directory. Applications are under the "install/usr/bin" directory. The test program for the "Matrix-3_Axis_Digital_Accelerometer" module is "matrix-3_axis_digital_accelerometer".

6.4 Run Test Program

Please copy the library files and test program to the Tiny4412

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

Power on the Tiny4412 and run the following command in UbuntuCore's terminal
Note: this module is not plug and play therefore before running the module please make sure it is connected to a Tiny4412.

$ matrix-3_axis_digital_accelerometer

6.5 Code Sample

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 Connect to RaspberryPi

8 Connect to Arduino

9 Resources

ADXL345.pdf