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

From FriendlyELEC WiKi
Jump to: navigation, search
(Hardware Connection)
(Applications)
Line 145: Line 145:
 
|}
 
|}
  
<!---
+
===Connect to NanoPC-T2===
===连接NanoPC-T2===
+
Please refer to the following connection diagram to connect the module to the NanoPC-T2:<br>
参考下图连接模块:<br>
+
 
[[File:Matrix-3_Axis_Digital_Accelerometer_NanoPC-T2.jpg|frameless|600px|Matrix-3_Axis_Digital_Accelerometer_NanoPC-T2]]
 
[[File:Matrix-3_Axis_Digital_Accelerometer_NanoPC-T2.jpg|frameless|600px|Matrix-3_Axis_Digital_Accelerometer_NanoPC-T2]]
  
连接说明:
+
Connection Details:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
 
|Matrix-3_Axis_Digital_Accelerometer || NanoPC-T2
 
|Matrix-3_Axis_Digital_Accelerometer || NanoPC-T2
 
|-
 
|-
|INT2    || 留空
+
|INT2    || NC
 
|-
 
|-
|INT1    || 留空
+
|INT1    || NC
 
|-  
 
|-  
 
|CS      || USB Host 5V
 
|CS      || USB Host 5V
Line 173: Line 172:
  
  
 
+
<!---
 
+
 
+
 
==Connect to NanoPi 2==
 
==Connect to NanoPi 2==
 
===Hardware Connection===
 
===Hardware Connection===

Revision as of 08:20, 17 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

Please 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

Please 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

Please 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

Please 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


4.5 Compile Test Program

Please login the matrix hub and enter the nanopi2 branch

$ cd matrix
$ git checkout nanopi2

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.9.3" on your PC, which is used to compile files for the NanoPi 2.
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.
The modules are under the "modules" directory. The driver's source code is in github: https://github.com/friendlyarm/linux-3.4.y.git

4.6 Run Test Program

Please insert a TF card which is flashed with Debian to a Linux host and mount its boot and rootfs sections.
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

$ cp modules /media/rootfs/ -r
$ cp install/lib/* /media/rootfs/lib/ -d
$ cp install/usr/bin/* /media/rootfs/usr/bin/

Insert this TF card to your NanoPi 2, power on and run the following commands to load the driver.

$ cd /modules
$ insmod adxl34x.ko
$ insmod adxl34x-i2c.ko

Start the matrix-accelerometer program.

$ matrix-accelerometer

Note: this module is not plug and play therefore before running the module please make sure it is connected to a NanoPi 2.
Here is what you should expect:
matrix-accelerometer_result

4.7 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;
}

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 diagram 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 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

ADXL345.pdf


10 Update Log

10.1 Feb-23-2016

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