“(SKU:RB-02S037)ADXL345 三轴加速度计”的版本间的差异

来自ALSROBOT WiKi
跳转至: 导航搜索
 
(未显示1个用户的10个中间版本)
第1行: 第1行:
<br/>
+
[[文件:02s03701.png|500px|有框|右]]
[[文件:02s03702.jpg|400px|有框|右]]
+
 
==产品概述==
 
==产品概述==
 
ADXL345 数字三轴加速度计是一款小而薄的超低功耗3轴加速度计,分辨率高达(13位),测量范围达± 16g。数字输出数据为16位二进制补码格式,可通过SPI(3线或4线)或I2C数字接口访问。ADXL345非常适合移动设备应用。它可以在倾斜检测应用中测量静态重力加速度,还可以测量运动或冲击导致的动态加速度。其高分辨率(3.9mg/LSB),能够测量不到1.0°的倾斜角度变化。该器件提供多种特殊检测功能。活动和非活动检测功能通过比较任意轴上的加速度与用户设置的阈值来检测有无运动发生。敲击检测功能可以检测任意方向的单振和双振动作。自由落体检测功能可以检测器件是否正在掉落。这些功能可以独立映射到两个中断输出引脚中的一个。正在申请专利的集成式存储器管理系统采用一个32级先进先出(FIFO)缓冲器,可用于存储数据,从而将主机处理器负荷降至最低,并降低整体系统功耗。低功耗模式支持基于运动的智能电源管理,从而以极低的功耗进行阈值感测和运动加速度测量。
 
ADXL345 数字三轴加速度计是一款小而薄的超低功耗3轴加速度计,分辨率高达(13位),测量范围达± 16g。数字输出数据为16位二进制补码格式,可通过SPI(3线或4线)或I2C数字接口访问。ADXL345非常适合移动设备应用。它可以在倾斜检测应用中测量静态重力加速度,还可以测量运动或冲击导致的动态加速度。其高分辨率(3.9mg/LSB),能够测量不到1.0°的倾斜角度变化。该器件提供多种特殊检测功能。活动和非活动检测功能通过比较任意轴上的加速度与用户设置的阈值来检测有无运动发生。敲击检测功能可以检测任意方向的单振和双振动作。自由落体检测功能可以检测器件是否正在掉落。这些功能可以独立映射到两个中断输出引脚中的一个。正在申请专利的集成式存储器管理系统采用一个32级先进先出(FIFO)缓冲器,可用于存储数据,从而将主机处理器负荷降至最低,并降低整体系统功耗。低功耗模式支持基于运动的智能电源管理,从而以极低的功耗进行阈值感测和运动加速度测量。
 
 
==规格参数==
 
==规格参数==
 
# 工作电压:3.3-5v
 
# 工作电压:3.3-5v
# 超低功耗:测量模式下40uA电流损耗,待机模式下0.1uA@2.5v
+
# 超低功耗:测量模式下 40uA 电流损耗,待机模式下0.1uA @2.5v
# 通讯接口:I2C、SPI(3线or4线)
+
# 通讯接口:I2C、SPI (3线 or 4线)
 
# 接口类型:0.1"插针孔
 
# 接口类型:0.1"插针孔
==接线方法==
+
# 信号类型:数字信号
 +
==接口定义==
 +
* VCC:电源引脚
 +
* GND:该引脚必须接地
 +
* CS:片选端,低电平有效
 +
* INT1:中断1输出
 +
* INT2:中断2输出
 +
* SDO:备用I2C地址选择
 +
* SDA:I2C接口数据端
 +
* SCL:I2C接口时钟端
 +
==使用方法==
 +
===工作原理===
 +
ADXL345 加速度传感器首先由前端感应器件感测加速度的大小,然后由感应电信号器件转为可识别的电信号,这个信号是模拟信号,ADXL345 中集成了 AD 转换器,可以将模拟信号数字化,我们知道在计算机系统中数字信号一律用补码的形式来表示,在这也是如此,AD 转换器输出的是 16位的二进制补码,经过数字滤波器的滤波后在控制和中断逻辑单元的控制下访问32级 FIFO,通过串行接口读取数据。ADXL345 的控制命令也是通过接受来自串口的读写命令来实现的,这主要是对寄存器的操作。
 +
