Difference between revisions of "Matrix - 3-Axis Digital Accelerometer"
Line 1: | Line 1: | ||
− | [[Matrix - 3-Axis Digital Accelerometer| | + | [[Matrix - 3-Axis Digital Accelerometer/zh|查看中文]] |
− | == | + | ==Introduction== |
[[File:3AD.png|thumb|3-Axis Digital Accelerometer]] | [[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. |
− | * 13- | + | * 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. |
− | == | + | ==Features== |
− | * | + | * I2C, 3.3V |
− | * 13- | + | * 13-bit, up to +-16g |
− | * 2. | + | * 2.54mm spacing pin interface |
− | * | + | * PCB dimension(mm): 16 x 32 |
− | + | ||
[[File:adxpcb.png|frameless|400px|重力加速度PCB]] | [[File:adxpcb.png|frameless|400px|重力加速度PCB]] | ||
− | * | + | * 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 | + | |SDO || Set Slave Address |
|- | |- | ||
− | |5V | + | |5V || Supply Voltage 5V |
|- | |- | ||
− | |GND || | + | |GND || Ground |
|} | |} | ||
− | == | + | ==Basic Device Operation== |
− | * ADXL345 | + | * 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 | + | * 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: |
[[File:三轴重力.png|frameless|400px|三轴重力加速度]] | [[File:三轴重力.png|frameless|400px|三轴重力加速度]] | ||
− | == | + | ==Download Matrix Source Code== |
− | + | All the matrix modules' code samples are open source. They are maintained on GitHub - git://github.com/friendlyarm/matrix.git <br> | |
− | + | Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with.<br> | |
− | * | + | * The matrix-nanopi branch contains the matrix modules' code samples for the NanoPi |
− | * | + | * 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; |
− | + | ||
− | + | 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> | ||
− | + | Clone the matrix code from GitHub | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ git clone git://github.com/friendlyarm/matrix.git | $ git clone git://github.com/friendlyarm/matrix.git | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' code samples. | |
− | == | + | ==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: | + | [[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 | + | |CS || Pin1 |
|- | |- | ||
|SCL || Pin5 | |SCL || Pin5 | ||
Line 98: | Line 86: | ||
|SDA || Pin3 | |SDA || Pin3 | ||
|- | |- | ||
− | |SDO | + | |SDO || Pin2 |
|- | |- | ||
− | |5V | + | |5V || Pin4 |
|- | |- | ||
|GND || Pin6 | |GND || Pin6 | ||
|} | |} | ||
− | === | + | ===Compile Test Program=== |
− | + | Please login the Matrix git and enter the matrix-nanopi branch | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ cd matrix | $ cd matrix | ||
− | $ git checkout | + | $ git checkout matrix-nanopi |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Compile the Matrix code | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ make CROSS_COMPILE=arm-linux- clean | $ make CROSS_COMPILE=arm-linux- clean | ||
Line 118: | Line 106: | ||
$ make CROSS_COMPILE=arm-linux- install | $ make CROSS_COMPILE=arm-linux- install | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 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> | |
− | + | 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=== |
− | + | Please copy the library files and test program to the NanoPi | |
− | + | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | $ cp install/usr/bin/* | + | $ cp install/usr/bin/* nanopi_rootfs/usr/bin/ |
− | $ cp install/lib/* | + | $ cp install/lib/* nanopi_rootfs/lib/ -d |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 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- | + | $ 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 | + | char position[BUF_SIZE]; |
− | memset(position, 0, | + | memset(position, 0, BUF_SIZE); |
if (adxl34xRead(position) > 0) { | if (adxl34xRead(position) > 0) { | ||
Line 147: | Line 134: | ||
printf("Fail to get position\n"); | printf("Fail to get position\n"); | ||
} | } | ||
− | |||
return 0; | return 0; | ||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | ==Connect to Tiny4412== |
− | === | + | ===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.<br> | |
− | + | Note: only the Tiny4412SDK-1506 carrier board can work with this module. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | === | + | ===Hardware Connection=== |
− | + | Please refer to the following diagram to connect the Matrix-3_Axis_Digital_Accelerometer to the Tiny4412 <br> | |
− | [[File:matrix- | + | [[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 || | + | |Matrix-3_Axis_Digital_Accelerometer || Tiny4412 |
|- | |- | ||
− | |INT2 || | + | |INT2 || Floating |
|- | |- | ||
− | |INT1 || | + | |INT1 || Floating |
|- | |- | ||
− | |CS | + | |CS || CON16 5V |
|- | |- | ||
− | |SCL || | + | |SCL || CON18 SCL |
|- | |- | ||
− | |SDA || | + | |SDA || CON18 SDA |
|- | |- | ||
− | |SDO | + | |SDO || CON14 5V |
|- | |- | ||
− | |5V | + | |5V || CON18 5V |
|- | |- | ||
− | |GND || | + | |GND || CON18 GND |
|} | |} | ||
− | === | + | ===Compile Test Program=== |
− | + | Please login the Matrix hub and enter the matrix-tiny4412 branch | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
$ cd matrix | $ cd matrix | ||
− | $ git checkout | + | $ git checkout matrix-tiny4412 |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | Compile the Matrix code | |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | $ make CROSS_COMPILE=arm-linux- clean | + | $ make CROSS_COMPILE=arm-linux-gnueabihf- clean |
− | $ make CROSS_COMPILE=arm-linux- | + | $ make CROSS_COMPILE=arm-linux-gnueabihf- |
− | $ make CROSS_COMPILE=arm-linux- install | + | $ make CROSS_COMPILE=arm-linux-gnueabihf- install |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 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> | |
− | + | 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=== |
− | + | Please copy the library files and test program to the Tiny4412 | |
− | + | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | $ cp install/usr/bin/* | + | $ cp install/usr/bin/* tiny4412_rootfs/usr/bin/ |
− | $ cp install/lib/* | + | $ cp install/lib/* tiny4412_rootfs/lib/ -d |
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | 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- | + | $ 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 | + | char position[BUF_SIZE]; |
− | memset(position, 0, | + | memset(position, 0, BUF_SIZE); |
if (adxl34xRead(position) > 0) { | if (adxl34xRead(position) > 0) { | ||
Line 235: | Line 210: | ||
printf("Fail to get position\n"); | printf("Fail to get position\n"); | ||
} | } | ||
− | |||
return 0; | return 0; | ||
} | } | ||
+ | |||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | ==Connect to RaspberryPi== |
− | + | ||
− | + | ||
− | + | ||
− | === | + | ==Connect to Arduino== |
− | + | ||
− | + | ||
− | + | ==Resources== | |
− | + | [http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf ADXL345.pdf] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | === | + | |
+ | <!-- | ||
+ | |||
+ | |||
+ | ==Features== | ||
+ | * SPI/I2C,3.3V | ||
+ | * 13-bit,up to +-16g | ||
+ | * 2.54mm spacing pin interface | ||
+ | |||
+ | ==How To== | ||
+ | ===Connection=== | ||
+ | *Connect to Tiny4412 SDK (1506) | ||
+ | ::GND: Ground | ||
+ | ::VCC: 5V | ||
+ | ::INT2: NC, empty pin | ||
+ | ::INT1: NC, empty pin | ||
+ | ::CS: 5V | ||
+ | ::SCL: I2C SCL | ||
+ | ::SDA: I2C SDA | ||
+ | ::SDO: 5V for slave address | ||
+ | |||
+ | ===Code Sample in C Under Linux=== | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
− | int main(int argc, char ** argv) | + | #include <stdio.h> |
+ | #include <stdlib.h> | ||
+ | #include <string.h> | ||
+ | #include "libfahw-adxl34x.h" | ||
+ | |||
+ | int main(int argc, char ** argv) | ||
{ | { | ||
char *position = (char *) malloc(32); | char *position = (char *) malloc(32); | ||
memset(position, 0, 32); | memset(position, 0, 32); | ||
− | + | ||
if (adxl34xRead(position) > 0) { | if (adxl34xRead(position) > 0) { | ||
printf("Get position: %s", position); | printf("Get position: %s", position); | ||
} else { | } else { | ||
− | printf("Fail to get position\n"); | + | printf("Fail to get position\n"); |
} | } | ||
free(position); | free(position); | ||
Line 318: | Line 269: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | == | + | ===Compile and Run=== |
+ | <syntaxhighlight lang="bash"> | ||
+ | git clone http://github.com/friendlyarm/fa-hardware.git | ||
+ | cd fa-hardware | ||
+ | cd demo | ||
+ | cd matrix-3_axis_digital_accelerometer | ||
+ | make | ||
+ | </syntaxhighlight> | ||
+ | Copy your compiled bin to your board and you are ready to go. | ||
− | == | + | ==Resources== |
− | + | --> | |
− | + |
Revision as of 03:30, 11 November 2015
Contents
1 Introduction
- 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
- 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 Download Matrix Source Code
All the matrix modules' code samples are open source. They are maintained on GitHub - git://github.com/friendlyarm/matrix.git
Each branch in this hub contains the matrix modules' code samples for a board that the matrix modules can work with.
- The matrix-nanopi branch contains the matrix modules' code samples for the NanoPi
- 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;
Please follow the steps below to get the source code:
Install the git utility on a PC running Ubuntu14.04
$ sudo apt-get install git
Clone the matrix code from GitHub
$ git clone git://github.com/friendlyarm/matrix.git
If this is successful a "matrix" directory will be generated, which will contain all the matrix modules' 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
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 diagram to connect the Matrix-3_Axis_Digital_Accelerometer to the 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 hub 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