Matrix - 3-Axis Digital Accelerometer

From FriendlyELEC WiKi
Revision as of 11:05, 4 August 2015 by Yftan (Talk | contribs)

Jump to: navigation, search

查看中文

1 Introduction

3-Axis Digital Accelerometer

三轴重力加速度主要功能是用作测量x\y\z方向上的速度,可利用测量到的速度计算当前角度。模块可以使用IIC或SPI进行通信。此配件搭载了一颗ADXL345芯片。ADXL345是Anolog Device公司的三轴数字重力传感器,13-bit精度,采集范围可以是+-2g,+-4g,+-8g和+-16g,通讯方式为SPI或I2C。配件采用5V供电,PCB上的电源转换芯片输出3.3V给ADXL345。

2 特性

  • SPI/I2C,3.3V
  • 13-bit,up to +-16g
  • 2.54mm排针接口,接线方便,通用性强

3 使用方法

3.1 连接

  • 连接到Tiny4412 SDK (1506)
GND针脚: 接地
VCC: 接5V
INT2:留空
INT1: 留空
CS: 接5V
SCL: I2C SCL
SDA: I2C SDA
SDO: 接5V,用来决定slave address

3.2 Code Sample in C Under Linux

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "libfahw-adxl34x.h"
 
int main(int argc, char ** argv)
{
    char *position = (char *) malloc(32);
    memset(position, 0, 32);
 
    if (adxl34xRead(position) > 0) {
        printf("Get position: %s", position);
    } else {
        printf("Fail to get position\n");
    }
    free(position);
    return 0;
}

3.3 Compile and Run

git clone http://github.com/friendlyarm/fa-hardware.git
cd fa-hardware
cd demo
cd matrix-3_axis_digital_accelerometer
make

Copy your compiled bin to your board and you are ready to go.

4 Resources