===编程原理===
 +
使用 IIC 通信连接 ADXL345 和 Arduino UNO 控制器(连线方法详见下图),使用 ±2g 加速度测试模式,通过查看 ADXL345 芯片手册,可以对芯片地址进行设置,该器件还提供了多种特殊检测功能,活动和非活动检测功能通过比较任意轴上的加速度与用户设置阀值来检测有无运动发生。敲击检测功能可以检测任意方向的单振和双振动作。自由落体检测功能可以检测器件是否正在掉落。这些功能可以独立映像到两个中断输出引脚中的一个。集成式内存管理系统采用一个32级先进先出缓冲期,用于数据存储,从而将主机处理器负荷降至最低,并降低整体系统功耗。
 +
===接线方法===
 
{|border="1" cellspacing="0" align="center" cellpadding="5" width="400px"
 
{|border="1" cellspacing="0" align="center" cellpadding="5" width="400px"
 
|-
 
|-
第35行: 第48行:
 
|}
 
|}
 
<br>
 
<br>
实物接线图:
+
接线图:
 
[[文件:adxl345jiexian.jpg|700px|有框|居中]]
 
[[文件:adxl345jiexian.jpg|700px|有框|居中]]
 
+
===例子程序===
==例子程序==
+
[http://pan.baidu.com/s/1o6CI1ZG wire库文件下载] <br/>
 
<pre style="color:blue">
 
<pre style="color:blue">
 
 
#include <Wire.h>
 
#include <Wire.h>
+
#define DEVICE (0x53)       //ADXL345 device address
#define DEVICE (0x53)   //ADXL345 device address
+
#define TO_READ (6)         //num of bytes we are going to read each time (two bytes for each axis)
#define TO_READ (6)       //num of bytes we are going to read each time (two bytes for each axis)
+
byte buff[TO_READ] ;       //6 bytes buffer for saving data read from the device
+
char str[512];             //string buffer to transform data before sending it to the serial port
byte buff[TO_READ] ;   //6 bytes buffer for saving data read from the device
+
int regAddress = 0x32;      //first axis-acceleration-data register on the ADXL345
char str[512];                     //string buffer to transform data before sending it to the serial port
+
int x, y, z;         //three axis acceleration data
+
double roll = 0.00, pitch = 0.00; //Roll & Pitch are the angles which rotate by the axis X and y
void setup()
+
//in the sequence of R(x-y-z),more info visit
{
+
void setup() {
   Wire.begin();       // join i2c bus (address optional for master)
+
   Wire.begin();         // join i2c bus (address optional for master)
 
   Serial.begin(9600);  // start serial for output
 
   Serial.begin(9600);  // start serial for output
+
 
 
   //Turning on the ADXL345
 
   //Turning on the ADXL345
 
   writeTo(DEVICE, 0x2D, 0);       
 
   writeTo(DEVICE, 0x2D, 0);       
第59行: 第71行:
 
   writeTo(DEVICE, 0x2D, 8);
 
   writeTo(DEVICE, 0x2D, 8);
 
}
 
}
+
 
void loop()
+
void loop() {
{
+
 
  int regAddress = 0x32;    //first axis-acceleration-data register on the ADXL345
+
  int x, y, z;
+
+
 
   readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345
 
   readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345
+
                                              //each axis reading comes in 10 bit resolution, ie 2 bytes.  Least Significat Byte first!!
  //each axis reading comes in 10 bit resolution, ie 2 bytes.  Least Significat Byte first!!
+
                                              //thus we are converting both bytes in to one int
  //thus we are converting both bytes in to one int
+
 
   x = (((int)buff[1]) << 8) | buff[0];   
 
   x = (((int)buff[1]) << 8) | buff[0];   
 
   y = (((int)buff[3])<< 8) | buff[2];
 
   y = (((int)buff[3])<< 8) | buff[2];
 
   z = (((int)buff[5]) << 8) | buff[4];
 
   z = (((int)buff[5]) << 8) | buff[4];
 
 
   //we send the x y z values as a string to the serial port
 
   //we send the x y z values as a string to the serial port
 +
  Serial.print("The acceleration info of x, y, z are:");
 
   sprintf(str, "%d %d %d", x, y, z);   
 
   sprintf(str, "%d %d %d", x, y, z);   
 
   Serial.print(str);
 
   Serial.print(str);
 
   Serial.write(10);
 
   Serial.write(10);
+
  //Roll & Pitch calculate
 +
  RP_calculate();
 +
  Serial.print("Roll:"); Serial.println( roll );
 +
  Serial.print("Pitch:"); Serial.println( pitch );
 +
  Serial.println("");
 
   //It appears that delay is needed in order not to clog the port
 
   //It appears that delay is needed in order not to clog the port
 
   delay(50);
 
   delay(50);
 
}
 
}
+
 
 
//---------------- Functions
 
//---------------- Functions
 
//Writes val to address register on device
 
//Writes val to address register on device
第90行: 第102行:
 
   Wire.endTransmission(); //end transmission
 
   Wire.endTransmission(); //end transmission
 
}
 
}
+
 
 
//reads num bytes starting from address register on device in to buff array
 
