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

From FriendlyELEC WiKi
Jump to: navigation, search
(Applications)
 
(54 intermediate revisions by 3 users not shown)
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.
  
==特性==
+
==Features==
* I2C接口,3.3V
+
* I2C, 3.3V
* 13-bit,up to +-16g
+
* 13-bit, up to +-16g
* 2.54mm排针接口,接线方便,通用性强
+
* 2.54mm spacing pin interface
* +-16g,13-bit精度
+
* PCB dimension(mm): 16 x 32
* PCB尺寸(mm):16x32
+
 
[[File:adxpcb.png|frameless|400px|重力加速度PCB]]
 
[[File:adxpcb.png|frameless|400px|重力加速度PCB]]
  
* 引脚说明:<br>
+
* Pin Description: <br>
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
|名称 || 描述        
+
|Pin || Description        
 
|-
 
|-
|INT2    || 中断引脚
+
|INT2    || Interrupt
 
|-
 
|-
|INT1    || 中断引脚
+
|INT1    || Interrupt
 
|-  
 
|-  
|CS      || 使能引脚
+
|CS      || Enable
 
|-
 
|-
 
|SCL    || I2C SCL
 
|SCL    || I2C SCL
Line 31: Line 30:
 
|SDA    || I2C SDA
 
|SDA    || I2C SDA
 
|-
 
|-
|SDO    || 设置slave address
+
|SDO    || Set Slave Address
 
|-
 
|-
|5V        || 电源5V
+
|5V        || Supply Voltage 5V
 
|-
 
|-
|GND    ||
+
|GND    || Ground
 
|}
 
|}
  
==工作原理==
+
==Basic Device Operation==
* ADXL345 是一款小巧纤薄的低功耗三轴加速度计,可以对高达±16 g的加速度进行高分辨率(13 位)测量。数字输出数据为 16 位二进制补码格式,可通过SPI (3 线或 4 线)或者I2C数字接口访问。
+
* The ADXL345 is a small, thin, ultralow power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16 g. Digital output data is formatted as 16-bit twos complement and is acces-sible through either a SPI (3- or 4-wire) or I2C digital interface.
* ADXL345 非常适合移动设备应用。它可以在倾斜检测应用中测量静态重力加速度,还可以测量运动或冲击导致的动态加速度。它具有高分辨率(4 mg/LSB),能够测量约 0.25°的倾角变化。
+
* The ADXL345 is well suited for mobile device applications. It measures the static acceleration of gravity in tilt-sensing appli-cations, as well as dynamic acceleration resulting from motion or shock. Its high resolution (3.9 mg/LSB) enables measurement of inclination changes less than 1.0°.
* 由于这里使用的是I2C通信方式,所以只简单的介绍I2C的工作原理,具体时序的实现可自行去查看芯片手册。ADXL345遵循UM1024 I2C-总线规格,它支持标准的数据传输模式(100KHz),并且支持快速传输模式(400KHz),采用I2C模式,需要把CS引脚上拉,I2C引脚无连接时,默认模式不存在。
+
* The ADXL345 conforms to the UM1024 I2C Specification. It supports standard (100 kHz) and fast (400 kHz) data transfer modes. If the CS is tied high it will be in the I2C mode. If the CS or ALT ADDRESS pin is floating or unconnected the state will be unknown.
* 这里采用I2C通信,接线方式如下图:
+
* The module's I2C connection diagram is as follows:
 
[[File:三轴重力.png|frameless|400px|三轴重力加速度]]
 
[[File:三轴重力.png|frameless|400px|三轴重力加速度]]
  
==下载Matrix源码==
+
<!---
Matrix配件相关的代码是完全开源的,统一由一个仓库进行管理:git://github.com/friendlyarm/matrix.git <br>
+
==Download Matrix Source Code==
该仓库里不同的分支代表着Matrix配件所支持的不同开发板。<br>
+
All the matrix modules' code samples are open source. They are maintained on GitHub - https://github.com/friendlyarm/matrix.git <br>
*matrix-nanopi分支包含了Matrix对NanoPi的支持;
+
Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with.<br>
*matrix-tiny4412分支包含了Matrix对Tiny4412的支持;
+
* The matrix-nanopi branch contains the matrix modules' code samples for the NanoPi
*matrix-raspberrypi分支包含了Matrix对RaspberryPi的支持;
+
* The matrix-nanopi2 branch contains the matrix modules' code samples for the NanoPi 2
 +
