(SKU:RB-02S037)Triple Axis Accelerometer ADXL345

From ALSRobot-Wki
Jump to: navigation, search
02s03702.jpg

Contents

overview

The ADXL345 is a small, thin, low 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 accessible through either a SPI (3- or 4-wire) or I2C digital interface.

Technical parameters and performance

  1. Wide power range DC3V to 5V
  2. Grove module
  3. 3 axis sensing
  4. High sensitivity
  5. Small, low-profile package: 14-Terminal LGA
  6. Low power 0.1 μA in standby mode at VS = 2.5 V (typical)
  7. 10,000 g shock survival
  8. RoHS/WEEE lead-free compliant
  9. Interface: Digital TTL
  10. High-Resolution Conversion of Light Intensity to Frequency
  11. Programmable Color and Full-Scale Output Frequency
  12. Power Down Feature
  13. Communicates Directly to Microcontroller
  14. Weight:3g

using method

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


Connect Icon

Physical wiring diagram:

Adxl345jiexian.jpg

Application Routine

Sample code


#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
 
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()
{
  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
 
  //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
  sprintf(str, "%d %d %d", x, y, z);  
  Serial.print(str);
  Serial.write(10);
 
  //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
}

Program effect

Product recommendation

Buy address:Triple Axis Accelerometer ADXL345

Personal tools
Namespaces

Variants
Actions
Navigation
Tools