//reads num bytes starting from address register on device in to buff array
 
void readFrom(int device, byte address, int num, byte buff[]) {
 
void readFrom(int device, byte address, int num, byte buff[]) {
第96行: 第108行:
 
   Wire.write(address);        //sends address to read from
 
   Wire.write(address);        //sends address to read from
 
   Wire.endTransmission(); //end transmission
 
   Wire.endTransmission(); //end transmission
+
 
 
     Wire.beginTransmission(device); //start transmission to device
 
     Wire.beginTransmission(device); //start transmission to device
 
   Wire.requestFrom(device, num);    // request 6 bytes from device
 
   Wire.requestFrom(device, num);    // request 6 bytes from device
+
 
 
   int i = 0;
 
   int i = 0;
 
   while(Wire.available())    //device may send less than requested (abnormal)
 
   while(Wire.available())    //device may send less than requested (abnormal)
第109行: 第121行:
 
}
 
}
  
 +
//calculate the Roll&Pitch
 +
void RP_calculate(){
 +
  double x_Buff = float(x);
 +
  double y_Buff = float(y);
 +
  double z_Buff = float(z);
 +
  roll = atan2(y_Buff , z_Buff) * 57.3;
 +
  pitch = atan2((- x_Buff) , sqrt(y_Buff * y_Buff + z_Buff * z_Buff)) * 57.3;
 +
}
 
</pre>
 
</pre>
 +
===程序效果===
 +