* The matrix-tiny4412 branch contains the matrix modules' code samples for the Tiny4412;
 +
* The matrix-raspberrypi branch contains the matrix modules' code samples for the RaspberryPi;
  
在主机PC上安装git,以Ubuntu14.04为例
+
Please follow the steps below to get the source code:<br>
 +
Install the git utility on a PC running Ubuntu14.04
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ sudo apt-get install git
 
$ sudo apt-get install git
 
</syntaxhighlight>
 
</syntaxhighlight>
  
克隆Matrix配件代码仓库
+
Clone the matrix code from GitHub
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
$ git clone git://github.com/friendlyarm/matrix.git
+
$ git clone https://github.com/friendlyarm/matrix.git
 
</syntaxhighlight>
 
</syntaxhighlight>
克隆完成后会得到一个matrix目录,里面存放着所有Matrix配件的代码。
+
If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' code samples.
 +
--->
  
==与NanoPi连接使用==
+
==Applications==
===准备工作===
+
===Connect to NanoPi M1===
在NanoPi上运行Debian系统,然后在主机PC上安装并使用相应的编译器。参考wiki:[[NanoPi/zh|NanoPi]]
+
Refer to the following connection diagram to connect the module to the NanoPi M1:<br>
 +
[[File:Matrix-3_Axis_Digital_Accelerometer_nanopi_m1.jpg|frameless|600px|Matrix-3_Axis_Digital_Accelerometer_nanopi_m1]]
  
===硬件连接===
+
Connection Details:
参考下图连接模块Matrix-3_Axis_Digital_Accelerometer和NanoPi <br>
+
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Accelerometer || NanoPi M1     
 +
|-
 +
|INT2    || NC
 +
|-
 +
|INT1    || NC
 +
|-
 +
|CS      || Pin2
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|SDA    || Pin3
 +
|-
 +
|SDO    || High, it is connected to the GPIO pin-header's 3.3V
 +
|-
 +
|5V      || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
 +
 
 +
===Connect to NanoPi 2===
 +
Refer to the following connection diagram to connect the module to the NanoPi 2:<br>
 +
