Tuorial on ADXL345 3-axis Acclelerometer using Arduino UNOR3 and Breakout Board

1. Introduction
The ADXL345 3-axis accelerator sensor supports I2C Bus, 4-Wire SPI Port, and 3-Wire SPI Port operations. However, the Breakout Board (Fig-1) has come up in I2C Mode. To operate the Breakout Board in 4-Wire SPI Mode, the R4-register has been isolated carefully using a sharp tip of a 60W soldering iron. The filter and storage capacitors of the Breakout Board are not presented in Fig-1.

2. Physical view of the Sensor is presented in Fig-1.

3. 4-Wire SPI Connection Diagram (Fig-1) among Arduino UNO, Level Shifter, and ADXL345 Breakout Board.


Figure-1:

4. Test Sketch to read the Device ID (0xE5) of the Sensor

#include <SPI.h>

void setup()
{
  Serial.begin(9600);
  SPI.begin();

  SPI.setClockDivider(SPI_CLOCK_DIV16); // 1 MHz speed
  SPI.setDataMode(SPI_MODE3); // Set SPI mode (SPI_MODE3 for ADXL345)
  SPI.setBitOrder(MSBFIRST);  // MSB first
  digitalWrite(SS, LOW);
  delay(200);

  // Put ADXL345 in 4-Wire SPI mode
  SPI.transfer(0x31); //DATA_FORMAT Register in single byte write mode
  delayMicroseconds(100);
  SPI.transfer(0x0B);  //data for DATA_FORMAT Register
  delayMicroseconds(100);
}

void loop()
{
  //Reading device ID (0xE5) to be sure that the 3-Wire SPI Port is working
  SPI.transfer(0x80);  //DEViceID Register in single byte read mode: 10 000000
  byte devID = SPI.transfer(0xFF);
  Serial.println(devID, HEX); //expecting E5; but, shows: FF
  //--------------------------------------------------
  delay(2000);
}

5. Output

E5
E5
E5

6. I2C Bus Operation
When Library is installed, then examples can be found in the IDE to read 3-axis accelerations/components of g.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.