Issues with Grove-3-Axis-Digital-Accelerometer

Hi Everyone.

Im trying to connect a Grove - ADXL345 - 3-Axis Digital Accelerometer(±16g) to my Ardunio Uno R3 but I keep getting the following output when using serial monitoring. I swapped out the Grove - ADXL345 - 3-Axis Digital Accelerometer(±16g) for another and I get the same results with that one too.

Failed to initialize ADXL345 accelerometer.

Below is my code.

#include <Wire.h>
#include <ADXL345_WE.h>

ADXL345_WE accelerometer = ADXL345_WE(0x53);  

void setup() {
  Serial.begin(9600);
  while (!Serial);

  if (!accelerometer.init()) {
    Serial.println("Failed to initialize ADXL345 accelerometer.");
    while (1);
  }

  accelerometer.setRange(ADXL345_RANGE_16G);
}

void loop() {
  xyzFloat rawValues = accelerometer.getRawValues();

  Serial.print("x: "); Serial.print(rawValues.x);
  Serial.print("  y: "); Serial.print(rawValues.y);
  Serial.print("  z: "); Serial.println(rawValues.z);

  delay(100);
}

I dont think this should be overly difficult but I cant seem to solve this. I confirmed SDA is connected to SDA on the Arduino board (Also tried connecting it to A4 - no luck), I confirmed SCL is connected to SCL (Also tried connecting it to A5 - no luck).

I ran the following IC2 scanner to confirm the sensor is at 0x53

#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}

void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for (address = 1; address < 127; address++) {
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");
      nDevices++;
    }
  }

  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("Done\n");

  delay(5000);
}

and get to following output.

Scanning...
I2C device found at address 0x53 !
Done

Swapped out multiple jumper cables and confirmed confirmed continuity with my multimeter.

Am I missing something simple/key?

Thanks!

How have you been connecting the device? This shows problems in connections with SPI and I2C...

I was able to correct the issue by using the following library <ADXL345.h> and not <ADXL345_WE.h>

1 Like

This is good!

Did you read all the warnings about low voltages?

OoOo.

No I did not. The part about getting different output when connected to 3.3V and 5v?

Yes, the low voltage references. The text in the link is very thorough, with drawings and examples.