打开串口监视窗口,可以看到类似下图的数据,分别为:三轴加速度的数据,按照R-xyz旋转顺序时的[http://blog.csdn.net/yuzhongchun/article/details/22749521 姿态角]。按各轴旋转可以观测到相应的数据变化。
 +
[[文件:02s03710.png|404px|有框|居中]]
  
==相关推荐==
+
==视频演示==
购买:[http://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-3667083713.12.MXloI1&id=13280714814 Arduino ADXL345 三轴加速度计 ]<br/>
+
[[File:san zhou 02.png|400px|左|link=http://v.youku.com/v_show/id_XMjAwNDEzMjQw.html?from=y1.7-2]]
论坛地址:[http://www.makerspace.cn/portal.php 奥松机器人技术论坛]
+
[[File:san zhou 01.png|400px|居中|link=http://v.youku.com/v_show/id_XMzkzMjE2NzM2.html?from=y1.7-2]]
 +
<br/>
 +
==产品相关推荐==
 +
[[文件:erweima.png|230px|无框|右]]
 +
===产品购买地址===
 +
[http://item.taobao.com/item.htm?spm=a1z10.3-c.w4002-3667083713.12.MXloI1&id=13280714814 Arduino ADXL345 三轴加速度计 ]<br/>
 +
===周边产品推荐===
 +
[http://www.alsrobot.cn/goods-546.html Carduino UNO R3 控制器]<br/>
 +
[http://www.alsrobot.cn/goods-147.html V5.0传感器扩展板]<br/>
 +
===相关问题解答===
 +
[http://www.makerspace.cn/forum.php?mod=viewthread&tid=3904&fromuid=10780 如何使用stm8s103f3单片机控制adxl345三轴加速度传感器]<br/>
 +
===相关学习资料===
 +
[http://pan.baidu.com/s/1ntIkk6t ADXL345 芯片中文版说明书下载]<br/>
 +
[http://v.youku.com/v_show/id_XMzkzMjE2NzM2.html?from=y1.7-2 视频: AS-4WD轮式机器人三轴加速度计操控功能演示]<br/>
 +
[http://www.makerspace.cn/forum.php?mod=viewthread&tid=1733&fromuid=10780 视频:Arduino ADXL345 三轴加速度计]<br/>
 +
[http://www.makerspace.cn/portal.php 奥松机器人技术论坛]<br/>

2016年1月15日 (五) 16:05的最后版本

02s03701.png

目录

产品概述

ADXL345 数字三轴加速度计是一款小而薄的超低功耗3轴加速度计,分辨率高达(13位),测量范围达± 16g。数字输出数据为16位二进制补码格式,可通过SPI(3线或4线)或I2C数字接口访问。ADXL345非常适合移动设备应用。它可以在倾斜检测应用中测量静态重力加速度,还可以测量运动或冲击导致的动态加速度。其高分辨率(3.9mg/LSB),能够测量不到1.0°的倾斜角度变化。该器件提供多种特殊检测功能。活动和非活动检测功能通过比较任意轴上的加速度与用户设置的阈值来检测有无运动发生。敲击检测功能可以检测任意方向的单振和双振动作。自由落体检测功能可以检测器件是否正在掉落。这些功能可以独立映射到两个中断输出引脚中的一个。正在申请专利的集成式存储器管理系统采用一个32级先进先出(FIFO)缓冲器,可用于存储数据,从而将主机处理器负荷降至最低,并降低整体系统功耗。低功耗模式支持基于运动的智能电源管理,从而以极低的功耗进行阈值感测和运动加速度测量。

规格参数

  1. 工作电压:3.3-5v
  2. 超低功耗:测量模式下 40uA 电流损耗,待机模式下0.1uA @2.5v
  3. 通讯接口:I2C、SPI (3线 or 4线)
  4. 接口类型:0.1"插针孔
  5. 信号类型:数字信号

接口定义

  • VCC:电源引脚
  • GND:该引脚必须接地
  • CS:片选端,低电平有效
  • INT1:中断1输出
  • INT2:中断2输出
  • SDO:备用I2C地址选择
  • SDA:I2C接口数据端
  • SCL:I2C接口时钟端

使用方法

工作原理

ADXL345 加速度传感器首先由前端感应器件感测加速度的大小,然后由感应电信号器件转为可识别的电信号,这个信号是模拟信号,ADXL345 中集成了 AD 转换器,可以将模拟信号数字化,我们知道在计算机系统中数字信号一律用补码的形式来表示,在这也是如此,AD 转换器输出的是 16位的二进制补码,经过数字滤波器的滤波后在控制和中断逻辑单元的控制下访问32级 FIFO,通过串行接口读取数据。ADXL345 的控制命令也是通过接受来自串口的读写命令来实现的,这主要是对寄存器的操作。

编程原理

使用 IIC 通信连接 ADXL345 和 Arduino UNO 控制器(连线方法详见下图),使用 ±2g 加速度测试模式,通过查看 ADXL345 芯片手册,可以对芯片地址进行设置,该器件还提供了多种特殊检测功能,活动和非活动检测功能通过比较任意轴上的加速度与用户设置阀值来检测有无运动发生。敲击检测功能可以检测任意方向的单振和双振动作。自由落体检测功能可以检测器件是否正在掉落。这些功能可以独立映像到两个中断输出引脚中的一个。集成式内存管理系统采用一个32级先进先出缓冲期,用于数据存储,从而将主机处理器负荷降至最低,并降低整体系统功耗。

接线方法

ADXL345 Arduino
VCC 3V3
GND GND
CS 3V3
SDO GND
SDA A4
SCL A5


接线图:

Adxl345jiexian.jpg

例子程序

wire库文件下载

#include <Wire.h>
#define DEVICE (0x53)       //ADXL345 device address
#define TO_READ (6)         //num of bytes we are going to read each time (two bytes for each axis)
byte buff[TO_READ] ;        //6 bytes buffer for saving data read from the device
char str[512];              //string buffer to transform data before sending it to the serial port
int regAddress = 0x32;      //first axis-acceleration-data register on the ADXL345
int x, y, z;				        //three axis acceleration data
double roll = 0.00, pitch = 0.00;		//Roll & Pitch are the angles which rotate by the axis X and y 
//in the sequence of R(x-y-z),more info visit
void setup() {
  Wire.begin();         // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output

  //Turning on the ADXL345
  writeTo(DEVICE, 0x2D, 0);      
  writeTo(DEVICE, 0x2D, 16);
  writeTo(DEVICE, 0x2D, 8);
}

void loop() {

  readFrom(DEVICE, regAddress, TO_READ, buff); //read the acceleration data from the ADXL345
                                              //each axis reading comes in 10 bit resolution, ie 2 bytes.  Least Significat Byte first!!
                                              //thus we are converting both bytes in to one int
  x = (((int)buff[1]) << 8) | buff[0];   
  y = (((int)buff[3])<< 8) | buff[2];
  z = (((int)buff[5]) << 8) | buff[4];
  //we send the x y z values as a string to the serial port
  Serial.print("The acceleration info of x, y, z are:");
  sprintf(str, "%d %d %d", x, y, z);  
  Serial.print(str);
  Serial.write(10);
  //Roll & Pitch calculate
  RP_calculate();
  Serial.print("Roll:"); Serial.println( roll ); 
  Serial.print("Pitch:"); Serial.println( pitch );
  Serial.println("");
  //It appears that delay is needed in order not to clog the port
  delay(50);
}

//---------------- Functions
//Writes val to address register on device
void writeTo(int device, byte address, byte val) {
  Wire.beginTransmission(device); //start transmission to device 
  Wire.write(address);        // send register address
  Wire.write(val);        // send value to write
  Wire.endTransmission(); //end transmission
}

//reads num bytes starting from address register on device in to buff array
void readFrom(int device, byte address, int num, byte buff[]) {
  Wire.beginTransmission(device); //start transmission to device 
  Wire.write(address);        //sends address to read from
  Wire.endTransmission(); //end transmission

    Wire.beginTransmission(device); //start transmission to device
  Wire.requestFrom(device, num);    // request 6 bytes from device

  int i = 0;
  while(Wire.available())    //device may send less than requested (abnormal)
  { 
    buff[i] = Wire.read(); // receive a byte
    i++;
  }
  Wire.endTransmission(); //end transmission
}

//calculate the Roll&Pitch
void RP_calculate(){
  double x_Buff = float(x);
  double y_Buff = float(y);
  double z_Buff = float(z);
  roll = atan2(y_Buff , z_Buff) * 57.3;
  pitch = atan2((- x_Buff) , sqrt(y_Buff * y_Buff + z_Buff * z_Buff)) * 57.3;
}

程序效果

打开串口监视窗口,可以看到类似下图的数据,分别为:三轴加速度的数据,按照R-xyz旋转顺序时的姿态角。按各轴旋转可以观测到相应的数据变化。

02s03710.png

视频演示

San zhou 02.png
San zhou 01.png


产品相关推荐

Erweima.png

产品购买地址

Arduino ADXL345 三轴加速度计

周边产品推荐

Carduino UNO R3 控制器
V5.0传感器扩展板

相关问题解答

如何使用stm8s103f3单片机控制adxl345三轴加速度传感器

相关学习资料

ADXL345 芯片中文版说明书下载
视频: AS-4WD轮式机器人三轴加速度计操控功能演示
视频:Arduino ADXL345 三轴加速度计
奥松机器人技术论坛