[[File:Matrix-3_Axis_Digital_Accelerometer_nanopi_2.jpg|frameless|600px|Matrix-3_Axis_Digital_Accelerometer_nanopi_2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Accelerometer || NanoPi 2     
 +
|-
 +
|INT2    || NC
 +
|-
 +
|INT1    || NC
 +
|-
 +
|CS      || Pin2
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|SDA    || Pin3
 +
|-
 +
|SDO    || High, it is connected to the GPIO pin-header's 3.3V
 +
|-
 +
|5V      || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
 +
 
 +
===Connect to NanoPi M2 / NanoPi 2 Fire===
 +
Refer to the following connection diagram to connect the module to the NanoPi M2/ NanoPi 2 Fire:<br>
 +
[[File:Matrix-3_Axis_Digital_Accelerometer_nanopi_M2.jpg|frameless|600px|Matrix-3_Axis_Digital_Accelerometer_nanopi_M2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Accelerometer || NanoPi M2     
 +
|-
 +
|INT2    || NC
 +
|-
 +
|INT1    || NC
 +
|-
 +
|CS      || Pin2
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|SDA    || Pin3
 +
|-
 +
|SDO    || High, it is connected to the GPIO pin-header's 3.3V
 +
|-
 +
|5V      || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
 +
 
 +
===Connect to NanoPC-T2===
 +
Refer to the following connection diagram to connect the module to the NanoPC-T2:<br>
 +
[[File:Matrix-3_Axis_Digital_Accelerometer_NanoPC-T2.jpg|frameless|600px|Matrix-3_Axis_Digital_Accelerometer_NanoPC-T2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Accelerometer || NanoPC-T2
 +
|-
 +
|INT2    || NC
 +
|-
 +
|INT1    || NC
 +
|-
 +
|CS      || USB Host 5V
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|SDA    || Pin6
 +
|-
 +
|SDO    || USB Host 5V
 +
|-
 +
|5V      || Pin29
 +
|-
 +
|GND    || Pin30
 +
|}
 +
 
 +
 
 +
<!---
 +
==Connect to NanoPi 2==
 +
===Hardware Connection===
 +
Please refer to the following connection diagram to connect the Matrix-3_Axis_Digital_Accelerometer to the NanoPi 2:<br>
 +
[[File:Matrix-3_Axis_Digital_Accelerometer_nanopi_2.jpg|frameless|600px|Matrix-3_Axis_Digital_Accelerometer_nanopi_2]]
 +
 
 +
Connection Details:
 +
{| class="wikitable"
 +
|-
 +
|Matrix-3_Axis_Digital_Accelerometer || NanoPi 2     
 +
|-
 +
|INT2    || Not Connected
 +
|-
 +
|INT1    || Not Connected
 +
|-
 +
|CS      || Pin2, High
 +
|-
 +
|SCL    || Pin5
 +
|-
 +
|SDA    || Pin3
 +
|-
 +
|SDO    || Pin2
 +
|-
 +
|5V      || Pin4
 +
|-
 +
|GND    || Pin6
 +
|}
 +
 
 +
--->
 +
 
 +
<!---
 +
===Compile Test Program===
 +
Please login the matrix hub and enter the nanopi2 branch
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix
 +
$ git checkout nanopi2
 +
</syntaxhighlight>
 +
 
 +
Compile the Matrix code
 +
<syntaxhighlight lang="bash">
 +
$ make CROSS_COMPILE=arm-linux- clean
 +
$ make CROSS_COMPILE=arm-linux-
 +
$ make CROSS_COMPILE=arm-linux- install
 +
</syntaxhighlight>
 +
Note: please make sure to install the cross compiler "arm-linux-gcc-4.9.3" on your PC, which is used to compile files for the NanoPi 2.<br>
 +
Generated library files are under the "install/lib" directory. The test program is under the "install/usr/bin" directory. The modules are under the "modules" directory.<br>
 +
The modules are under the "modules" directory. The driver's source code is in github: https://github.com/friendlyarm/linux-3.4.y.git <br>
 +
--->
 +
 
 +
==Compile & Run Test Program==
 +
Boot your ARM board with Debian and copy the matrix code:
 +
<syntaxhighlight lang="bash">
 +
$ apt-get update && apt-get install git
 +
$ git clone https://github.com/friendlyarm/matrix.git
 +
</syntaxhighlight>
 +
If your cloning is done successfully a "matrix" directory will be generated.
 +
 
 +
Compile and install Matrix:
 +
<syntaxhighlight lang="bash">
 +
$ cd matrix
 +
$ make && make install
 +
</syntaxhighlight>
 +
 
 +
Run test program:
 +
<syntaxhighlight lang="bash">
 +
$ matrix-accelerometer
 +
</syntaxhighlight>
 +
Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.<br>
 +
Here is what you should observe:<br>
 +
<syntaxhighlight lang="bash">
 +
The position is (-6, 3, 236)
 +
</syntaxhighlight>
 +
 
 +
<!---
 +
===Run Test Program===
 +
Please insert a TF card which is flashed with Debian to a Linux host and mount its boot and rootfs sections.<br>
 +
We assume the rootfs is mounted to /media/rootfs then please run the following commands to copy the module, library and test program to the card<br>
 +
<syntaxhighlight lang="bash">
 +
$ cp modules /media/rootfs/ -r
 +
$ cp install/lib/* /media/rootfs/lib/ -d
 +
$ cp install/usr/bin/* /media/rootfs/usr/bin/
 +
</syntaxhighlight>
 +
 
 +
Insert this TF card to your NanoPi 2, power on and run the following commands to load the driver.<br>
 +
<syntaxhighlight lang="bash">
 +
$ cd /modules
 +
$ insmod adxl34x.ko
 +
$ insmod adxl34x-i2c.ko
 +
</syntaxhighlight>
 +
 
 +
Start the matrix-accelerometer program.<br>
 +
<syntaxhighlight lang="bash">
 +
$ matrix-accelerometer
 +
</syntaxhighlight>
 +
Note: this module is not plug and play therefore before running the module please make sure it is connected to a NanoPi 2.<br>
 +
Here is what you should expect:<br>
 +
[[File:matrix-accelerometer_result.png|frameless|600px|matrix-accelerometer_result]]
 +
--->
 +
 
 +
==Code Sample==
 +
This Matrix code sample can work with all the ARM boards mentioned in this module's wiki. The name of this code sample is "matrix-3_axis_digital_accelerometer". Here is its source code:
 +
<syntaxhighlight lang="c">
 +
int main(int argc, char ** argv)
 +
{
 +
    char position[BUF_SIZE];
 +
    int board;
 +
   
 +
    if ((board = boardInit()) < 0) {
 +
        printf("Fail to init board\n");
 +
        return -1;
 +
    }
 +
   
 +
    system("modprobe adxl34x");
 +
    system("modprobe adxl34x-i2c");
 +
    memset(position, 0, BUF_SIZE);
 +
    if (adxl34xRead(position) > 0) {
 +
        printf("The position is %s", position);
 +
    } else {
 +
        printf("Fail to get position\n");       
 +
    }
 +
    system("rmmod adxl34x-i2c");
 +
    system("rmmod adxl34x");
 +
   
 +
    return 0;
 +
}
 +
</syntaxhighlight>
 +
For more details about this APIs called in this code sample refer to [[Matrix API reference manual]] <br>
 +
 
 +
<!---
 +
==Connect to NanoPi==
 +
===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/zh|NanoPi]]
 +
 
 +
===Hardware Connection===
 +
Please refer to the following diagrams to connect "Matrix-3_Axis_Digital_Accelerometer" to the NanoPi <br>
 
[[File:matrix-3_axis_digital_accelerometer_nanopi.jpg|frameless|600px|matrix-3_axis_digital_accelerometer_nanopi]]
 
[[File:matrix-3_axis_digital_accelerometer_nanopi.jpg|frameless|600px|matrix-3_axis_digital_accelerometer_nanopi]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
 
|Matrix-3_Axis_Digital_Accelerometer || NanoPi       
 
|Matrix-3_Axis_Digital_Accelerometer || NanoPi       
 
|-
 
|-
|INT2    || 留空
+
|INT2    || Floating
 
|-
 
|-
|INT1    || 留空
+
|INT1    || Floating
 
|-  
 
|-  
 
|CS      || Pin1
 
|CS      || Pin1
Line 93: Line 331:
 
|}
 
|}
  
===编译测试程序===
+
===Compile Test Program===
进入Matrix代码仓库,切换到matrix-nanopi分支
+
Please login the Matrix git and enter the matrix-nanopi branch
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
Line 100: Line 338:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
编译Matrix配件代码
+
Compile the Matrix code
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ make CROSS_COMPILE=arm-linux- clean
 
$ make CROSS_COMPILE=arm-linux- clean
Line 106: Line 344:
 
$ make CROSS_COMPILE=arm-linux- install
 
$ make CROSS_COMPILE=arm-linux- install
 
</syntaxhighlight>
 
</syntaxhighlight>
注意:请确保你的主机PC当前使用的交叉编译器为NanoPi-Debian配套的arm-linux-gcc-4.4.3。<br>
+
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.<br>
编译出来的库文件位于install/lib目录下,而测试程序则位于install/usr/bin目录下,模块Matrix-3_Axis_Digital_Accelerometer对应的测试程序为matrix-3_axis_digital_accelerometer。<br>
+
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===
拷贝库文件和测试程序到NanoPi的文件系统上
+
Please copy the library files and test program to the NanoPi
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cp install/usr/bin/* nanopi_rootfs/usr/bin/
 
$ cp install/usr/bin/* nanopi_rootfs/usr/bin/
Line 116: Line 354:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
然后启动NanoPi,在Debian的shell终端中执行如下命令运行模块Matrix-3_Axis_Digital_Accelerometer的测试程序 <br>
+
Power on the NanoPi and run the following command in Debian's terminal<br>
注意:此模块并不支持热插拔,启动系统前需要确保硬件正常连接。
+
Note: this module is not plug and play therefore before running the module please make sure it is connected to a NanoPi.
 
<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)  
 
{
 
{
     char *position = (char *) malloc(32);
+
     char position[BUF_SIZE];
     memset(position, 0, 32);
+
     memset(position, 0, BUF_SIZE);
 
      
 
      
 
     if (adxl34xRead(position) > 0) {
 
     if (adxl34xRead(position) > 0) {
Line 134: Line 372:
 
         printf("Fail to get position\n");         
 
         printf("Fail to get position\n");         
 
     }
 
     }
    free(position);
 
 
     return 0;
 
     return 0;
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==与Tiny4412连接使用==
+
==Connect to Tiny4412==
===准备工作===
+
===Preparations===
参考Tiny4412光盘里的《友善之臂Ubuntu使用手册》,在Tiny4412上运行UbuntuCore系统,然后在主机PC上安装并使用相应的编译器。<br>
+
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.<br>
注意:只能使用Tiny4412SDK-1506的底板。
+
Note: only the Tiny4412SDK-1506 carrier board can work with this module.
  
===硬件连接===
+
===Hardware Connection===
参考下图连接模块Matrix-3_Axis_Digital_Accelerometer和Tiny4412 <br>
+
Please refer to the following diagram to connect the Matrix-3_Axis_Digital_Accelerometer to the Tiny4412 <br>
 
[[File:matrix-3_axis_digital_accelerometer_tiny4412.jpg|frameless|600px|matrix-3_axis_digital_accelerometer_tiny4412]]
 
[[File:matrix-3_axis_digital_accelerometer_tiny4412.jpg|frameless|600px|matrix-3_axis_digital_accelerometer_tiny4412]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
 
|Matrix-3_Axis_Digital_Accelerometer || Tiny4412       
 
|Matrix-3_Axis_Digital_Accelerometer || Tiny4412       
 
|-
 
|-
|INT2    || 留空
+
|INT2    || Floating
 
|-
 
|-
|INT1    || 留空
+
|INT1    || Floating
 
|-  
 
|-  
 
|CS      || CON16 5V
 
|CS      || CON16 5V
Line 170: Line 407:
 
|}
 
|}
  
===编译测试程序===
+
===Compile Test Program===
进入Matrix代码仓库,切换到matrix-tiny4412分支
+
Please login the Matrix hub and enter the matrix-tiny4412 branch
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
$ cd matrix
 
$ cd matrix
Line 177: Line 414:
 
</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 183: Line 420:
 
$ 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 193: Line 430:
 
</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)  
 
{
 
{
     char *position = (char *) malloc(32);
+
     char position[BUF_SIZE];
     memset(position, 0, 32);
+
     memset(position, 0, BUF_SIZE);
 
      
 
      
 
     if (adxl34xRead(position) > 0) {
 
     if (adxl34xRead(position) > 0) {
Line 211: Line 448:
 
         printf("Fail to get position\n");         
 
         printf("Fail to get position\n");         
 
     }
 
     }
    free(position);
 
 
     return 0;
 
     return 0;
 
}
 
}
 +
 
</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]
  
  
 +
==Update Log==
 +
===Feb-23-2016===
 +
* Changed CS pin spec in Section 5.1
 +
* Added driver's source code location in Section 5.2
  
 +
===June-17-2016===
 +
* Re-organized and simplified wiki
  
  
  
<!--
 
  
==Introduction==
+
 
[[File:3AD.png|thumb|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.
+
  
  

Latest revision as of 10:22, 19 June 2016

查看中文

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 Description:
Pin Description
INT2 Interrupt
INT1 Interrupt
CS Enable
SCL I2C SCL
SDA I2C SDA
SDO Set Slave Address
5V Supply Voltage 5V
GND Ground

3 Basic Device Operation

  • The ADXL345 is a small, thin, ultralow power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16 g. Digital output data is formatted as 16-bit twos complement and is acces-sible through either a SPI (3- or 4-wire) or I2C digital interface.
  • The ADXL345 is well suited for mobile device applications. It measures the static acceleration of gravity in tilt-sensing appli-cations, as well as dynamic acceleration resulting from motion or shock. Its high resolution (3.9 mg/LSB) enables measurement of inclination changes less than 1.0°.
  • The ADXL345 conforms to the UM1024 I2C Specification. It supports standard (100 kHz) and fast (400 kHz) data transfer modes. If the CS is tied high it will be in the I2C mode. If the CS or ALT ADDRESS pin is floating or unconnected the state will be unknown.
  • The module's I2C connection diagram is as follows:

三轴重力加速度


4 Applications

4.1 Connect to NanoPi M1

Refer to the following connection diagram to connect the module to the NanoPi M1:
Matrix-3_Axis_Digital_Accelerometer_nanopi_m1

Connection Details:

Matrix-3_Axis_Digital_Accelerometer NanoPi M1
INT2 NC
INT1 NC
CS Pin2
SCL Pin5
SDA Pin3
SDO High, it is connected to the GPIO pin-header's 3.3V
5V Pin4
GND Pin6

4.2 Connect to NanoPi 2

Refer to the following connection diagram to connect the module to the NanoPi 2:
Matrix-3_Axis_Digital_Accelerometer_nanopi_2

Connection Details:

Matrix-3_Axis_Digital_Accelerometer NanoPi 2
INT2 NC
INT1 NC
CS Pin2
SCL Pin5
SDA Pin3
SDO High, it is connected to the GPIO pin-header's 3.3V
5V Pin4
GND Pin6

4.3 Connect to NanoPi M2 / NanoPi 2 Fire

Refer to the following connection diagram to connect the module to the NanoPi M2/ NanoPi 2 Fire:
Matrix-3_Axis_Digital_Accelerometer_nanopi_M2

Connection Details:

Matrix-3_Axis_Digital_Accelerometer NanoPi M2
INT2 NC
INT1 NC
CS Pin2
SCL Pin5
SDA Pin3
SDO High, it is connected to the GPIO pin-header's 3.3V
5V Pin4
GND Pin6

4.4 Connect to NanoPC-T2

Refer to the following connection diagram to connect the module to the NanoPC-T2:
Matrix-3_Axis_Digital_Accelerometer_NanoPC-T2

Connection Details:

Matrix-3_Axis_Digital_Accelerometer NanoPC-T2
INT2 NC
INT1 NC
CS USB Host 5V
SCL Pin5
SDA Pin6
SDO USB Host 5V
5V Pin29
GND Pin30



5 Compile & Run Test Program

Boot your ARM board with Debian and copy the matrix code:

$ apt-get update && apt-get install git
$ git clone https://github.com/friendlyarm/matrix.git

If your cloning is done successfully a "matrix" directory will be generated.

Compile and install Matrix:

$ cd matrix
$ make && make install

Run test program:

$ matrix-accelerometer

Note: this module is not plug and play therefore before running the module please make sure it is connected to an ARM board.
Here is what you should observe:

The position is (-6, 3, 236)


6 Code Sample

This Matrix code sample can work with all the ARM boards mentioned in this module's wiki. The name of this code sample is "matrix-3_axis_digital_accelerometer". Here is its source code:

int main(int argc, char ** argv) 
{
    char position[BUF_SIZE];
    int board;
 
    if ((board = boardInit()) < 0) {
        printf("Fail to init board\n");
        return -1;
    }
 
    system("modprobe adxl34x");
    system("modprobe adxl34x-i2c");
    memset(position, 0, BUF_SIZE);
    if (adxl34xRead(position) > 0) {
        printf("The position is %s", position);
    } else {
        printf("Fail to get position\n");        
    }
    system("rmmod adxl34x-i2c");
    system("rmmod adxl34x");
 
    return 0;
}

For more details about this APIs called in this code sample refer to Matrix API reference manual


7 Resources

ADXL345.pdf


8 Update Log

8.1 Feb-23-2016

  • Changed CS pin spec in Section 5.1
  • Added driver's source code location in Section 5.2

8.2 June-17-2016

  • Re-organized and simplified wiki